ios_facts: Gather CDP neighbor data (#49129)

* ios_facts: Gather CDP neighbor data

* ios_facts: Create tests for ansible_net_neighbors
This commit is contained in:
Paul Neumann 2018-11-29 20:05:17 +01:00 committed by Nathaniel Case
parent a51eca364f
commit a914f494a8
6 changed files with 162 additions and 3 deletions

View file

@ -0,0 +1,4 @@
Global CDP information:
Sending CDP packets every 60 seconds
Sending a holdtime value of 180 seconds
Sending CDPv2 advertisements is enabled

View file

@ -0,0 +1,40 @@
-------------------------
Device ID: R2
Entry address(es):
IP address: 10.0.0.3
Platform: cisco CSR1000V, Capabilities: Router IGMP
Interface: GigabitEthernet1, Port ID (outgoing port): GigabitEthernet2
Holdtime : 149 sec
Version :
Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Sun 08-Jul-18 04:30 by mcpre
advertisement version: 2
Duplex: full
Management address(es):
IP address: 10.0.0.3
-------------------------
Device ID: R3
Entry address(es):
IP address: 10.0.0.4
Platform: cisco CSR1000V, Capabilities: Router IGMP
Interface: GigabitEthernet1, Port ID (outgoing port): GigabitEthernet3
Holdtime : 149 sec
Version :
Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Sun 08-Jul-18 04:30 by mcpre
advertisement version: 2
Duplex: full
Management address(es):
IP address: 10.0.0.4
Total cdp entries displayed : 2

View file

@ -0,0 +1,6 @@
Global LLDP Information:
Status: ACTIVE
LLDP advertisements are sent every 30 seconds
LLDP hold time advertised is 120 seconds
LLDP interface reinitialisation delay is 2 seconds

View file

@ -0,0 +1,50 @@
------------------------------------------------
Local Intf: Gi1
Chassis id: 001e.14d4.5300
Port id: Gi3
Port Description: GigabitEthernet3
System Name: R3
System Description:
Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Sun 08-Jul-18 04:30 by
Time remaining: 116 seconds
System Capabilities: B,R
Enabled Capabilities: R
Management Addresses:
IP: 10.0.0.4
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type - not advertised
Vlan ID: - not advertised
------------------------------------------------
Local Intf: Gi3
Chassis id: 001e.e6c9.6d00
Port id: Gi1
Port Description: GigabitEthernet1
System Name: Rtest
System Description:
Cisco IOS Software [Everest], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.4, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2018 by Cisco Systems, Inc.
Compiled Sun 08-Jul-18 04:30 by
Time remaining: 116 seconds
System Capabilities: B,R
Enabled Capabilities: R
Management Addresses:
IP: 10.3.0.3
Auto Negotiation - not supported
Physical media capabilities - not advertised
Media Attachment Unit type - not advertised
Vlan ID: - not advertised
Total entries displayed: 2

View file

@ -19,6 +19,7 @@ __metaclass__ = type
from units.compat.mock import patch
from ansible.modules.network.ios import ios_facts
from ansible.module_utils.six import assertCountEqual
from units.modules.utils import set_module_args
from .ios_module import TestIosModule, load_fixture
@ -87,3 +88,20 @@ class TestIosFactsModule(TestIosModule):
self.assertEqual(
result['ansible_facts']['ansible_net_filesystems_info']['bootflash:']['spacefree_kb'], 6453180.0
)
def test_ios_facts_neighbors(self):
set_module_args(dict(gather_subset='interfaces'))
result = self.execute_module()
assertCountEqual(
self,
result['ansible_facts']['ansible_net_neighbors'].keys(), ['GigabitEthernet1', 'GigabitEthernet3']
)
assertCountEqual(
self,
result['ansible_facts']['ansible_net_neighbors']['GigabitEthernet1'],
[{'host': 'R2', 'port': 'GigabitEthernet2'}, {'host': 'R3', 'port': 'GigabitEthernet3'}]
)
assertCountEqual(
self,
result['ansible_facts']['ansible_net_neighbors']['GigabitEthernet3'], [{'host': 'Rtest', 'port': 'Gi1'}]
)