diff --git a/plugins/module_utils/network/iosxr/facts/legacy/base.py b/plugins/module_utils/network/iosxr/facts/legacy/base.py index 0c5e0a90d..48574fc03 100644 --- a/plugins/module_utils/network/iosxr/facts/legacy/base.py +++ b/plugins/module_utils/network/iosxr/facts/legacy/base.py @@ -207,11 +207,9 @@ def parse_neighbors(self, neighbors): return facts def parse_cdp_neighbors(self, neighbors): + # import epdb; epdb.serve() facts = dict() - nbors = neighbors.split( - "------------------------------------------------", - ) - for entry in nbors[1:]: + for entry in neighbors.split("-------------------------"): if entry == "": continue intf_port = self.parse_cdp_intf_port(entry) diff --git a/tests/unit/modules/network/iosxr/fixtures/show_cdp b/tests/unit/modules/network/iosxr/fixtures/show_cdp new file mode 100644 index 000000000..cd5d89cee --- /dev/null +++ b/tests/unit/modules/network/iosxr/fixtures/show_cdp @@ -0,0 +1,4 @@ +Global CDP information: + Sending CDP packets every 60 seconds + Sending a holdtime value of 30 seconds + Sending CDPv2 advertisements is not enabled diff --git a/tests/unit/modules/network/iosxr/fixtures/show_cdp_neighbors_detail b/tests/unit/modules/network/iosxr/fixtures/show_cdp_neighbors_detail new file mode 100644 index 000000000..0e32e30c9 --- /dev/null +++ b/tests/unit/modules/network/iosxr/fixtures/show_cdp_neighbors_detail @@ -0,0 +1,16 @@ +------------------------- +Device ID: device2.cisco.com +Entry address(es): + IP address: 171.68.162.134 +Platform: cisco 4500, Capabilities: Router +Interface: Ethernet0/1, Port ID (outgoing port): Ethernet0 +Holdtime : 156 sec + +Version : +Cisco Internetwork Operating System Software +IOS (tm) 4500 Software (C4500-J-M), Version 11.1(10.4), MAINTENANCE INTERIM SOFTWARE +Copyright (c) 1986-1997 by Cisco Systems, Inc. +Compiled Mon 07-Apr-97 19:51 by dschwart + + +Total cdp entries displayed : 1 \ No newline at end of file diff --git a/tests/unit/modules/network/iosxr/test_iosxr_facts.py b/tests/unit/modules/network/iosxr/test_iosxr_facts.py index da7d597ae..ab0275ab2 100644 --- a/tests/unit/modules/network/iosxr/test_iosxr_facts.py +++ b/tests/unit/modules/network/iosxr/test_iosxr_facts.py @@ -22,7 +22,7 @@ __metaclass__ = type import json - +from ansible.module_utils.six import assertCountEqual from ansible_collections.cisco.iosxr.plugins.modules import iosxr_facts from ansible_collections.cisco.iosxr.tests.unit.compat.mock import patch from ansible_collections.cisco.iosxr.tests.unit.modules.utils import set_module_args @@ -131,3 +131,19 @@ def test_iosxr_facts_cpu_utilization(self): ansible_facts["ansible_net_cpu_utilization"], cpu_utilization_data, ) + + def test_iosxr_facts_neighbors(self): + set_module_args(dict(gather_subset="interfaces")) + result = self.execute_module() + ansible_facts = result["ansible_facts"]["ansible_net_neighbors"] + expected_neighbors = { + "Ethernet0/1": [ + { + "host": "device2.cisco.com", + "platform": "cisco 4500", + "port": "Ethernet0", + "ip": "171.68.162.134", + }, + ], + } + self.assertCountEqual(ansible_facts.keys(), expected_neighbors.keys())