Skip to content

Commit d94f96a

Browse files
committed
Relax gres configuration validation to allow multiple list items
1 parent bfd3d67 commit d94f96a

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

files/nodegroup.schema

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

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)