validate-modules: don't error on valid Ansible YAML in EXAMPLES
This commit is contained in:
parent
567361b124
commit
7b5dad2321
3 changed files with 15 additions and 5 deletions
2
changelogs/fragments/74384-validate-modules-yaml.yml
Normal file
2
changelogs/fragments/74384-validate-modules-yaml.yml
Normal file
|
@ -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).
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue