From cad351328d7cd27ab24ff2b03bd14b65ecd7bf87 Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Thu, 31 May 2018 10:45:17 -0400 Subject: [PATCH] Search for macaddresses more stringently (#40901) * Search for macaddresses more stringently Fixes #40829 (cherry picked from commit e7afd3d378479195f5da715f9ba74264bd95bcab) --- lib/ansible/modules/network/ios/ios_facts.py | 2 +- .../ios/fixtures/ios_facts_show_interfaces | 61 +++++++++++++++++++ .../ios/fixtures/ios_facts_show_ip_interface | 0 .../fixtures/ios_facts_show_ipv6_interface | 0 .../network/ios/fixtures/ios_facts_show_lldp | 0 .../modules/network/ios/test_ios_facts.py | 13 ++++ 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/units/modules/network/ios/fixtures/ios_facts_show_interfaces create mode 100644 test/units/modules/network/ios/fixtures/ios_facts_show_ip_interface create mode 100644 test/units/modules/network/ios/fixtures/ios_facts_show_ipv6_interface create mode 100644 test/units/modules/network/ios/fixtures/ios_facts_show_lldp diff --git a/lib/ansible/modules/network/ios/ios_facts.py b/lib/ansible/modules/network/ios/ios_facts.py index 78e6f0ff9f3..0793f1a9ce6 100644 --- a/lib/ansible/modules/network/ios/ios_facts.py +++ b/lib/ansible/modules/network/ios/ios_facts.py @@ -379,7 +379,7 @@ class Interfaces(FactsBase): return match.group(1) def parse_macaddress(self, data): - match = re.search(r'address is (\S+)', data) + match = re.search(r'Hardware is (?:.*), address is (\S+)', data) if match: return match.group(1) diff --git a/test/units/modules/network/ios/fixtures/ios_facts_show_interfaces b/test/units/modules/network/ios/fixtures/ios_facts_show_interfaces new file mode 100644 index 00000000000..002b8b9eeed --- /dev/null +++ b/test/units/modules/network/ios/fixtures/ios_facts_show_interfaces @@ -0,0 +1,61 @@ +GigabitEthernet0/0 is up, line protocol is up + Hardware is iGbE, address is 5e00.0003.0000 (bia 5e00.0003.0000) + Description: OOB Management + Internet address is 10.8.38.66/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 253/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, Auto Speed, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:00, output 00:00:00, output hang never + Last clearing of "show interface" counters never + Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 3000 bits/sec, 2 packets/sec + 5 minute output rate 2000 bits/sec, 2 packets/sec + 2226666 packets input, 398288440 bytes, 0 no buffer + Received 156442 broadcasts (0 IP multicasts) + 25440 runts, 0 giants, 0 throttles + 25440 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 1304895 packets output, 119337031 bytes, 0 underruns + 0 output errors, 0 collisions, 3 interface resets + 1083697 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 1 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out +GigabitEthernet1 is up, line protocol is up + Hardware is CSR vNIC, address is 5e00.0006.0000 (bia 5e00.0006.0000) + Description: OOB Management + Internet address is 10.8.38.67/24 + MTU 1500 bytes, BW 1000000 Kbit/sec, DLY 10 usec, + reliability 255/255, txload 1/255, rxload 1/255 + Encapsulation ARPA, loopback not set + Keepalive set (10 sec) + Full Duplex, 1000Mbps, link type is auto, media type is RJ45 + output flow-control is unsupported, input flow-control is unsupported + ARP type: ARPA, ARP Timeout 04:00:00 + Last input 00:00:01, output 00:00:07, output hang never + Last clearing of "show interface" counters never + Input queue: 0/375/0/0 (size/max/drops/flushes); Total output drops: 0 + Queueing strategy: fifo + Output queue: 0/40 (size/max) + 5 minute input rate 3000 bits/sec, 3 packets/sec + 5 minute output rate 3000 bits/sec, 3 packets/sec + 8463791 packets input, 1445150230 bytes, 0 no buffer + Received 0 broadcasts (0 IP multicasts) + 0 runts, 0 giants, 0 throttles + 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored + 0 watchdog, 0 multicast, 0 pause input + 3521571 packets output, 348781823 bytes, 0 underruns + 0 output errors, 0 collisions, 1 interface resets + 4150764 unknown protocol drops + 0 babbles, 0 late collision, 0 deferred + 0 lost carrier, 0 no carrier, 0 pause output + 0 output buffer failures, 0 output buffers swapped out +Tunnel1110 is up, line protocol is up + Hardware is Tunnel + Internet address is 10.10.10.2/30 diff --git a/test/units/modules/network/ios/fixtures/ios_facts_show_ip_interface b/test/units/modules/network/ios/fixtures/ios_facts_show_ip_interface new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/network/ios/fixtures/ios_facts_show_ipv6_interface b/test/units/modules/network/ios/fixtures/ios_facts_show_ipv6_interface new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/network/ios/fixtures/ios_facts_show_lldp b/test/units/modules/network/ios/fixtures/ios_facts_show_lldp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/units/modules/network/ios/test_ios_facts.py b/test/units/modules/network/ios/test_ios_facts.py index c6bd8ca2208..9557b7d9066 100644 --- a/test/units/modules/network/ios/test_ios_facts.py +++ b/test/units/modules/network/ios/test_ios_facts.py @@ -64,3 +64,16 @@ class TestIosFactsModule(TestIosModule): self.assertEqual( result['ansible_facts']['ansible_net_stacked_serialnums'], ['CAT0726R0ZU', 'CAT0726R10A', 'CAT0732R0M4'] ) + + def test_ios_facts_tunnel_address(self): + set_module_args(dict(gather_subset='interfaces')) + result = self.execute_module() + self.assertEqual( + result['ansible_facts']['ansible_net_interfaces']['GigabitEthernet0/0']['macaddress'], '5e00.0003.0000' + ) + self.assertEqual( + result['ansible_facts']['ansible_net_interfaces']['GigabitEthernet1']['macaddress'], '5e00.0006.0000' + ) + self.assertIsNone( + result['ansible_facts']['ansible_net_interfaces']['Tunnel1110']['macaddress'] + )