Fix processing of add_file_common_args=True when argument_spec is not specified as kwarg. (#72334)
This commit is contained in:
parent
dee8a4a8f1
commit
233e7beb5b
2 changed files with 14 additions and 12 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "ansible-test validate-modules - when a module uses ``add_file_common_args=True`` and does not use a keyword argument for ``argument_spec`` in ``AnsibleModule()``, the common file arguments were not considered added during validation (https://github.com/ansible/ansible/pull/72334)."
|
|
@ -146,19 +146,19 @@ def get_py_argument_spec(filename, collection):
|
||||||
raise AnsibleModuleNotInitialized()
|
raise AnsibleModuleNotInitialized()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
# for ping kwargs == {'argument_spec':{'data':{'type':'str','default':'pong'}}, 'supports_check_mode':True}
|
||||||
# for ping kwargs == {'argument_spec':{'data':{'type':'str','default':'pong'}}, 'supports_check_mode':True}
|
if 'argument_spec' in fake.kwargs:
|
||||||
argument_spec = fake.kwargs['argument_spec']
|
argument_spec = fake.kwargs['argument_spec']
|
||||||
# If add_file_common_args is truish, add options from FILE_COMMON_ARGUMENTS when not present.
|
else:
|
||||||
# This is the only modification to argument_spec done by AnsibleModule itself, and which is
|
argument_spec = fake.args[0]
|
||||||
# not caught by setup_env's AnsibleModule replacement
|
# If add_file_common_args is truish, add options from FILE_COMMON_ARGUMENTS when not present.
|
||||||
if fake.kwargs.get('add_file_common_args'):
|
# This is the only modification to argument_spec done by AnsibleModule itself, and which is
|
||||||
for k, v in FILE_COMMON_ARGUMENTS.items():
|
# not caught by setup_env's AnsibleModule replacement
|
||||||
if k not in argument_spec:
|
if fake.kwargs.get('add_file_common_args'):
|
||||||
argument_spec[k] = v
|
for k, v in FILE_COMMON_ARGUMENTS.items():
|
||||||
return argument_spec, fake.args, fake.kwargs
|
if k not in argument_spec:
|
||||||
except KeyError:
|
argument_spec[k] = v
|
||||||
return fake.args[0], fake.args, fake.kwargs
|
return argument_spec, fake.args, fake.kwargs
|
||||||
except (TypeError, IndexError):
|
except (TypeError, IndexError):
|
||||||
return {}, (), {}
|
return {}, (), {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue