Skip to content

Commit

Permalink
Fix parameters with aliases not being passed (#92)
Browse files Browse the repository at this point in the history
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 <None>
Reviewed-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
gravesm authored Oct 12, 2021
1 parent 4c2b7de commit 7bad786
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/92-fix-params-with-aliases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- fix parameters with aliases not being passed through (https://github.com/ansible-collections/cloud.common/issues/91).
2 changes: 1 addition & 1 deletion plugins/module_utils/turbo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/module_utils/test_turbo_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit 7bad786

Please sign in to comment.