Skip to content

Commit 4a71c27

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

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

files/nodegroup.schema

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
"gres_autodetect": {
27+
"type": "string",
28+
"minLength": 1
29+
},
30+
"gres": {
31+
"$ref": "#/definitions/gres"
32+
}
33+
},
34+
"if": {
35+
"properties": {
36+
"gres_autodetect": {
37+
"const": "off"
38+
}
39+
}
40+
},
41+
"then": {
42+
"properties": {
43+
"gres": {
44+
"items": {
45+
"required": [
46+
"file"
47+
]
48+
}
49+
}
50+
}
51+
},
52+
"else": {
53+
"properties": {
54+
"gres": {
55+
"items": {
56+
"not": {
57+
"required": [
58+
"file"
59+
]
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}

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)