From 4c531bb4186d29f3d6a202d244957835fc54ca5d Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Wed, 10 Mar 2021 09:16:23 +0530 Subject: [PATCH] Fix cli_parse template_path read error (#51) Fix cli_parse template_path read error Reviewed-by: https://github.com/apps/ansible-zuul --- changelogs/fragments/cli_parse_errors_return.yaml | 3 +++ plugins/sub_plugins/cli_parser/textfsm_parser.py | 4 ++-- plugins/sub_plugins/cli_parser/ttp_parser.py | 2 +- .../plugins/sub_plugins/cli_parsers/test_textfsm_parser.py | 6 +++--- .../unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py | 6 +++--- 5 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/cli_parse_errors_return.yaml diff --git a/changelogs/fragments/cli_parse_errors_return.yaml b/changelogs/fragments/cli_parse_errors_return.yaml new file mode 100644 index 0000000..9b173ed --- /dev/null +++ b/changelogs/fragments/cli_parse_errors_return.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix cli_parse template_path read error (https://github.com/ansible-collections/ansible.utils/pull/51). diff --git a/plugins/sub_plugins/cli_parser/textfsm_parser.py b/plugins/sub_plugins/cli_parser/textfsm_parser.py index 0bdf949..3d1e19b 100644 --- a/plugins/sub_plugins/cli_parser/textfsm_parser.py +++ b/plugins/sub_plugins/cli_parser/textfsm_parser.py @@ -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) diff --git a/plugins/sub_plugins/cli_parser/ttp_parser.py b/plugins/sub_plugins/cli_parser/ttp_parser.py index c1429fc..bd8098d 100644 --- a/plugins/sub_plugins/cli_parser/ttp_parser.py +++ b/plugins/sub_plugins/cli_parser/ttp_parser.py @@ -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 ) } diff --git a/tests/unit/plugins/sub_plugins/cli_parsers/test_textfsm_parser.py b/tests/unit/plugins/sub_plugins/cli_parsers/test_textfsm_parser.py index 9b4625c..2d76097 100644 --- a/tests/unit/plugins/sub_plugins/cli_parsers/test_textfsm_parser.py +++ b/tests/unit/plugins/sub_plugins/cli_parsers/test_textfsm_parser.py @@ -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) diff --git a/tests/unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py b/tests/unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py index 9a8ebab..c4a7add 100644 --- a/tests/unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py +++ b/tests/unit/plugins/sub_plugins/cli_parsers/test_ttp_parser.py @@ -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)