Skip to content

Commit

Permalink
Priperly filter out aliases
Browse files Browse the repository at this point in the history
Prevous attempt at filtering aliases was broken because it filtered
out an actual main parameter name and replace it with the first
available alias.
  • Loading branch information
Tadej Borovšak committed Oct 11, 2021
1 parent a6fece1 commit 5b72fcb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions plugins/module_utils/turbo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def _keep_value(v, argument_specs, key, subkey=None):
return True

def _is_an_alias(k):
aliases = argument_specs[k].get("aliases")
return aliases and k != aliases[0]
return k in argument_specs[k].get("aliases", [])

new_params = {}
for k, v in params.items():
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/module_utils/test_turbo_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,22 @@ def test_prepare_args_dedup_aliases():
"bar": {"aliases": ["bar"], "type": int},
}
params = {"foo": 1, "bar": 1}
assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"foo": 1}}


def test_prepare_args_dedup_aliases_only_value():
argspec = {
"foo": {"aliases": ["bar"], "type": int},
"bar": {"aliases": ["bar"], "type": int},
}
params = {"foo": 1}
assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"foo": 1}}


def test_prepare_args_dedup_aliases_only_alias():
argspec = {
"foo": {"aliases": ["bar"], "type": int},
"bar": {"aliases": ["bar"], "type": int},
}
params = {"bar": 1}
assert prepare_args(argspec, params) == {"ANSIBLE_MODULE_ARGS": {"bar": 1}}

0 comments on commit 5b72fcb

Please sign in to comment.