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

validate-modules: don't error on valid Ansible YAML in EXAMPLES #74384

Merged
merged 1 commit into from
Apr 22, 2021
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
2 changes: 2 additions & 0 deletions changelogs/fragments/74384-validate-modules-yaml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ansible-test validate-modules - EXAMPLES will no longer be marked as invalid YAML when it uses Ansible-specific YAML tags (https://github.com/ansible/ansible/pull/74384).
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ def _validate_docs(self):
else:
_doc, errors, traces = parse_yaml(doc_info['EXAMPLES']['value'],
doc_info['EXAMPLES']['lineno'],
self.name, 'EXAMPLES', load_all=True)
self.name, 'EXAMPLES', load_all=True,
ansible_loader=True)
for error in errors:
self.reporter.error(
path=self.object_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.yaml import SafeLoader
from ansible.module_utils.six import string_types
from ansible.parsing.yaml.loader import AnsibleLoader


class AnsibleTextIOWrapper(TextIOWrapper):
Expand Down Expand Up @@ -133,18 +135,23 @@ def get_module_name_from_filename(filename, collection):
return name


def parse_yaml(value, lineno, module, name, load_all=False):
def parse_yaml(value, lineno, module, name, load_all=False, ansible_loader=False):
traces = []
errors = []
data = None

if load_all:
loader = yaml.safe_load_all
yaml_load = yaml.load_all
else:
loader = yaml.safe_load
yaml_load = yaml.load

if ansible_loader:
loader = AnsibleLoader
else:
loader = SafeLoader

try:
data = loader(value)
data = yaml_load(value, Loader=loader)
if load_all:
data = list(data)
except yaml.MarkedYAMLError as e:
Expand Down