Created
August 25, 2020 14:42
-
-
Save NilashishC/c488e9c3d9d98880817470f40ae19298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (c) 2020 Ansible Project | |
| # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | |
| from __future__ import absolute_import, division, print_function | |
| __metaclass__ = type | |
| import os | |
| from ansible.playbook.task import Task | |
| from ansible.template import Templar | |
| from ansible_collections.ansible.netcommon.tests.unit.compat import unittest | |
| from ansible_collections.ansible.netcommon.tests.unit.compat.mock import ( | |
| MagicMock, | |
| ) | |
| from ansible_collections.ansible.netcommon.tests.unit.mock.loader import ( | |
| DictDataLoader, | |
| ) | |
| from ansible_collections.ansible.netcommon.plugins.action.cli_parse import ( | |
| ActionModule, | |
| ) | |
| class TestPyatsParser(unittest.TestCase): | |
| task = MagicMock(Task) | |
| play_context = MagicMock() | |
| play_context.check_mode = False | |
| connection = MagicMock() | |
| fake_loader = DictDataLoader({}) | |
| templar = Templar(loader=fake_loader) | |
| def load_fixture(self, filename): | |
| nxos_cfg_path = os.path.join( | |
| os.path.dirname(__file__), "fixtures", filename | |
| ) | |
| with open(nxos_cfg_path) as f: | |
| return f.read() | |
| def test_pyats_parser(self): | |
| self.task.args = { | |
| "text": self.load_fixture("nxos_show_version.cfg"), | |
| "parser": { | |
| "name": "ansible.netcommon.pyats", | |
| "command": "show version", | |
| }, | |
| } | |
| self.task_vars = {"ansible_network_os": "cisco.nxos.nxos"} | |
| self.task.action = "cli_parse" | |
| plugin = ActionModule( | |
| self.task, | |
| self.connection, | |
| self.play_context, | |
| loader=None, | |
| templar=self.templar, | |
| shared_loader_obj=None, | |
| ) | |
| plugin._execute_module = MagicMock() | |
| result = plugin.run(task_vars=self.task_vars) | |
| parsed_output = { | |
| "platform": { | |
| "hardware": { | |
| "bootflash": "3509454 kB", | |
| "chassis": "Nexus9000 9000v", | |
| "cpu": "", | |
| "device_name": "an-nxos9k-01", | |
| "memory": "4041236 kB", | |
| "model": "Nexus9000 9000v", | |
| "processor_board_id": "96NK4OUJH32", | |
| "rp": "None", | |
| "slots": "None", | |
| }, | |
| "kernel_uptime": { | |
| "days": 12, | |
| "hours": 23, | |
| "minutes": 48, | |
| "seconds": 10, | |
| }, | |
| "name": "Nexus", | |
| "os": "NX-OS", | |
| "reason": "Unknown", | |
| "software": { | |
| "system_compile_time": "8/31/2017 14:00:00 [08/31/2017 22:29:32]", | |
| "system_image_file": "bootflash:///nxos.7.0.3.I7.1.bin", | |
| "system_version": "7.0(3)I7(1)", | |
| }, | |
| } | |
| } | |
| self.assertEqual(result, {"parsed": parsed_output}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment