From 049800c06376ee8d10366297f2ec82ccf7f8f932 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 4 May 2020 12:15:16 -0700 Subject: [PATCH] Fix metadata defaults * Metadata defaults were not being set if only a few fields were missing. * ansible-doc with no documentation and no status in metadata should return empty, just like if there was no documentation and no metadata at all. --- changelogs/fragments/fix-metadata-defaults.yml | 5 +++++ lib/ansible/parsing/plugin_docs.py | 13 ++++++++++--- test/integration/targets/ansible-doc/test.yml | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/fix-metadata-defaults.yml diff --git a/changelogs/fragments/fix-metadata-defaults.yml b/changelogs/fragments/fix-metadata-defaults.yml new file mode 100644 index 00000000000..e12f00c4667 --- /dev/null +++ b/changelogs/fragments/fix-metadata-defaults.yml @@ -0,0 +1,5 @@ +bugfixes: +- Plugin Metadata is supposed to have default values. When the metadata was + missing entirely, we were properly setting the defaults. Fixed the metadata + parsing so that the defaults are also set when we were missing just a few + fields. diff --git a/lib/ansible/parsing/plugin_docs.py b/lib/ansible/parsing/plugin_docs.py index 73945306c24..4f036127e0f 100644 --- a/lib/ansible/parsing/plugin_docs.py +++ b/lib/ansible/parsing/plugin_docs.py @@ -67,9 +67,16 @@ def read_docstring(filename, verbose=True, ignore_errors=True): if data['metadata']: # remove version - for x in ('version', 'metadata_version'): - if x in data['metadata']: - del data['metadata'][x] + for field in ('version', 'metadata_version'): + if field in data['metadata']: + del data['metadata'][field] + + if 'supported_by' not in data['metadata']: + data['metadata']['supported_by'] = 'community' + + if 'status' not in data['metadata']: + data['metadata']['status'] = ['preview'] + else: # Add default metadata data['metadata'] = {'supported_by': 'community', diff --git a/test/integration/targets/ansible-doc/test.yml b/test/integration/targets/ansible-doc/test.yml index a6944c44622..1781caad46b 100644 --- a/test/integration/targets/ansible-doc/test.yml +++ b/test/integration/targets/ansible-doc/test.yml @@ -85,8 +85,8 @@ register: result - assert: that: - - 'result is failed' - - '"ERROR! module test_no_docs_no_status missing documentation (or could not parse documentation): test_no_docs_no_status did not contain a DOCUMENTATION attribute" in result.stderr' + - 'result.stdout == ""' + - 'result.stderr == ""' - name: module with no documentation and non-iterable status in metadata command: ansible-doc test_no_docs_non_iterable_status