Fix processing of add_file_common_args=True when argument_spec is not specified as kwarg. (#72334) (#72361)

(cherry picked from commit 233e7beb5b)
pull/72904/head
Felix Fontein 4 years ago committed by GitHub
parent 42da480721
commit 2ff5bf0f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)."

@ -145,10 +145,12 @@ def get_py_argument_spec(filename, collection):
if not fake.called:
raise AnsibleModuleNotInitialized()
try:
try:
# 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']
else:
argument_spec = fake.args[0]
# If add_file_common_args is truish, add options from FILE_COMMON_ARGUMENTS when not present.
# This is the only modification to argument_spec done by AnsibleModule itself, and which is
# not caught by setup_env's AnsibleModule replacement
@ -157,8 +159,6 @@ def get_py_argument_spec(filename, collection):
if k not in argument_spec:
argument_spec[k] = v
return argument_spec, fake.args, fake.kwargs
except KeyError:
return fake.args[0], fake.args, fake.kwargs
except (TypeError, IndexError):
return {}, (), {}

Loading…
Cancel
Save