summaryrefslogtreecommitdiffstats
path: root/test/lib
diff options
context:
space:
mode:
authorFelix Fontein <felix@fontein.de>2024-09-24 17:15:43 +0200
committerGitHub <noreply@github.com>2024-09-24 17:15:43 +0200
commitf4e2e206b3356c9b9fa94e8cbead1cdb88cede54 (patch)
tree5ada604e6dd979079539418ae3fd9f73b4da6bd4 /test/lib
parentdnf5: fix tb when plugins API is not available (#83969) (diff)
downloadansible-f4e2e206b3356c9b9fa94e8cbead1cdb88cede54.tar.xz
ansible-f4e2e206b3356c9b9fa94e8cbead1cdb88cede54.zip
Add basic validation for action_groups (#83965)
Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py b/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py
index ad7d017767..a3cfca0a97 100644
--- a/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py
+++ b/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py
@@ -6,6 +6,7 @@ import os
import re
import sys
+from collections.abc import Sequence, Mapping
from functools import partial
import yaml
@@ -29,6 +30,15 @@ def fqcr(value):
return value
+def fqcr_or_shortname(value):
+ """Validate a FQCR or a shortname."""
+ if not isinstance(value, string_types):
+ raise Invalid('Must be a string that is a FQCR or a short name')
+ if '.' in value and not AnsibleCollectionRef.is_valid_fqcr(value):
+ raise Invalid('Must be a FQCR or a short name')
+ return value
+
+
def isodate(value, check_deprecation_date=False, is_tombstone=False):
"""Validate a datetime.date or ISO 8601 date string."""
# datetime.date objects come from YAML dates, these are ok
@@ -264,6 +274,22 @@ def validate_metadata_file(path, is_ansible, check_deprecation_dates=False):
list_dict_import_redirection_schema = [{str_type: import_redirection_schema}
for str_type in string_types]
+ # action_groups schema
+
+ def at_most_one_dict(value):
+ if isinstance(value, Sequence):
+ if sum(1 for v in value if isinstance(v, Mapping)) > 1:
+ raise Invalid('List must contain at most one dictionary')
+ return value
+
+ metadata_dict = Schema({
+ Required('metadata'): Schema({
+ 'extend_group': [fqcr_or_shortname],
+ }, extra=PREVENT_EXTRA)
+ }, extra=PREVENT_EXTRA)
+ action_group_schema = All([metadata_dict, fqcr_or_shortname], at_most_one_dict)
+ list_dict_action_groups_schema = [{str_type: action_group_schema} for str_type in string_types]
+
# top level schema
schema = Schema({
@@ -272,7 +298,7 @@ def validate_metadata_file(path, is_ansible, check_deprecation_dates=False):
('import_redirection'): Any(None, *list_dict_import_redirection_schema),
# requires_ansible: In the future we should validate this with SpecifierSet
('requires_ansible'): Any(*string_types),
- ('action_groups'): dict,
+ ('action_groups'): Any(*list_dict_action_groups_schema),
}, extra=PREVENT_EXTRA)
# Ensure schema is valid