Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent metadata changes in a stable branch #48994

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docsite/rst/dev_guide/testing_validate-modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Errors
331 argument in argument_spec must be a dictionary/hash when used
332 ``AnsibleModule`` schema validation error
333 ``ANSIBLE_METADATA.status`` of deprecated or removed can't include other statuses
334 ``ANSIBLE_METADATA`` cannot be changed in a point release for a stable branch

..
--------- -------------------
Expand Down
16 changes: 12 additions & 4 deletions test/sanity/validate-modules/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,14 +873,14 @@ def _validate_docs(self):
filename_deprecated_or_removed = True

# Have to check the metadata first so that we know if the module is removed or deprecated
metadata = None
if not bool(doc_info['ANSIBLE_METADATA']['value']):
self.reporter.error(
path=self.object_path,
code=314,
msg='No ANSIBLE_METADATA provided'
)
else:
metadata = None
if isinstance(doc_info['ANSIBLE_METADATA']['value'], ast.Dict):
metadata = ast.literal_eval(
doc_info['ANSIBLE_METADATA']['value']
Expand Down Expand Up @@ -998,7 +998,7 @@ def _validate_docs(self):
self._validate_docs_schema(doc, doc_schema(self.object_name.split('.')[0]), 'DOCUMENTATION', 305)

self._check_version_added(doc)
self._check_for_new_args(doc)
self._check_for_new_args(doc, metadata)

if not bool(doc_info['EXAMPLES']['value']):
self.reporter.error(
Expand Down Expand Up @@ -1309,13 +1309,13 @@ def _validate_argument_spec(self, docs, spec, kwargs):
msg='"%s" is listed in DOCUMENTATION.options, but not accepted by the module' % arg
)

def _check_for_new_args(self, doc):
def _check_for_new_args(self, doc, metadata):
if not self.base_branch or self._is_new_module():
return

with CaptureStd():
try:
existing_doc = get_docstring(self.base_module, fragment_loader, verbose=True)[0]
existing_doc, dummy_examples, dummy_return, existing_metadata = get_docstring(self.base_module, fragment_loader, verbose=True)
existing_options = existing_doc.get('options', {}) or {}
except AssertionError:
fragment = doc['extends_documentation_fragment']
Expand Down Expand Up @@ -1346,6 +1346,14 @@ def _check_for_new_args(self, doc):
except ValueError:
mod_version_added = StrictVersion('0.0')

if self.base_branch and 'stable-' in self.base_branch:
if metadata != existing_metadata:
self.reporter.error(
path=self.object_path,
code=334,
msg=('ANSIBLE_METADATA cannot be changed in a point release for a stable branch')
)

options = doc.get('options', {}) or {}

should_be = '.'.join(ansible_version.split('.')[:2])
Expand Down