From f2b552fa7e40832e684081e999558f9f67f4390b Mon Sep 17 00:00:00 2001 From: Ganesh B Nalawade Date: Tue, 9 Mar 2021 11:14:21 +0530 Subject: [PATCH 1/2] Fix cli_parse template_path read error * If sub-plugins (ttp, textfsm) fails to pass template file path return the error as value of `errors` key instead on `error` as the `cli_parse` action plugin expects `errors` key --- 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 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/sub_plugins/cli_parser/textfsm_parser.py b/plugins/sub_plugins/cli_parser/textfsm_parser.py index 0bdf949e..3d1e19bb 100644 --- a/plugins/sub_plugins/cli_parser/textfsm_parser.py +++ b/plugins/sub_plugins/cli_parser/textfsm_parser.py @@ -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) diff --git a/plugins/sub_plugins/cli_parser/ttp_parser.py b/plugins/sub_plugins/cli_parser/ttp_parser.py index c1429fc6..bd8098d2 100644 --- a/plugins/sub_plugins/cli_parser/ttp_parser.py +++ b/plugins/sub_plugins/cli_parser/ttp_parser.py @@ -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 ) } 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 9b4625ca..2d760977 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 @@ 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) 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 9a8ebab1..c4a7add1 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 @@ 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) From 74996ac9328f66052353306a732f46243e2def1f Mon Sep 17 00:00:00 2001 From: Ganesh B Nalawade Date: Tue, 9 Mar 2021 11:19:57 +0530 Subject: [PATCH 2/2] add changelogs --- changelogs/fragments/cli_parse_errors_return.yaml | 3 +++ 1 file changed, 3 insertions(+) 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 00000000..9b173ed1 --- /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).