From 7bad7862ed6be7866190dad8bda9d70c3b5b4af6 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 12 Oct 2021 14:07:17 -0400 Subject: [PATCH] Fix parameters with aliases not being passed (#92) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix parameters with aliases not being passed Depends-On: ansible/ansible-zuul-jobs#1176 SUMMARY The recently added _is_an_alias() function should check whether the current key is in the list of aliases. Fixes: #91 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: None Reviewed-by: Gonéri Le Bouder --- changelogs/fragments/92-fix-params-with-aliases.yml | 3 +++ plugins/module_utils/turbo/module.py | 2 +- tests/unit/module_utils/test_turbo_module.py | 13 ++++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/92-fix-params-with-aliases.yml diff --git a/changelogs/fragments/92-fix-params-with-aliases.yml b/changelogs/fragments/92-fix-params-with-aliases.yml new file mode 100644 index 0000000..5e1be2d --- /dev/null +++ b/changelogs/fragments/92-fix-params-with-aliases.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - fix parameters with aliases not being passed through (https://github.com/ansible-collections/cloud.common/issues/91). diff --git a/plugins/module_utils/turbo/module.py b/plugins/module_utils/turbo/module.py index b2d9a67..4d71cf8 100644 --- a/plugins/module_utils/turbo/module.py +++ b/plugins/module_utils/turbo/module.py @@ -80,7 +80,7 @@ def _keep_value(v, argument_specs, key, subkey=None): def _is_an_alias(k): aliases = argument_specs[k].get("aliases") - return aliases and k != aliases[0] + return aliases and k in aliases new_params = {} for k, v in params.items(): diff --git a/tests/unit/module_utils/test_turbo_module.py b/tests/unit/module_utils/test_turbo_module.py index 1aa85e2..00756a0 100644 --- a/tests/unit/module_utils/test_turbo_module.py +++ b/tests/unit/module_utils/test_turbo_module.py @@ -129,9 +129,12 @@ def test_prepare_args_subkey_with_default(): def test_prepare_args_dedup_aliases(): - argspec = { - "foo": {"aliases": ["bar"], "type": int}, - "bar": {"aliases": ["bar"], "type": int}, - } + argspec = {"foo": {"aliases": ["bar"], "type": int}} params = {"foo": 1, "bar": 1} - assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"bar": 1}} + assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"foo": 1}} + + +def test_prepare_args_with_aliases(): + argspec = {"foo": {"aliases": ["bar"], "type": int}} + params = {"foo": 1} + assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"foo": 1}}