From aa37f3cf258d9ccdc26133bb65fd4e77c5ef221a Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Mon, 22 Jan 2024 22:08:54 +0530 Subject: [PATCH] [backport][stable-2.14] Support `action_plugin` in plugin_routing_schema (#82562) (#82583) * Support `action_plugin` in plugin_routing_schema (#82562) now validation schema matches reality Signed-off-by: NilashishC Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com> (cherry picked from commit b01f1f207c9c46eda8f8e8ffab8bd4b99e03c754) * Module redirects should be FQCR Signed-off-by: NilashishC * pep8 fixes Signed-off-by: NilashishC --------- Signed-off-by: NilashishC --- ...runtime-metadata-modules-action_plugin.yml | 4 ++ .../ns/col/meta/runtime.yml | 4 ++ .../ns/failure/meta/runtime.yml | 4 ++ .../runme.sh | 10 ++++ .../ns/col/meta/runtime.yml | 2 +- .../sanity/code-smell/runtime-metadata.py | 46 +++++++++++++++---- 6 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/fix-runtime-metadata-modules-action_plugin.yml create mode 100644 test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/meta/runtime.yml create mode 100644 test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/failure/meta/runtime.yml diff --git a/changelogs/fragments/fix-runtime-metadata-modules-action_plugin.yml b/changelogs/fragments/fix-runtime-metadata-modules-action_plugin.yml new file mode 100644 index 00000000000..7826c8c0d24 --- /dev/null +++ b/changelogs/fragments/fix-runtime-metadata-modules-action_plugin.yml @@ -0,0 +1,4 @@ +bugfixes: +- >- + ``ansible-test sanity --test runtime-metadata`` - add ``action_plugin`` as a valid field + for modules in the schema (https://github.com/ansible/ansible/pull/82562). diff --git a/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/meta/runtime.yml b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/meta/runtime.yml new file mode 100644 index 00000000000..7c4b25dd3f0 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/col/meta/runtime.yml @@ -0,0 +1,4 @@ +plugin_routing: + modules: + module: + action_plugin: ns.col.action diff --git a/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/failure/meta/runtime.yml b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/failure/meta/runtime.yml new file mode 100644 index 00000000000..7c163fea15b --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-validate-modules/ansible_collections/ns/failure/meta/runtime.yml @@ -0,0 +1,4 @@ +plugin_routing: + lookup: + lookup: + action_plugin: invalid diff --git a/test/integration/targets/ansible-test-sanity-validate-modules/runme.sh b/test/integration/targets/ansible-test-sanity-validate-modules/runme.sh index e0299969c39..57c497c9fff 100755 --- a/test/integration/targets/ansible-test-sanity-validate-modules/runme.sh +++ b/test/integration/targets/ansible-test-sanity-validate-modules/runme.sh @@ -8,6 +8,16 @@ ansible-test sanity --test validate-modules --color --truncate 0 --failure-ok -- diff -u "${TEST_DIR}/expected.txt" actual-stdout.txt grep -f "${TEST_DIR}/expected.txt" actual-stderr.txt +cd ../col +ansible-test sanity --test runtime-metadata + +cd ../failure +if ansible-test sanity --test runtime-metadata 2>&1 | tee out.txt; then + echo "runtime-metadata in failure should be invalid" + exit 1 +fi +grep out.txt -e 'extra keys not allowed' + cd ../ps_only if ! command -V pwsh; then diff --git a/test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/meta/runtime.yml b/test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/meta/runtime.yml index fee22ad8c68..49bc20b35f9 100644 --- a/test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/meta/runtime.yml +++ b/test/integration/targets/ansible-test-sanity/ansible_collections/ns/col/meta/runtime.yml @@ -2,4 +2,4 @@ requires_ansible: '>=2.11' # force ansible-doc to check the Ansible version (re plugin_routing: modules: hi: - redirect: hello + redirect: ns.col2.hello 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 6cf2777401a..f1b759d7447 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 @@ -184,17 +194,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 +237,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),