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

Fix cli_parse template_path read error #51

Merged
merged 2 commits into from
Mar 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/cli_parse_errors_return.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fix cli_parse template_path read error (https://github.com/ansible-collections/ansible.utils/pull/51).
4 changes: 2 additions & 2 deletions plugins/sub_plugins/cli_parser/textfsm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def parse(self, *_args, **_kwargs):
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)
Expand Down
2 changes: 1 addition & 1 deletion plugins/sub_plugins/cli_parser/ttp_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def parse(self, *_args, **_kwargs):
)
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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_textfsm_parser_invalid_parser(self):
}
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)
6 changes: 3 additions & 3 deletions tests/unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_textfsm_parser_invalid_parser(self):
}
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)