Fix cli_parse template_path read error (#51)
Fix cli_parse template_path read error Reviewed-by: https://github.com/apps/ansible-zuulpull/55/head
parent
6411be3a2b
commit
4c531bb418
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- Fix cli_parse template_path read error (https://github.com/ansible-collections/ansible.utils/pull/51).
|
|
@ -94,14 +94,14 @@ class CliParser(CliParserBase):
|
||||||
template_path = self._task_args.get("parser").get("template_path")
|
template_path = self._task_args.get("parser").get("template_path")
|
||||||
if template_path and not os.path.isfile(template_path):
|
if template_path and not os.path.isfile(template_path):
|
||||||
return {
|
return {
|
||||||
"error": "error while reading template_path file {file}".format(
|
"errors": "error while reading template_path file {file}".format(
|
||||||
file=template_path
|
file=template_path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
template = open(self._task_args.get("parser").get("template_path"))
|
template = open(self._task_args.get("parser").get("template_path"))
|
||||||
except IOError as exc:
|
except IOError as exc:
|
||||||
return {"error": to_native(exc)}
|
return {"errors": to_native(exc)}
|
||||||
|
|
||||||
re_table = textfsm.TextFSM(template)
|
re_table = textfsm.TextFSM(template)
|
||||||
fsm_results = re_table.ParseText(cli_output)
|
fsm_results = re_table.ParseText(cli_output)
|
||||||
|
|
|
@ -99,7 +99,7 @@ class CliParser(CliParserBase):
|
||||||
)
|
)
|
||||||
if template_path and not os.path.isfile(template_path):
|
if template_path and not os.path.isfile(template_path):
|
||||||
return {
|
return {
|
||||||
"error": "error while reading template_path file {file}".format(
|
"errors": "error while reading template_path file {file}".format(
|
||||||
file=template_path
|
file=template_path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ class TestTextfsmParser(unittest.TestCase):
|
||||||
}
|
}
|
||||||
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
|
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
|
||||||
result = parser.parse()
|
result = parser.parse()
|
||||||
error = {
|
errors = {
|
||||||
"error": "error while reading template_path file {0}".format(
|
"errors": "error while reading template_path file {0}".format(
|
||||||
fake_path
|
fake_path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
self.assertEqual(result, error)
|
self.assertEqual(result, errors)
|
||||||
|
|
|
@ -63,9 +63,9 @@ class TestTextfsmParser(unittest.TestCase):
|
||||||
}
|
}
|
||||||
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
|
parser = CliParser(task_args=task_args, task_vars=[], debug=False)
|
||||||
result = parser.parse()
|
result = parser.parse()
|
||||||
error = {
|
errors = {
|
||||||
"error": "error while reading template_path file {0}".format(
|
"errors": "error while reading template_path file {0}".format(
|
||||||
fake_path
|
fake_path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
self.assertEqual(result, error)
|
self.assertEqual(result, errors)
|
||||||
|
|
Loading…
Reference in New Issue