Skip to content

Commit 521ea02

Browse files
authored
Relax gres configuration validation to allow multiple conf keys (#193)
* Relax gres configuration validation to allow multiple list items * Add all allowable properties on nodegroup * Allow additional properties in nodegroup schema validation
1 parent bfd3d67 commit 521ea02

File tree

2 files changed

+93
-15
lines changed

2 files changed

+93
-15
lines changed

files/nodegroup.schema

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{ "$schema": "https://json-schema.org/draft/2020-12/schema",
2+
"type": "object",
3+
"definitions": {
4+
"gres": {
5+
"type": "array",
6+
"items": {
7+
"type": "object",
8+
"properties": {
9+
"conf": {
10+
"type": "string",
11+
"minLength": 1
12+
},
13+
"file": {
14+
"type": "string",
15+
"minLength": 1
16+
}
17+
},
18+
"required": [
19+
"conf"
20+
]
21+
}
22+
}
23+
},
24+
"properties": {
25+
"name": {
26+
"type": "string",
27+
"minLength": 1
28+
},
29+
"ram_mb": {
30+
"type": "number",
31+
},
32+
"ram_multiplier": {
33+
"type": "number",
34+
},
35+
"features": {
36+
"type": "array",
37+
"items": {
38+
"type": "string"
39+
}
40+
},
41+
"node_params": {
42+
"type": "object",
43+
},
44+
"gres_autodetect": {
45+
"type": "string",
46+
"minLength": 1
47+
},
48+
"gres": {
49+
"$ref": "#/definitions/gres"
50+
}
51+
},
52+
"required": [
53+
"name"
54+
],
55+
"if": {
56+
"properties": {
57+
"gres_autodetect": {
58+
"const": "off"
59+
}
60+
}
61+
},
62+
"then": {
63+
"properties": {
64+
"gres": {
65+
"items": {
66+
"required": [
67+
"file"
68+
]
69+
}
70+
}
71+
}
72+
},
73+
"else": {
74+
"properties": {
75+
"gres": {
76+
"items": {
77+
"not": {
78+
"required": [
79+
"file"
80+
]
81+
}
82+
}
83+
}
84+
}
85+
}
86+
}

tasks/validate.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,15 @@
2121
delegate_to: localhost
2222
run_once: true
2323

24-
- name: Check gres configuration when gres_autodetect is set
25-
assert:
26-
that:
27-
- _failure_reasons | selectattr('when', 'truthy') | length == 0
28-
fail_msg: >
29-
Your nodegroup definition must include a single gres dictionary containing a conf key
30-
if gres_autodetect is set. The following nodegroup failed this check: {{ item }}.
31-
Reasons for failure: {{ _failure_reasons | selectattr('when', 'truthy') | map(attribute='msg') | join(', ') }}
24+
- name: Validate openhpc_nodegroups
25+
ansible.utils.validate:
26+
criteria: "{{ lookup('file', 'nodegroup.schema') }}"
27+
engine: 'ansible.utils.jsonschema'
28+
data: "{{ item }}"
3229
vars:
33-
_openhpc_gres_autodetect_groups: "{{ openhpc_nodegroups | selectattr('gres_autodetect', 'defined') | selectattr('gres_autodetect', 'search', '(?!off).*') }}"
34-
_failure_reasons:
35-
- msg: The gres key was a list with more than one item
36-
when: "{{ item.gres | length != 1 }}"
37-
- msg: The gres dictionary does not contain a conf key
38-
when: "{{ item.gres.0.conf is not defined }}"
30+
ansible_jsonschema_draft: '2020-12'
3931
delegate_to: localhost
40-
loop: "{{ _openhpc_gres_autodetect_groups }}"
32+
loop: "{{ openhpc_nodegroups }}"
4133
run_once: true
4234

4335
- name: Fail if configuration is old

0 commit comments

Comments
 (0)