From d94f96a4d43976f1a789bff62ff52fd11b30db5a Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Tue, 10 Jun 2025 14:19:13 +0100 Subject: [PATCH 1/3] Relax gres configuration validation to allow multiple list items --- files/nodegroup.schema | 72 ++++++++++++++++++++++++++++++++++++++++++ tasks/validate.yml | 22 ++++--------- 2 files changed, 79 insertions(+), 15 deletions(-) create mode 100644 files/nodegroup.schema diff --git a/files/nodegroup.schema b/files/nodegroup.schema new file mode 100644 index 0000000..33bc2c9 --- /dev/null +++ b/files/nodegroup.schema @@ -0,0 +1,72 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "definitions": { + "gres": { + "type": "array", + "items": { + "type": "object", + "properties": { + "conf": { + "type": "string", + "minLength": 1 + }, + "file": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "conf" + ] + } + } + }, + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "gres_autodetect": { + "type": "string", + "minLength": 1 + }, + "gres": { + "$ref": "#/definitions/gres" + } + }, + "required": [ + "name" + ], + "if": { + "properties": { + "gres_autodetect": { + "const": "off" + } + } + }, + "then": { + "properties": { + "gres": { + "items": { + "required": [ + "file" + ] + } + } + } + }, + "else": { + "properties": { + "gres": { + "items": { + "not": { + "required": [ + "file" + ] + } + } + } + } + } +} diff --git a/tasks/validate.yml b/tasks/validate.yml index b1bc104..99ae719 100644 --- a/tasks/validate.yml +++ b/tasks/validate.yml @@ -21,23 +21,15 @@ delegate_to: localhost run_once: true -- name: Check gres configuration when gres_autodetect is set - assert: - that: - - _failure_reasons | selectattr('when', 'truthy') | length == 0 - fail_msg: > - Your nodegroup definition must include a single gres dictionary containing a conf key - if gres_autodetect is set. The following nodegroup failed this check: {{ item }}. - Reasons for failure: {{ _failure_reasons | selectattr('when', 'truthy') | map(attribute='msg') | join(', ') }} +- name: Validate openhpc_nodegroups + ansible.utils.validate: + criteria: "{{ lookup('file', 'nodegroup.schema') }}" + engine: 'ansible.utils.jsonschema' + data: "{{ item }}" vars: - _openhpc_gres_autodetect_groups: "{{ openhpc_nodegroups | selectattr('gres_autodetect', 'defined') | selectattr('gres_autodetect', 'search', '(?!off).*') }}" - _failure_reasons: - - msg: The gres key was a list with more than one item - when: "{{ item.gres | length != 1 }}" - - msg: The gres dictionary does not contain a conf key - when: "{{ item.gres.0.conf is not defined }}" + ansible_jsonschema_draft: '2020-12' delegate_to: localhost - loop: "{{ _openhpc_gres_autodetect_groups }}" + loop: "{{ openhpc_nodegroups }}" run_once: true - name: Fail if configuration is old From 06a8c28a5e65417b37b991d638d4c053ee1c020b Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Wed, 11 Jun 2025 09:36:57 +0100 Subject: [PATCH 2/3] Add all allowable properties on nodegroup --- files/nodegroup.schema | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/files/nodegroup.schema b/files/nodegroup.schema index 33bc2c9..3b495f6 100644 --- a/files/nodegroup.schema +++ b/files/nodegroup.schema @@ -1,5 +1,4 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", +{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "definitions": { "gres": { @@ -27,6 +26,21 @@ "type": "string", "minLength": 1 }, + "ram_mb": { + "type": "number", + }, + "ram_multiplier": { + "type": "number", + }, + "features": { + "type": "array", + "items": { + "type": "string" + } + }, + "node_params": { + "type": "object", + }, "gres_autodetect": { "type": "string", "minLength": 1 @@ -38,6 +52,7 @@ "required": [ "name" ], + "additionalProperties": false, "if": { "properties": { "gres_autodetect": { From 353ea7ecfe4cac133615da7d8d905210c5fae79d Mon Sep 17 00:00:00 2001 From: Will Szumski Date: Wed, 11 Jun 2025 09:42:37 +0100 Subject: [PATCH 3/3] Allow additional properties in nodegroup schema validation --- files/nodegroup.schema | 1 - 1 file changed, 1 deletion(-) diff --git a/files/nodegroup.schema b/files/nodegroup.schema index 3b495f6..814c60a 100644 --- a/files/nodegroup.schema +++ b/files/nodegroup.schema @@ -52,7 +52,6 @@ "required": [ "name" ], - "additionalProperties": false, "if": { "properties": { "gres_autodetect": {