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). 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)