Fix cli_parse template_path read error (#51)

Fix cli_parse template_path read error

Reviewed-by: https://github.com/apps/ansible-zuul
pull/55/head
Ganesh Nalawade 2021-03-10 09:16:23 +05:30 committed by GitHub
parent 6411be3a2b
commit 4c531bb418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 9 deletions

View File

@ -0,0 +1,3 @@
---
bugfixes:
- Fix cli_parse template_path read error (https://github.com/ansible-collections/ansible.utils/pull/51).

View File

@ -94,14 +94,14 @@ class CliParser(CliParserBase):
template_path = self._task_args.get("parser").get("template_path")
if template_path and not os.path.isfile(template_path):
return {
"error": "error while reading template_path file {file}".format(
"errors": "error while reading template_path file {file}".format(
file=template_path
)
}
try:
template = open(self._task_args.get("parser").get("template_path"))
except IOError as exc:
return {"error": to_native(exc)}
return {"errors": to_native(exc)}
re_table = textfsm.TextFSM(template)
fsm_results = re_table.ParseText(cli_output)

View File

@ -99,7 +99,7 @@ class CliParser(CliParserBase):
)
if template_path and not os.path.isfile(template_path):
return {
"error": "error while reading template_path file {file}".format(
"errors": "error while reading template_path file {file}".format(
file=template_path
)
}

View File

@ -63,9 +63,9 @@ class TestTextfsmParser(unittest.TestCase):
}
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
result = parser.parse()
error = {
"error": "error while reading template_path file {0}".format(
errors = {
"errors": "error while reading template_path file {0}".format(
fake_path
)
}
self.assertEqual(result, error)
self.assertEqual(result, errors)

View File

@ -63,9 +63,9 @@ class TestTextfsmParser(unittest.TestCase):
}
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
result = parser.parse()
error = {
"error": "error while reading template_path file {0}".format(
errors = {
"errors": "error while reading template_path file {0}".format(
fake_path
)
}
self.assertEqual(result, error)
self.assertEqual(result, errors)