summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py')
-rw-r--r--test/lib/ansible_test/_util/controller/sanity/code-smell/runtime-metadata.py57
1 files changed, 45 insertions, 12 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 6cf27774..188d50fe 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
@@ -16,9 +16,19 @@ from voluptuous.humanize import humanize_error
from ansible.module_utils.compat.version import StrictVersion, LooseVersion
from ansible.module_utils.six import string_types
+from ansible.utils.collection_loader import AnsibleCollectionRef
from ansible.utils.version import SemanticVersion
+def fqcr(value):
+ """Validate a FQCR."""
+ if not isinstance(value, string_types):
+ raise Invalid('Must be a string that is a FQCR')
+ if not AnsibleCollectionRef.is_valid_fqcr(value):
+ raise Invalid('Must be a FQCR')
+ 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
@@ -126,12 +136,15 @@ def validate_metadata_file(path, is_ansible, check_deprecation_dates=False):
with open(path, 'r', encoding='utf-8') as f_path:
routing = yaml.safe_load(f_path)
except yaml.error.MarkedYAMLError as ex:
- print('%s:%d:%d: YAML load failed: %s' % (path, ex.context_mark.line +
- 1, ex.context_mark.column + 1, re.sub(r'\s+', ' ', str(ex))))
+ print('%s:%d:%d: YAML load failed: %s' % (
+ path,
+ ex.context_mark.line + 1 if ex.context_mark else 0,
+ ex.context_mark.column + 1 if ex.context_mark else 0,
+ re.sub(r'\s+', ' ', str(ex)),
+ ))
return
except Exception as ex: # pylint: disable=broad-except
- print('%s:%d:%d: YAML load failed: %s' %
- (path, 0, 0, re.sub(r'\s+', ' ', str(ex))))
+ print('%s:%d:%d: YAML load failed: %s' % (path, 0, 0, re.sub(r'\s+', ' ', str(ex))))
return
if is_ansible:
@@ -184,17 +197,37 @@ def validate_metadata_file(path, is_ansible, check_deprecation_dates=False):
avoid_additional_data
)
- plugin_routing_schema = Any(
- Schema({
- ('deprecation'): Any(deprecation_schema),
- ('tombstone'): Any(tombstoning_schema),
- ('redirect'): Any(*string_types),
- }, extra=PREVENT_EXTRA),
+ plugins_routing_common_schema = Schema({
+ ('deprecation'): Any(deprecation_schema),
+ ('tombstone'): Any(tombstoning_schema),
+ ('redirect'): fqcr,
+ }, extra=PREVENT_EXTRA)
+
+ plugin_routing_schema = Any(plugins_routing_common_schema)
+
+ # Adjusted schema for modules only
+ plugin_routing_schema_modules = Any(
+ plugins_routing_common_schema.extend({
+ ('action_plugin'): fqcr}
+ )
+ )
+
+ # Adjusted schema for module_utils
+ plugin_routing_schema_mu = Any(
+ plugins_routing_common_schema.extend({
+ ('redirect'): Any(*string_types)}
+ ),
)
list_dict_plugin_routing_schema = [{str_type: plugin_routing_schema}
for str_type in string_types]
+ list_dict_plugin_routing_schema_mu = [{str_type: plugin_routing_schema_mu}
+ for str_type in string_types]
+
+ list_dict_plugin_routing_schema_modules = [{str_type: plugin_routing_schema_modules}
+ for str_type in string_types]
+
plugin_schema = Schema({
('action'): Any(None, *list_dict_plugin_routing_schema),
('become'): Any(None, *list_dict_plugin_routing_schema),
@@ -207,8 +240,8 @@ def validate_metadata_file(path, is_ansible, check_deprecation_dates=False):
('httpapi'): Any(None, *list_dict_plugin_routing_schema),
('inventory'): Any(None, *list_dict_plugin_routing_schema),
('lookup'): Any(None, *list_dict_plugin_routing_schema),
- ('module_utils'): Any(None, *list_dict_plugin_routing_schema),
- ('modules'): Any(None, *list_dict_plugin_routing_schema),
+ ('module_utils'): Any(None, *list_dict_plugin_routing_schema_mu),
+ ('modules'): Any(None, *list_dict_plugin_routing_schema_modules),
('netconf'): Any(None, *list_dict_plugin_routing_schema),
('shell'): Any(None, *list_dict_plugin_routing_schema),
('strategy'): Any(None, *list_dict_plugin_routing_schema),