Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruchip16 committed Nov 29, 2023
1 parent 4cd0fbe commit c4f6c0c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
6 changes: 2 additions & 4 deletions plugins/module_utils/network/iosxr/facts/legacy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/modules/network/iosxr/fixtures/show_cdp
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion tests/unit/modules/network/iosxr/test_iosxr_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())

0 comments on commit c4f6c0c

Please sign in to comment.