From 7b5dad23214804c79d318784460c5d365f04e852 Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Thu, 22 Apr 2021 06:48:43 +0000 Subject: [PATCH] validate-modules: don't error on valid Ansible YAML in EXAMPLES --- .../fragments/74384-validate-modules-yaml.yml | 2 ++ .../validate-modules/validate_modules/main.py | 3 ++- .../validate-modules/validate_modules/utils.py | 15 +++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/74384-validate-modules-yaml.yml diff --git a/changelogs/fragments/74384-validate-modules-yaml.yml b/changelogs/fragments/74384-validate-modules-yaml.yml new file mode 100644 index 00000000000..b55d00b751d --- /dev/null +++ b/changelogs/fragments/74384-validate-modules-yaml.yml @@ -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). diff --git a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py index 1e713674faf..8b8fceab55a 100644 --- a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py +++ b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/main.py @@ -1069,7 +1069,8 @@ class ModuleValidator(Validator): 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, diff --git a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/utils.py b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/utils.py index 939ae651da8..ac46f6669f6 100644 --- a/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/utils.py +++ b/test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/utils.py @@ -31,7 +31,9 @@ import yaml.reader 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): @@ -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: