class test_show_interfaces_accounting(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "Loopback0": { "accounting": { "ip": { "chars_in": 671855, "pkts_out": 13651, "pkts_in": 13651, "chars_out": 671855 }, "ipv6": { "chars_in": 1596, "pkts_out": 25, "pkts_in": 21, "chars_out": 1900 } } }, "GigabitEthernet0/0": { "accounting": { "other": { "chars_in": 0, "pkts_out": 16094, "pkts_in": 0, "chars_out": 965640 }, "arp": { "chars_in": 10783020, "pkts_out": 45, "pkts_in": 179717, "chars_out": 2700 }, "dec mop": { "chars_in": 0, "pkts_out": 267, "pkts_in": 0, "chars_out": 20559 }, "ip": { "chars_in": 1388409, "pkts_out": 13176, "pkts_in": 13444, "chars_out": 1292961 }, "cdp": { "chars_in": 7438028, "pkts_out": 2984, "pkts_in": 34936, "chars_out": 1071256 } } } } golden_output = { 'execute.return_value': ''' show interfaces accounting GigabitEthernet0/0 Protocol Pkts In Chars In Pkts Out Chars Out Other 0 0 16094 965640 IP 13444 1388409 13176 1292961 DEC MOP 0 0 267 20559 ARP 179717 10783020 45 2700 CDP 34936 7438028 2984 1071256 Interface GigabitEthernet0/2 is disabled Loopback0 Protocol Pkts In Chars In Pkts Out Chars Out IP 13651 671855 13651 671855 IPv6 21 1596 25 1900 Tunnel0 Pim Register Tunnel (Encap) for RP 10.186.1.1 Protocol Pkts In Chars In Pkts Out Chars Out No traffic sent or received on this interface. ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowInterfacesAccounting(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.device = Mock(**self.golden_output) obj = ShowInterfacesAccounting(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output)
class test_show_ipv6_nd_interface(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_output = { 'execute.return_value': ''' n9kv-3# show ipv6 nd interface vrf all ICMPv6 ND Interfaces for VRF "default" Ethernet1/1, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:db8:c56d:4::3/64 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:7 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: 00:06:16 Last Neighbor-Advertisement sent: 00:02:12 Last Router-Advertisement sent: 1d18h Next Router-Advertisement sent in: 0.000000 Router-Advertisement parameters: Periodic interval: 200 to 201 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1801 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Enabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 1 Ethernet1/3, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:db8:c56d:1::3/64 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:7 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: 00:07:39 Last Neighbor-Advertisement sent: 02:39:27 Last Router-Advertisement sent: 00:01:33 Next Router-Advertisement sent in: 00:03:50 Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 1 loopback0, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:3:3::3/128 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:0 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: never Last Neighbor-Advertisement sent: never Last Router-Advertisement sent: never Next Router-Advertisement sent in: never Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 0 loopback1, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:33:33::33/128 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:0 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: never Last Neighbor-Advertisement sent: never Last Router-Advertisement sent: never Next Router-Advertisement sent in: never Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 0 ICMPv6 ND Interfaces for VRF "management" ICMPv6 ND Interfaces for VRF "vrf1" Ethernet1/2, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:db8:c8d1:4::3/64 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:7 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: 00:09:34 Last Neighbor-Advertisement sent: 00:01:07 Last Router-Advertisement sent: 00:05:42 Next Router-Advertisement sent in: 00:01:46 Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 1 Ethernet1/4, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:db8:c8d1:1::3/64 [VALID] IPv6 link-local address: fe80::5c01:c0ff:fe02:7 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: 00:03:31 Last Neighbor-Advertisement sent: 07:32:12 Last Router-Advertisement sent: 00:08:09 Next Router-Advertisement sent in: 00:01:36 Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 1 ''' } golden_parsed_output = { "vrf": { "vrf1": { "interfaces": { "Ethernet1/2": { "router_advertisement": { "default_router_preference": "medium", "interval": 600, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": False, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1800, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 1 }, "local_address": "fe80::5c01:c0ff:fe02:7", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:db8:c8d1:4::3/64", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "00:05:42", "last_neighbor_advertisement": "00:01:07", "last_neighbor_solicitation": "00:09:34", "next_router_advertisement": "00:01:46" }, "interface": "Ethernet1/2" }, "Ethernet1/4": { "router_advertisement": { "default_router_preference": "medium", "interval": 600, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": False, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1800, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 1 }, "local_address": "fe80::5c01:c0ff:fe02:7", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:db8:c8d1:1::3/64", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "00:08:09", "last_neighbor_advertisement": "07:32:12", "last_neighbor_solicitation": "00:03:31", "next_router_advertisement": "00:01:36" }, "interface": "Ethernet1/4" } } }, "default": { "interfaces": { "loopback1": { "router_advertisement": { "default_router_preference": "medium", "interval": 600, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": False, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1800, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 0 }, "local_address": "fe80::5c01:c0ff:fe02:0", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:33:33::33/128", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "never", "last_neighbor_advertisement": "never", "last_neighbor_solicitation": "never", "next_router_advertisement": "never" }, "interface": "loopback1" }, "Ethernet1/1": { "router_advertisement": { "default_router_preference": "medium", "interval": 201, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": True, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1801, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 1 }, "local_address": "fe80::5c01:c0ff:fe02:7", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:db8:c56d:4::3/64", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "1d18h", "last_neighbor_advertisement": "00:02:12", "last_neighbor_solicitation": "00:06:16", "next_router_advertisement": "0.000000" }, "interface": "Ethernet1/1" }, "Ethernet1/3": { "router_advertisement": { "default_router_preference": "medium", "interval": 600, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": False, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1800, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 1 }, "local_address": "fe80::5c01:c0ff:fe02:7", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:db8:c56d:1::3/64", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "00:01:33", "last_neighbor_advertisement": "02:39:27", "last_neighbor_solicitation": "00:07:39", "next_router_advertisement": "00:03:50" }, "interface": "Ethernet1/3" }, "loopback0": { "router_advertisement": { "default_router_preference": "medium", "interval": 600, "retrans_timer": 0, "suppress_mtu": False, "current_hop_limit": 64, "reachable_time": 0, "mtu": 1500, "suppress": False, "other_stateful_configuration": False, "suppress_route_information": False, "lifetime": 1800, "managed_address_configuration": False }, "oper_status": "up", "neighbor_solicitation": { "interval": 1000, "retry_interval": 1000, "retry_base": 1, "retry_attempts": 3 }, "dad": { "maximum_attempts": 1, "current_attempt": 0 }, "local_address": "fe80::5c01:c0ff:fe02:0", "error_message": { "unreachables": False, "redirects": True }, "enable": True, "link_status": "up", "ip": "2001:3:3::3/128", "mac_extract": "disabled", "active_timers": { "last_router_advertisement": "never", "last_neighbor_advertisement": "never", "last_neighbor_solicitation": "never", "next_router_advertisement": "never" }, "interface": "loopback0" } } } } } golden_parsed_output1 = { 'vrf': { 'VRF1': { 'interfaces': { 'Ethernet1/2.420': { 'interface': 'Ethernet1/2.420', 'oper_status': 'up', 'link_status': 'up', 'enable': True, 'ip': '2001:10:13:120::3/64', 'local_address': 'fe80::5c00:40ff:fe02:7', 'mac_extract': 'disabled', 'active_timers': { 'last_neighbor_solicitation': '00:04:07', 'last_neighbor_advertisement': '00:04:02', 'last_router_advertisement': '00:01:02', 'next_router_advertisement': '00:07:47', }, 'router_advertisement': { 'interval': 600, 'managed_address_configuration': False, 'other_stateful_configuration': False, 'default_router_preference': 'medium', 'current_hop_limit': 64, 'mtu': 1500, 'lifetime': 1800, 'reachable_time': 0, 'retrans_timer': 0, 'suppress': False, 'suppress_mtu': False, 'suppress_route_information': False, }, 'neighbor_solicitation': { 'interval': 1000, 'retry_base': 1, 'retry_interval': 1000, 'retry_attempts': 3, }, 'error_message': { 'redirects': True, 'unreachables': False, }, 'dad': { 'maximum_attempts': 1, 'current_attempt': 1, }, }, }, }, }, } golden_output1 = { 'execute.return_value': ''' R3_nx# show ipv6 nd interface Ethernet1/2.420 vrf VRF1 ICMPv6 ND Interfaces for VRF "VRF1" Ethernet1/2.420, Interface status: protocol-up/link-up/admin-up IPv6 address: 2001:10:13:120::3/64 [VALID] IPv6 link-local address: fe80::5c00:40ff:fe02:7 [VALID] ND mac-extract : Disabled ICMPv6 active timers: Last Neighbor-Solicitation sent: 00:04:07 Last Neighbor-Advertisement sent: 00:04:02 Last Router-Advertisement sent: 00:01:02 Next Router-Advertisement sent in: 00:07:47 Router-Advertisement parameters: Periodic interval: 200 to 600 seconds Send "Managed Address Configuration" flag: false Send "Other Stateful Configuration" flag: false Send "Default Router Preference" value: Medium Send "Current Hop Limit" field: 64 Send "MTU" option value: 1500 Send "Router Lifetime" field: 1800 secs Send "Reachable Time" field: 0 ms Send "Retrans Timer" field: 0 ms Suppress RA: Disabled Suppress MTU in RA: Disabled Suppress Route Information Option in RA: Disabled Neighbor-Solicitation parameters: NS retransmit interval: 1000 ms ND NUD retry base: 1 ND NUD retry interval: 1000 ND NUD retry attempts: 3 ICMPv6 error message parameters: Send redirects: true (0) Send unreachables: false ICMPv6 DAD parameters: Maximum DAD attempts: 1 Current DAD attempt : 1 ''' } def test_show_ipv6_nd_interface_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIpv6NdInterface(device=self.device) parsed_output = obj.parse(vrf="all") self.assertEqual(parsed_output, self.golden_parsed_output) def test_show_nve_empty(self): self.device = Mock(**self.empty_output) obj = ShowIpv6NdInterface(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden1(self): self.maxDiff = None self.device = Mock(**self.golden_output1) obj = ShowIpv6NdInterface(device=self.device) parsed_output = obj.parse(vrf="VRF1", interface='Ethernet1/2.420') self.assertEqual(parsed_output, self.golden_parsed_output1)
class test_show_ipv6_routers(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_output = { 'execute.return_value': ''' n9kv-3# show ipv6 routers vrf all Router fe80::f816:3eff:fe82:6320 on Ethernet1/1 , last update time 3.2 min Current_hop_limit 64, Lifetime 1800, AddrFlag 0, OtherFlag 0, MTU 1500 HomeAgentFlag 0, Preference Medium Reachable time 0 msec, Retransmission time 0 msec Prefix 2001:db8:c56d:4::/64 onlink_flag 1 autonomous_flag 1 valid lifetime 2592000, preferred lifetime 604800 Router fe80::f816:3eff:fe8b:59c9 on Ethernet1/2 , last update time 1.5 min Current_hop_limit 64, Lifetime 1800, AddrFlag 0, OtherFlag 0, MTU 1500 HomeAgentFlag 0, Preference Medium Reachable time 0 msec, Retransmission time 0 msec Prefix 2001:db8:c8d1:4::/64 onlink_flag 1 autonomous_flag 1 valid lifetime 2592000, preferred lifetime 604800 Prefix 2001:db8:888c:4::/64 onlink_flag 1 autonomous_flag 1 valid lifetime 2592000, preferred lifetime 604800 Router fe80::f816:3eff:fe19:8682 on Ethernet1/3 , last update time 2.8 min Current_hop_limit 64, Lifetime 1800, AddrFlag 0, OtherFlag 0, MTU 1500 HomeAgentFlag 0, Preference Medium Reachable time 0 msec, Retransmission time 0 msec Prefix 2001:db8:c56d:1::/64 onlink_flag 1 autonomous_flag 1 valid lifetime 2592000, preferred lifetime 604800 Router fe80::f816:3eff:fec7:8140 on Ethernet1/4 , last update time 2.3 min Current_hop_limit 64, Lifetime 1800, AddrFlag 0, OtherFlag 0, MTU 1500 HomeAgentFlag 0, Preference Medium Reachable time 0 msec, Retransmission time 0 msec Prefix 2001:db8:c8d1:1::/64 onlink_flag 1 autonomous_flag 1 valid lifetime 2592000, preferred lifetime 604800 ''' } golden_parsed_output = { "interfaces": { "Ethernet1/3": { "neighbors": { "fe80::f816:3eff:fe19:8682": { "homeagent_flag": 0, "is_router": True, "addr_flag": 0, "ip": "fe80::f816:3eff:fe19:8682", "lifetime": 1800, "current_hop_limit": 64, "retransmission_time": 0, "last_update": "2.8", "mtu": 1500, "preference": "medium", "other_flag": 0, "reachable_time": 0, "prefix": { "2001:db8:c56d:1::/64": { "preferred_lifetime": 604800, "valid_lifetime": 2592000, "autonomous_flag": 1, "onlink_flag": 1, } } } }, "interface": "Ethernet1/3" }, "Ethernet1/1": { "neighbors": { "fe80::f816:3eff:fe82:6320": { "homeagent_flag": 0, "is_router": True, "addr_flag": 0, "ip": "fe80::f816:3eff:fe82:6320", "lifetime": 1800, "current_hop_limit": 64, "retransmission_time": 0, "last_update": "3.2", "mtu": 1500, "preference": "medium", "other_flag": 0, "reachable_time": 0, "prefix": { "2001:db8:c56d:4::/64": { "preferred_lifetime": 604800, "valid_lifetime": 2592000, "autonomous_flag": 1, "onlink_flag": 1, } } } }, "interface": "Ethernet1/1" }, "Ethernet1/4": { "neighbors": { "fe80::f816:3eff:fec7:8140": { "homeagent_flag": 0, "is_router": True, "addr_flag": 0, "ip": "fe80::f816:3eff:fec7:8140", "lifetime": 1800, "current_hop_limit": 64, "retransmission_time": 0, "last_update": "2.3", "mtu": 1500, "preference": "medium", "other_flag": 0, "reachable_time": 0, "prefix": { "2001:db8:c8d1:1::/64": { "preferred_lifetime": 604800, "autonomous_flag": 1, "valid_lifetime": 2592000, "onlink_flag": 1, } } } }, "interface": "Ethernet1/4" }, "Ethernet1/2": { "neighbors": { "fe80::f816:3eff:fe8b:59c9": { "homeagent_flag": 0, "is_router": True, "addr_flag": 0, "ip": "fe80::f816:3eff:fe8b:59c9", "lifetime": 1800, "current_hop_limit": 64, "retransmission_time": 0, "last_update": "1.5", "mtu": 1500, "preference": "medium", "other_flag": 0, "reachable_time": 0, "prefix": { "2001:db8:c8d1:4::/64": { "preferred_lifetime": 604800, "onlink_flag": 1, "valid_lifetime": 2592000, "autonomous_flag": 1, }, "2001:db8:888c:4::/64": { "preferred_lifetime": 604800, "onlink_flag": 1, "valid_lifetime": 2592000, "autonomous_flag": 1, } } } }, "interface": "Ethernet1/2" } } } def test_show_ipv6_icmp_neighbor_detail_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIpv6Routers(device=self.device) parsed_output = obj.parse(vrf="all") self.assertEqual(parsed_output, self.golden_parsed_output) def test_show_nve_empty(self): self.device = Mock(**self.empty_output) obj = ShowIpv6Routers(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse()
class test_show_ntp_associations(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'clock_state': { 'system_status': { 'associations_address': '10.16.2.2', 'associations_local_mode': 'client', 'clock_offset': 27.027, 'clock_refid': '127.127.1.1', 'clock_state': 'synchronized', 'clock_stratum': 3, 'root_delay': 5.61 } }, 'peer': { '10.16.2.2': { 'local_mode': { 'client': { 'delay': 5.61, 'jitter': 3.342, 'mode': 'synchronized', 'offset': 27.027, 'poll': 64, 'reach': 7, 'receive_time': 25, 'refid': '127.127.1.1', 'remote': '10.16.2.2', 'stratum': 3, 'configured': True, 'local_mode': 'client' } } }, '10.36.3.3': { 'local_mode': { 'client': { 'delay': 0.0, 'jitter': 15937.0, 'mode': 'unsynchronized', 'offset': 0.0, 'poll': 512, 'reach': 0, 'receive_time': '-', 'refid': '.STEP.', 'remote': '10.36.3.3', 'stratum': 16, 'configured': True, 'local_mode': 'client' } } } } } golden_output_1 = { 'execute.return_value': ''' iosv-1#show ntp associations address ref clock st when poll reach delay offset disp *~10.16.2.2 127.127.1.1 3 25 64 7 5.610 27.027 3.342 ~10.36.3.3 .STEP. 16 - 512 0 0.000 0.000 15937. * sys.peer, # selected, + candidate, - outlyer, x falseticker, ~ configured ''' } golden_parsed_output_2 = { 'clock_state': { 'system_status': { 'associations_address': '10.16.2.2', 'associations_local_mode': 'client', 'clock_offset': 27.027, 'clock_refid': '127.127.1.1', 'clock_state': 'synchronized', 'clock_stratum': 3, 'root_delay': 5.61 } }, 'peer': { '10.16.2.2': { 'local_mode': { 'client': { 'delay': 5.61, 'jitter': 3.342, 'local_mode': 'client', 'mode': 'synchronized', 'offset': 27.027, 'poll': 64, 'reach': 7, 'receive_time': 25, 'refid': '127.127.1.1', 'remote': '10.16.2.2', 'configured': True, 'stratum': 3 } } }, '10.36.3.3': { 'local_mode': { 'client': { 'delay': 0.0, 'jitter': 15937.0, 'local_mode': 'client', 'mode': 'unsynchronized', 'offset': 0.0, 'poll': 512, 'reach': 0, 'receive_time': '-', 'refid': '.STEP.', 'remote': '10.36.3.3', 'configured': True, 'stratum': 16 } } } } } golden_output_2 = { 'execute.return_value': ''' show ntp associations address ref clock st when poll reach delay offset disp ~10.16.2.2 127.127.1.1 3 41 64 0 0.000 0.000 15937. ~10.36.3.3 .INIT. 16 - 64 0 0.000 0.000 15937. * sys.peer, # selected, + candidate, - outlyer, x falseticker, ~ configured ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpAssociations(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_1(self): self.maxDiff = None self.device = Mock(**self.golden_output_1) obj = ShowNtpAssociations(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1) def test_golden_2(self): self.maxDiff = None self.device = Mock(**self.golden_output_1) obj = ShowNtpAssociations(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_2)
class test_show_ntp_associations_detail(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_output = { 'execute.return_value': ''' Device> show ntp associations detail 172.31.32.2 configured, insane, invalid, stratum 5 ref ID 172.31.32.1, time AFE252C1.6DBDDFF2 (00:12:01.428 PDT Mon Jul 5 1993) our mode active, peer mode active, our poll intvl 1024, peer poll intvl 64 root delay 137.77 msec, root disp 142.75, reach 376, sync dist 215.363 delay 4.23 msec, offset -8.587 msec, dispersion 1.62 precision 2**19, version 4 assoc ID 1, assoc name 192.168.1.55, assoc in packets 60, assoc out packets 60, assoc error packets 0 org time AFE252E2.3AC0E887 (00:12:34.229 PDT Tue Oct 4 2011) rcv time AFE252E2.3D7E464D (00:12:34.240 PDT Mon Jan 1 1900) xmt time AFE25301.6F83E753 (00:13:05.435 PDT Tue Oct 4 2011) filtdelay = 4.23 4.14 2.41 5.95 2.37 2.33 4.26 4.33 filtoffset = -8.59 -8.82 -9.91 -8.42 -10.51 -10.77 -10.13 -10.11 filterror = 0.50 1.48 2.46 3.43 4.41 5.39 6.36 7.34 192.168.13.33 configured, selected, sane, valid, stratum 3 ref ID 192.168.1.111, time AFE24F0E.14283000 (23:56:14.078 PDT Sun Jul 4 1993) our mode client, peer mode server, our poll intvl 128, peer poll intvl 128 root delay 83.72 msec, root disp 217.77, reach 377, sync dist 264.633 delay 4.07 msec, offset 3.483 msec, dispersion 2.33 precision 2**6, version 3 assoc ID 2, assoc name myserver assoc in packets 0, assoc out packets 0, assoc error packets 0 org time AFE252B9.713E9000 (00:11:53.442 PDT Tue Oct 4 2011) rcv time AFE252B9.7124E14A (00:11:53.441 PDT Mon Jan 1 1900) xmt time AFE252B9.6F625195 (00:11:53.435 PDT Mon Jan 1 1900) filtdelay = 6.47 4.07 3.94 3.86 7.31 7.20 9.52 8.71 filtoffset = 3.63 3.48 3.06 2.82 4.51 4.57 4.28 4.59 filterror = 0.00 1.95 3.91 4.88 5.84 6.82 7.80 8.77 192.168.13.57 configured, our_master, sane, valid, stratum 3 ref ID 192.168.1.111, time AFE252DC.1F2B3000 (00:12:28.121 PDT Mon Jul 5 1993) our mode client, peer mode server, our poll intvl 128, peer poll intvl 128 root delay 125.50 msec, root disp 115.80, reach 377, sync dist 186.157 delay 7.86 msec, offset 11.176 msec, dispersion 3.62 precision 2**6, version 2 assoc ID 2, assoc name myserver assoc in packets 0, assoc out packets 0, assoc error packets 0 org time AFE252DE.77C29000 (00:12:30.467 PDT Tue Oct 4 2011) rcv time AFE252DE.7B2AE40B (00:12:30.481 PDT Mon Jan 1 1900) xmt time AFE252DE.6E6D12E4 (00:12:30.431 PDT Mon Jan 1 1900) filtdelay = 49.21 7.86 8.18 8.80 4.30 4.24 7.58 6.42 filtoffset = 11.30 11.18 11.13 11.28 8.91 9.09 9.27 9.57 filterror = 0.00 1.95 3.91 4.88 5.78 6.76 7.74 8.71 ''' } golden_parsed_output = { "vrf": { "default": { "associations": { "address": { "172.31.32.2": { "local_mode": { "active": { "isconfigured": { "True": { "selected": False, "unsynced": False, "address": "172.31.32.2", "isconfigured": True, "authenticated": False, "sane": False, "valid": False, "master": False, "stratum": 5, "refid": "172.31.32.1", "input_time": "AFE252C1.6DBDDFF2 (00:12:01.428 PDT Mon Jul 5 1993)", "peer_interface": "172.31.32.1", "poll": "1024", "vrf": "default", "local_mode": "active", "peer": { "172.31.32.1": { "local_mode": { "active": { "poll": 64, "local_mode": "active" } } } }, "root_delay_msec": "137.77", "root_disp": "142.75", "reach": "376", "sync_dist": "215.363", "delay_msec": "4.23", "offset_msec": "-8.587", "dispersion": "1.62", "jitter_msec": "None", "precision": "2**19", "version": 4, "assoc_name": "192.168.1.55", "assoc_id": 1, "ntp_statistics": { "packet_received": 60, "packet_sent": 60, "packet_dropped": 0 }, "originate_time": "AFE252E2.3AC0E887 (00:12:34.229 PDT Tue Oct 4 2011)", "receive_time": "AFE252E2.3D7E464D (00:12:34.240 PDT Mon Jan 1 1900)", "transmit_time": "AFE25301.6F83E753 (00:13:05.435 PDT Tue Oct 4 2011)", "filtdelay": "4.23 4.14 2.41 5.95 2.37 2.33 4.26 4.33", "filtoffset": "-8.59 -8.82 -9.91 -8.42 -10.51 -10.77 -10.13 -10.11", "filterror": "0.50 1.48 2.46 3.43 4.41 5.39 6.36 7.34" } } } } }, "192.168.13.33": { "local_mode": { "client": { "isconfigured": { "True": { "selected": True, "unsynced": False, "address": "192.168.13.33", "isconfigured": True, "authenticated": False, "sane": True, "valid": True, "master": False, "stratum": 3, "refid": "192.168.1.111", "input_time": "AFE24F0E.14283000 (23:56:14.078 PDT Sun Jul 4 1993)", "peer_interface": "192.168.1.111", "poll": "128", "vrf": "default", "local_mode": "client", "peer": { "192.168.1.111": { "local_mode": { "server": { "poll": 128, "local_mode": "server" } } } }, "root_delay_msec": "83.72", "root_disp": "217.77", "reach": "377", "sync_dist": "264.633", "delay_msec": "4.07", "offset_msec": "3.483", "dispersion": "2.33", "jitter_msec": "None", "precision": "2**6", "version": 3, "assoc_name": "myserver", "assoc_id": 2, "ntp_statistics": { "packet_received": 0, "packet_sent": 0, "packet_dropped": 0 }, "originate_time": "AFE252B9.713E9000 (00:11:53.442 PDT Tue Oct 4 2011)", "receive_time": "AFE252B9.7124E14A (00:11:53.441 PDT Mon Jan 1 1900)", "transmit_time": "AFE252B9.6F625195 (00:11:53.435 PDT Mon Jan 1 1900)", "filtdelay": "6.47 4.07 3.94 3.86 7.31 7.20 9.52 8.71", "filtoffset": "3.63 3.48 3.06 2.82 4.51 4.57 4.28 4.59", "filterror": "0.00 1.95 3.91 4.88 5.84 6.82 7.80 8.77" } } } } }, "192.168.13.57": { "local_mode": { "client": { "isconfigured": { "True": { "selected": False, "unsynced": False, "address": "192.168.13.57", "isconfigured": True, "authenticated": False, "sane": True, "valid": True, "master": True, "stratum": 3, "refid": "192.168.1.111", "input_time": "AFE252DC.1F2B3000 (00:12:28.121 PDT Mon Jul 5 1993)", "peer_interface": "192.168.1.111", "poll": "128", "vrf": "default", "local_mode": "client", "peer": { "192.168.1.111": { "local_mode": { "server": { "poll": 128, "local_mode": "server" } } } }, "root_delay_msec": "125.50", "root_disp": "115.80", "reach": "377", "sync_dist": "186.157", "delay_msec": "7.86", "offset_msec": "11.176", "dispersion": "3.62", "jitter_msec": "None", "precision": "2**6", "version": 2, "assoc_name": "myserver", "assoc_id": 2, "ntp_statistics": { "packet_received": 0, "packet_sent": 0, "packet_dropped": 0 }, "originate_time": "AFE252DE.77C29000 (00:12:30.467 PDT Tue Oct 4 2011)", "receive_time": "AFE252DE.7B2AE40B (00:12:30.481 PDT Mon Jan 1 1900)", "transmit_time": "AFE252DE.6E6D12E4 (00:12:30.431 PDT Mon Jan 1 1900)", "filtdelay": "49.21 7.86 8.18 8.80 4.30 4.24 7.58 6.42", "filtoffset": "11.30 11.18 11.13 11.28 8.91 9.09 9.27 9.57", "filterror": "0.00 1.95 3.91 4.88 5.78 6.76 7.74 8.71" } } } } } } } } } } def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowNtpAssociationsDetail(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output) def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpAssociationsDetail(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse()
def setUp(self): self.device = Device(name='aDevice') self.device.os = 'iosxe' self.device.mapping = {} self.device.mapping['cli'] = 'cli' self.device.connectionmgr.connections['cli'] = self.device
class test_show_hsrp_all(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'Ethernet4/1': { 'address_family': { 'ipv4': { 'version': { 2: { 'groups': { 0: { 'active_router': 'unknown', 'authentication': 'cisco123', 'configured_priority': 110, 'group_number': 0, 'hsrp_router_state': 'initial', 'hsrp_router_state_reason': 'interface down', 'last_state_change': 'never', 'lower_fwd_threshold': 1, 'num_state_changes': 0, 'preempt': True, 'primary_ipv4_address': { 'address': '192.168.1.254', 'virtual_ip_learn': False }, 'priority': 110, 'session_name': 'hsrp-Eth4/1-0', 'standby_router': 'unknown', 'timers': { 'hello_msec_flag': False, 'hello_sec': 1, 'hold_msec_flag': False, 'hold_sec': 3 }, 'upper_fwd_threshold': 110, 'virtual_mac_address': '0000.0c9f.f000', 'virtual_mac_address_status': 'default' }, }, }, }, }, }, 'interface': 'Ethernet4/1', 'use_bia': False }, } golden_output_1 = { 'execute.return_value': ''' Ethernet4/1 - Group 0 (HSRP-V2) (IPv4) Local state is Initial(Interface Down), priority 110 (Cfged 110), may preempt Forwarding threshold(for vPC), lower: 1 upper: 110 Hellotime 1 sec, holdtime 3 sec Virtual IP address is 192.168.1.254 (Cfged) Active router is unknown Standby router is unknown Authentication MD5, key-string "cisco123" Virtual mac address is 0000.0c9f.f000 (Default MAC) 0 state changes, last state change never IP redundancy name is hsrp-Eth4/1-0 (default) ''' } golden_parsed_output_2 = { 'Ethernet1/3': { 'address_family': { 'ipv4': { 'version': { 2: { 'groups': { 0: { 'active_priority': 110, 'active_router': 'local', 'authentication': 'cisco123', 'configured_priority': 110, 'group_number': 0, 'hsrp_router_state': 'active', 'last_state_change': '00:01:43', 'lower_fwd_threshold': 0, 'num_state_changes': 10, 'preempt': True, 'primary_ipv4_address': { 'address': '192.168.1.254', 'virtual_ip_learn': False }, 'priority': 110, 'session_name': 'hsrp-Eth1/3-0', 'standby_expire': 2.429, 'standby_ip_address': '192.168.1.2', 'standby_priority': 90, 'standby_router': '192.168.1.2', 'timers': { 'hello_msec_flag': False, 'hello_sec': 1, 'hold_msec_flag': False, 'hold_sec': 3 }, 'tracked_objects': { 1: { 'object_name': 1, 'priority_decrement': 22, 'status': 'UP' }, }, 'upper_fwd_threshold': 110, 'virtual_mac_address': '0000.0c9f.f000', 'virtual_mac_address_status': 'default' }, 2: { 'active_router': 'unknown', 'authentication': 'cisco', 'configured_priority': 1, 'group_number': 2, 'hsrp_router_state': 'disabled', 'hsrp_router_state_reason': 'virtual ip not cfged', 'last_state_change': 'never', 'lower_fwd_threshold': 0, 'num_state_changes': 0, 'priority': 1, 'session_name': 'hsrp-Eth1/3-2', 'standby_router': 'unknown', 'timers': { 'hello_msec_flag': False, 'hello_sec': 3, 'hold_msec_flag': False, 'hold_sec': 10 }, 'upper_fwd_threshold': 1, 'virtual_mac_address': '0000.0c9f.f002', 'virtual_mac_address_status': 'default' }, }, }, }, }, 'ipv6': { 'version': { 2: { 'groups': { 2: { 'active_priority': 100, 'active_router': 'local', 'authentication': 'cisco', 'configured_priority': 100, 'global_ipv6_addresses': { '192:168::1': { 'address': '192:168::1' } }, 'group_number': 2, 'hsrp_router_state': 'active', 'last_state_change': '02:43:40', 'link_local_ipv6_address': { 'address': 'fe80::5:73ff:fea0:2', 'auto_configure': True }, 'lower_fwd_threshold': 0, 'num_state_changes': 2, 'priority': 100, 'secondary_vips': ['192:168::1'], 'session_name': 'hsrp-Eth1/3-2-V6', 'standby_expire': 8.96, 'standby_ipv6_address': 'fe80::20c:29ff:fe69:14bb', 'standby_priority': 90, 'standby_router': 'fe80::20c:29ff:fe69:14bb', 'timers': { 'hello_msec_flag': False, 'hello_sec': 3, 'hold_msec_flag': False, 'hold_sec': 10 }, 'upper_fwd_threshold': 100, 'virtual_mac_address': '0005.73a0.0002', 'virtual_mac_address_status': 'default' }, }, }, }, }, }, 'interface': 'Ethernet1/3', 'use_bia': False }, } golden_output_2 = { 'execute.return_value': ''' Ethernet1/3 - Group 0 (HSRP-V2) (IPv4) Local state is Active, priority 110 (Cfged 110), may preempt Forwarding threshold(for vPC), lower: 0 upper: 110 Hellotime 1 sec, holdtime 3 sec Next hello sent in 0.502000 sec(s) Virtual IP address is 192.168.1.254 (Cfged) Active router is local Standby router is 192.168.1.2 , priority 90 expires in 2.429000 sec(s) Authentication MD5, key-string "cisco123" Virtual mac address is 0000.0c9f.f000 (Default MAC) 10 state changes, last state change 00:01:43 Track object 1 state UP decrement 22 IP redundancy name is hsrp-Eth1/3-0 (default) Ethernet1/3 - Group 2 (HSRP-V2) (IPv4) Local state is Disabled(Virtual IP not cfged), priority 1 (Cfged 1) Forwarding threshold(for vPC), lower: 0 upper: 1 Hellotime 3 sec, holdtime 10 sec Virtual IP address is unknown Active router is unknown Standby router is unknown Authentication text "cisco" Virtual mac address is 0000.0c9f.f002 (Default MAC) 0 state changes, last state change never IP redundancy name is hsrp-Eth1/3-2 (default) Ethernet1/3 - Group 2 (HSRP-V2) (IPv6) Local state is Active, priority 100 (Cfged 100) Forwarding threshold(for vPC), lower: 0 upper: 100 Hellotime 3 sec, holdtime 10 sec Next hello sent in 0.455000 sec(s) Virtual IP address is fe80::5:73ff:fea0:2 (Auto) Active router is local Standby router is fe80::20c:29ff:fe69:14bb , priority 90 expires in 8.960000 sec(s) Authentication text "cisco" Virtual mac address is 0005.73a0.0002 (Default MAC) 2 state changes, last state change 02:43:40 IP redundancy name is hsrp-Eth1/3-2-V6 (default) Secondary VIP(s): 192:168::1 ''' } golden_parsed_output_3 = { 'Ethernet1/3': { 'address_family': { 'ipv4': { 'version': { 1: { 'groups': { 1: { 'active_router': 'local', 'active_priority': 100, 'authentication': 'cisco', 'configured_priority': 100, 'group_number': 1, 'last_state_change': '00:05:57', 'hsrp_router_state': 'active', 'lower_fwd_threshold': 0, 'num_state_changes': 2, 'primary_ipv4_address': { 'address': '192.168.255.1', 'virtual_ip_learn': False }, 'priority': 100, 'session_name': 'hsrp-Eth1/3-1', 'standby_router': 'unknown', 'timers': { 'hello_msec_flag': False, 'hello_sec': 3, 'hold_msec_flag': False, 'hold_sec': 10 }, 'upper_fwd_threshold': 100, 'virtual_mac_address': '0000.0c07.ac01', 'virtual_mac_address_status': 'default' } } } } } }, 'interface': 'Ethernet1/3', 'use_bia': False } } golden_output_3 = { 'execute.return_value': ''' nx1# show hsrp all Ethernet1/3 - Group 1 (HSRP-V1) (IPv4) Local state is Active, priority 100 (Cfged 100) Forwarding threshold(for vPC), lower: 0 upper: 100 Hellotime 3 sec, holdtime 10 sec Next hello sent in 0.400000 sec(s) Virtual IP address is 192.168.255.1 (Cfged) Active router is local Standby router is unknown Authentication text "cisco" Virtual mac address is 0000.0c07.ac01 (Default MAC) 2 state changes, last state change 00:05:57 IP redundancy name is hsrp-Eth1/3-1 (default) ''' } def test_golden_1(self): self.maxDiff = None self.device = Mock(**self.golden_output_1) hsrp_all_obj = ShowHsrpAll(device=self.device) parsed_output = hsrp_all_obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1) def test_golden_2(self): self.maxDiff = None self.device = Mock(**self.golden_output_2) hsrp_all_obj = ShowHsrpAll(device=self.device) parsed_output = hsrp_all_obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_2) def test_golden_3(self): self.maxDiff = None self.device = Mock(**self.golden_output_3) hsrp_all_obj = ShowHsrpAll(device=self.device) parsed_output = hsrp_all_obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_3) def test_empty(self): self.device = Mock(**self.empty_output) hsrp_all_obj = ShowHsrpAll(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = hsrp_all_obj.parse()
class test_show_ip_multicast(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "vrf": { "default": { "enable": True, "route_limit": "no limit", "multipath": True, "mo_frr": False, "fallback_group_mode": "sparse", "multicast_bound_with_filter_autorp": 0 }}} golden_output = {'execute.return_value': '''\ Multicast Routing: enabled Multicast Multipath: enabled Multicast Route limit: No limit Multicast Fallback group mode: Sparse Number of multicast boundaries configured with filter-autorp option: 0 MoFRR: Disabled '''} golden_parsed_output2 = { "vrf": { "VRF1": { "enable": True, "route_limit": "no limit", "multipath": False, "mo_frr": False, "fallback_group_mode": "sparse", "multicast_bound_with_filter_autorp": 0 }}} golden_output2 = {'execute.return_value': '''\ Multicast Routing: enabled Multicast Multipath: disabled Multicast Route limit: No limit Multicast Fallback group mode: Sparse Number of multicast boundaries configured with filter-autorp option: 0 MoFRR: Disabled '''} def test_empty(self): self.device1 = Mock(**self.empty_output) obj = ShowIpMulticast(device=self.device1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_vrf_default(self): self.device = Mock(**self.golden_output) obj = ShowIpMulticast(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output,self.golden_parsed_output) def test_golden_vrf_non_default(self): self.device = Mock(**self.golden_output2) obj = ShowIpMulticast(device=self.device) parsed_output = obj.parse(vrf='VRF1') self.assertEqual(parsed_output,self.golden_parsed_output2)
class test_show_protocols_afi_all_all(unittest.TestCase): '''Unit test for "show protocols afi-all all" ''' device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output1 = { 'protocols': { 'bgp': { 'address_family': { 'vpnv4 unicast': { 'distance': { 'external': 20, 'internal': 200, 'local': 200 }, 'neighbors': { '4.4.4.4': { 'gr_enable': 'No', 'last_update': '00:01:28', 'nsr_state': 'None' } } }, 'vpnv6 unicast': { 'distance': { 'external': 20, 'internal': 200, 'local': 200 }, 'neighbors': { '4.4.4.4': { 'gr_enable': 'No', 'last_update': '00:01:28', 'nsr_state': 'None' } } } }, 'bgp_pid': 100, 'graceful_restart': { 'enable': False }, 'nsr': { 'current_state': 'active ready', 'enable': True } }, 'ospf': { 'vrf': { 'default': { 'address_family': { 'ipv4': { 'instance': { '1': { 'areas': { '0.0.0.0': { 'interfaces': [ 'Loopback0', 'GigabitEthernet0/0/0/0', 'GigabitEthernet0/0/0/2' ], 'mpls': { 'te': { 'enable': True } } } }, 'nsf': False, 'preference': { 'multi_values': { 'external': 114, 'granularity': { 'detail': { 'inter_area': 113, 'intra_area': 112 } } }, 'single_value': { 'all': 110 } }, 'redistribution': { 'bgp': { 'bgp_id': 100, 'metric': 111 }, 'connected': { 'enabled': True }, 'isis': { 'isis_pid': '10', 'metric': 3333 }, 'static': { 'enabled': True, 'metric': 10 } }, 'router_id': '3.3.3.3' } } } } } } } } } golden_output1 = { 'execute.return_value': ''' RP/0/0/CPU0:R3_ospf_xr#show protocols afi-all all Mon Jan 8 17:45:17.553 UTC Routing Protocol "BGP 100" Non-stop routing is enabled Graceful restart is not enabled Current BGP NSR state - Active Ready BGP NSR state not ready: Wait for standby ready msg Address Family VPNv4 Unicast: Distance: external 20 internal 200 local 200 Routing Information Sources: Neighbor State/Last update received NSR-State GR-Enabled 4.4.4.4 00:01:28 None No Address Family VPNv6 Unicast: Distance: external 20 internal 200 local 200 Routing Information Sources: Neighbor State/Last update received NSR-State GR-Enabled 4.4.4.4 00:01:28 None No Routing Protocol OSPF 1 Router Id: 3.3.3.3 Distance: 110 Distance: IntraArea 112 InterArea 113 External/NSSA 114 Non-Stop Forwarding: Disabled Redistribution: connected static with metric 10 bgp 100 with metric 111 isis 10 with metric 3333 Area 0 MPLS/TE enabled Loopback0 GigabitEthernet0/0/0/0 GigabitEthernet0/0/0/2 ''' } golden_parsed_output2 = { "protocols": { "ospf": { "vrf": { "default": { "address_family": { "ipv4": { "instance": { "1": { "preference": { "single_value": { "all": 110 } }, "router_id": "200.5.0.1", "nsf": True, "areas": { "0.0.0.1": { "mpls": { "te": { "enable": True } }, "interfaces": ["Loopback5"] }, "0.0.0.0": { "interfaces": ["Loopback0"] } } } } } } } } }, "ospfv3": { "vrf": { "default": { "address_family": { "ipv4": { "instance": { "1": { "preference": { "single_value": { "all": 110 } }, "router_id": "0.0.0.0" } } } } } } }, "bgp": { "bgp_pid": 100, "nsr": { "enable": True, "current_state": "tcp initial sync" }, "address_family": { "vpnv6 unicast": { "distance": { "internal": 200, "local": 200, "external": 20 } }, "vpnv4 unicast": { "distance": { "internal": 200, "local": 200, "external": 20 } } } } } } golden_output2 = { 'execute.return_value': ''' Routing Protocol "BGP 100" Non-stop routing is enabled Graceful restart is enabled Current BGP NSR state - TCP Initial Sync BGP NSR state not ready: TCP Initsync in progress Address Family VPNv4 Unicast: Distance: external 20 internal 200 local 200 Address Family VPNv6 Unicast: Distance: external 20 internal 200 local 200 IS-IS Router: 1 System Id: 1c53.0001.0001 Instance Id: 0 IS Levels: level-2-only Manual area address(es): 49.0001 Routing for area address(es): 49.0001 Non-stop forwarding: Disabled Most recent startup mode: Cold Restart TE connection status: Up Topologies supported by IS-IS: IPv4 Unicast Level-2 Metric style (generate/accept): Narrow/Narrow Metric: 10 ISPF status: Disabled No protocols redistributed Distance: 115 Advertise Passive Interface Prefixes Only: No IPv6 Unicast Level-2 Metric: 10 ISPF status: Disabled No protocols redistributed Distance: 115 Advertise Passive Interface Prefixes Only: No SRLB allocated: 0 - 0 SRGB not allocated Interfaces supported by IS-IS: GigabitEthernet0/0/0/0.104 is disabled (active in configuration) GigabitEthernet0/0/0/1.104 is disabled (active in configuration) Routing Protocol OSPF 1 Router Id: 200.5.0.1 Distance: 110 Non-Stop Forwarding: Enabled Redistribution: None Area 0 Loopback0 Area 1 MPLS/TE enabled Loopback5 Routing Protocol OSPFv3 1 Router Id: 0.0.0.0 Distance: 110 Graceful Restart: Disabled Redistribution: None ''' } def test_show_protocols_afi_all_all_full1(self): self.maxDiff = None self.device = Mock(**self.golden_output1) obj = ShowProtocolsAfiAllAll(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output1) def test_show_protocols_afi_all_all_full2(self): self.maxDiff = None self.device = Mock(**self.golden_output2) obj = ShowProtocolsAfiAllAll(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output2) def test_show_protocols_afi_all_all_empty(self): self.maxDiff = None self.device = Mock(**self.empty_output) obj = ShowProtocolsAfiAllAll(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse()
class test_show_ipv6_mroute(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "vrf": { "default": { "address_family": { "ipv6": { "multicast_group": { "FF07::1": { "source_address": { "2001:DB8:999::99": { "outgoing_interface_list": { "POS4/0": { "state_mode": "forward", "uptime": "00:02:06", "expire": "00:03:27" } }, "incoming_interface_list": { "POS1/0": { "rpf_nbr": "2001:DB8:999::99" } }, "uptime": "00:02:06", "flags": "SFT", 'rp_bit': False, 'msdp_learned': False, "rpf_nbr": "2001:DB8:999::99", "expire": "00:01:23" }, "*": { "outgoing_interface_list": { "POS4/0": { "state_mode": "forward", "uptime": "00:04:45", "expire": "00:02:47" } }, "incoming_interface_list": { "Tunnel5": { "rpf_nbr": "6:6:6::6" } }, "uptime": "00:04:45", "rp": "2001:DB8:6::6", "flags": "S", 'msdp_learned': False, 'rp_bit': False, "rpf_nbr": "6:6:6::6", "expire": "00:02:47" }}}}}}}}} golden_output = {'execute.return_value': '''\ Multicast Routing Table Flags:D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected, L - Local, I - Received Source Specific Host Report, P - Pruned, R - RP-bit set, F - Register flag, T - SPT-bit set, J - Join SPT Timers:Uptime/Expires Interface state:Interface, State (*, FF07::1), 00:04:45/00:02:47, RP 2001:DB8:6::6, flags:S Incoming interface:Tunnel5 RPF nbr:6:6:6::6 Outgoing interface list: POS4/0, Forward, 00:04:45/00:02:47 (2001:DB8:999::99, FF07::1), 00:02:06/00:01:23, flags:SFT Incoming interface:POS1/0 RPF nbr:2001:DB8:999::99 Outgoing interface list: POS4/0, Forward, 00:02:06/00:03:27 '''} golden_parsed_output2 = { "vrf": { "VRF1": { "address_family": { "ipv6": { "multicast_group": { "FF07::1": { "source_address": { "2001:DB8:999::99": { "outgoing_interface_list": { "POS4/0": { "state_mode": "forward", "uptime": "00:02:06", "expire": "00:03:27" } }, "incoming_interface_list": { "POS1/0": { "rpf_nbr": "2001:DB8:999::99" } }, "uptime": "00:02:06", "flags": "SFT", 'msdp_learned': False, 'rp_bit': False, "rpf_nbr": "2001:DB8:999::99", "expire": "00:01:23" }, "*": { "outgoing_interface_list": { "POS4/0": { "state_mode": "forward", "uptime": "00:04:45", "expire": "00:02:47" } }, "incoming_interface_list": { "Tunnel5": { "rpf_nbr": "6:6:6::6" } }, "uptime": "00:04:45", "rp": "2001:DB8:6::6", "flags": "S", 'msdp_learned': False, 'rp_bit': False, "rpf_nbr": "6:6:6::6", "expire": "00:02:47" }}}}}}}}} golden_output2 = {'execute.return_value': '''\ Multicast Routing Table Flags:D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected, L - Local, I - Received Source Specific Host Report, P - Pruned, R - RP-bit set, F - Register flag, T - SPT-bit set, J - Join SPT Timers:Uptime/Expires Interface state:Interface, State (*, FF07::1), 00:04:45/00:02:47, RP 2001:DB8:6::6, flags:S Incoming interface:Tunnel5 RPF nbr:6:6:6::6 Outgoing interface list: POS4/0, Forward, 00:04:45/00:02:47 (2001:DB8:999::99, FF07::1), 00:02:06/00:01:23, flags:SFT Incoming interface:POS1/0 RPF nbr:2001:DB8:999::99 Outgoing interface list: POS4/0, Forward, 00:02:06/00:03:27 '''} def test_empty(self): self.device1 = Mock(**self.empty_output) obj = ShowIpv6Mroute(device=self.device1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_vrf_default(self): self.device = Mock(**self.golden_output) obj = ShowIpv6Mroute(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output,self.golden_parsed_output) def test_golden_vrf_non_default(self): self.device = Mock(**self.golden_output2) obj = ShowIpv6Mroute(device=self.device) parsed_output = obj.parse(vrf='VRF1') self.assertEqual(parsed_output,self.golden_parsed_output2)
class test_show_ip_mroute_static(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "vrf": { "default": { "mroute": { "172.16.0.0/16": { "path": { "172.30.10.13 1": { "neighbor_address": "172.30.10.13", "admin_distance": "1" } } }, "172.16.1.0/24": { "path": { "172.30.10.13 1": { "neighbor_address": "172.30.10.13", "admin_distance": "1" }}}}}}} golden_output = {'execute.return_value': '''\ Mroute: 172.16.0.0/16, RPF neighbor: 172.30.10.13, distance: 1 Mroute: 172.16.1.0/24, RPF neighbor: 172.30.10.13, distance: 1 '''} golden_parsed_output2 = { "vrf": { "VRF1": { "mroute": { "77.77.77.77/32": { "path": { "10.12.12.13 1": { "neighbor_address": "10.12.12.13", "admin_distance": "1" }}}}}}} golden_output2 = {'execute.return_value': '''\ Mroute: 77.77.77.77/32, RPF neighbor: 10.12.12.13, distance: 1 '''} def test_empty(self): self.device1 = Mock(**self.empty_output) obj = ShowIpMrouteStatic(device=self.device1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_vrf_default(self): self.device = Mock(**self.golden_output) obj = ShowIpMrouteStatic(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output,self.golden_parsed_output) def test_golden_vrf_non_default(self): self.device = Mock(**self.golden_output2) obj = ShowIpMrouteStatic(device=self.device) parsed_output = obj.parse(vrf='VRF1') self.assertEqual(parsed_output,self.golden_parsed_output2)
class test_show_ip_mroute(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "vrf": { "default": { "address_family": { "ipv4": { "multicast_group": { "239.1.1.1": { "source_address": { "*": { "expire": "stopped", "rp": "1.1.1.1", "flags": "SPF", 'msdp_learned': False, 'rp_bit': False, "uptime": "00:00:03", "rpf_nbr": "0.0.0.0", }, "1.1.1.1": { "expire": "00:02:57", "flags": "PFT", 'msdp_learned': False, 'rp_bit': False, "uptime": "00:00:03", "rpf_info": "registering", "rpf_nbr": "0.0.0.0", "incoming_interface_list": { "Loopback0": { "rpf_info": "registering", "rpf_nbr": "0.0.0.0" } } }, "10.1.3.1": { "expire": "00:02:57", "flags": "PFT", 'msdp_learned': False, 'rp_bit': False, "uptime": "00:00:03", "rpf_info": "registering", "rpf_nbr": "0.0.0.0", "incoming_interface_list": { "GigabitEthernet2": { "rpf_info": "registering", "rpf_nbr": "0.0.0.0" } } } } }, "224.0.1.40": { "source_address": { "*": { "expire": "00:02:56", "outgoing_interface_list": { "Loopback0": { "expire": "00:02:56", "uptime": "2d09h", "state_mode": "forward/sparse" } }, "flags": "SCL", 'msdp_learned': False, 'rp_bit': False, "rp": "2.2.2.2", "uptime": "2d09h", "rpf_nbr": "0.0.0.0", } } }, "224.1.1.1": { "source_address": { "*": { "expire": "00:02:54", "outgoing_interface_list": { "ATM0/0": { "expire": "00:02:53", "uptime": "00:03:57", "vcd": "14", "state_mode": "forward/sparse" } }, "flags": "SJ", 'msdp_learned': False, 'rp_bit': False, "rp": "172.16.0.0", "uptime": "00:03:57", "rpf_nbr": "224.0.0.0224.0.0.0"}}}}}}}}} golden_output = {'execute.return_value': '''\ IP Multicast Routing Table Flags: D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected, L - Local, P - Pruned, R - RP-bit set, F - Register flag, T - SPT-bit set, J - Join SPT, M - MSDP created entry, E - Extranet, X - Proxy Join Timer Running, A - Candidate for MSDP Advertisement, U - URD, I - Received Source Specific Host Report, Z - Multicast Tunnel, z - MDT-data group sender, Y - Joined MDT-data group, y - Sending to MDT-data group, G - Received BGP C-Mroute, g - Sent BGP C-Mroute, N - Received BGP Shared-Tree Prune, n - BGP C-Mroute suppressed, Q - Received BGP S-A Route, q - Sent BGP S-A Route, V - RD & Vector, v - Vector, p - PIM Joins on route, x - VxLAN group Outgoing interface flags: H - Hardware switched, A - Assert winner, p - PIM Join Timers: Uptime/Expires Interface state: Interface, Next-Hop or VCD, State/Mode (*, 239.1.1.1), 00:00:03/stopped, RP 1.1.1.1, flags: SPF Incoming interface: Null, RPF nbr 0.0.0.0 Outgoing interface list: Null (1.1.1.1, 239.1.1.1), 00:00:03/00:02:57, flags: PFT Incoming interface: Loopback0, RPF nbr 0.0.0.0, Registering Outgoing interface list: Null (10.1.3.1, 239.1.1.1), 00:00:03/00:02:57, flags: PFT Incoming interface: GigabitEthernet2, RPF nbr 0.0.0.0, Registering Outgoing interface list: Null (*, 224.0.1.40), 2d09h/00:02:56, RP 2.2.2.2, flags: SCL Incoming interface: Null, RPF nbr 0.0.0.0 Outgoing interface list: Loopback0, Forward/Sparse, 2d09h/00:02:56 (*, 224.1.1.1), 00:03:57/00:02:54, RP 172.16.0.0, flags: SJ Incoming interface: Null, RPF nbr 224.0.0.0224.0.0.0 Outgoing interface list: ATM0/0, VCD 14, Forward/Sparse, 00:03:57/00:02:53 '''} golden_parsed_output2 = { "vrf": { "VRF1": { "address_family": { "ipv4": { "multicast_group": { "239.1.1.1": { "source_address": { "11.11.11.11": { "expire": "00:02:55", "uptime": "00:00:04", "flags": "PFT", 'msdp_learned': False, 'rp_bit': False, "rpf_info": "registering", "rpf_nbr": "0.0.0.0", "incoming_interface_list": { "Loopback1": { "rpf_info": "registering", "rpf_nbr": "0.0.0.0" } } }, "*": { "expire": "stopped", "uptime": "00:00:04", "flags": "SPF", 'msdp_learned': False, 'rp_bit': False, "rp": "11.11.11.11", "rpf_nbr": "0.0.0.0", } } }, "224.0.1.40": { "source_address": { "*": { "expire": "00:02:52", "uptime": "00:08:58", "rpf_nbr": "0.0.0.0", "outgoing_interface_list": { "Loopback1": { "state_mode": "forward/sparse", "uptime": "00:08:58", "expire": "00:02:52" } }, "flags": "SJCL", 'msdp_learned': False, 'rp_bit': False, "rp": "11.11.11.11"}}}}}}}}} golden_output2 = {'execute.return_value': '''\ IP Multicast Routing Table Flags: D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected, L - Local, P - Pruned, R - RP-bit set, F - Register flag, T - SPT-bit set, J - Join SPT, M - MSDP created entry, E - Extranet, X - Proxy Join Timer Running, A - Candidate for MSDP Advertisement, U - URD, I - Received Source Specific Host Report, Z - Multicast Tunnel, z - MDT-data group sender, Y - Joined MDT-data group, y - Sending to MDT-data group, G - Received BGP C-Mroute, g - Sent BGP C-Mroute, N - Received BGP Shared-Tree Prune, n - BGP C-Mroute suppressed, Q - Received BGP S-A Route, q - Sent BGP S-A Route, V - RD & Vector, v - Vector, p - PIM Joins on route, x - VxLAN group Outgoing interface flags: H - Hardware switched, A - Assert winner, p - PIM Join Timers: Uptime/Expires Interface state: Interface, Next-Hop or VCD, State/Mode (*, 239.1.1.1), 00:00:04/stopped, RP 11.11.11.11, flags: SPF Incoming interface: Null, RPF nbr 0.0.0.0 Outgoing interface list: Null (11.11.11.11, 239.1.1.1), 00:00:04/00:02:55, flags: PFT Incoming interface: Loopback1, RPF nbr 0.0.0.0, Registering Outgoing interface list: Null (*, 224.0.1.40), 00:08:58/00:02:52, RP 11.11.11.11, flags: SJCL Incoming interface: Null, RPF nbr 0.0.0.0 Outgoing interface list: Loopback1, Forward/Sparse, 00:08:58/00:02:52 '''} def test_empty(self): self.device1 = Mock(**self.empty_output) obj = ShowIpMroute(device=self.device1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_vrf_default(self): self.device = Mock(**self.golden_output) obj = ShowIpMroute(device=self.device) parsed_output = obj.parse() self.maxDiff = None self.assertEqual(parsed_output,self.golden_parsed_output) def test_golden_vrf_non_default(self): self.device = Mock(**self.golden_output2) obj = ShowIpMroute(device=self.device) parsed_output = obj.parse(vrf='VRF1') self.maxDiff = None self.assertEqual(parsed_output,self.golden_parsed_output2)
class test_show_ntp_peers(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'peer': { '1.1.1.1': { 'isconfigured': { 'True': { 'address': '1.1.1.1', 'isconfigured': True, 'type': 'server' } } }, '2.2.2.2': { 'isconfigured': { 'True': { 'address': '2.2.2.2', 'isconfigured': True, 'type': 'server' } } }, '4.4.4.4': { 'isconfigured': { 'True': { 'address': '4.4.4.4', 'isconfigured': True, 'type': 'server' } } }, '5.5.5.5': { 'isconfigured': { 'True': { 'address': '5.5.5.5', 'isconfigured': True, 'type': 'server' } } } } } golden_output_1 = { 'execute.return_value': '''\ -------------------------------------------------- Peer IP Address Serv/Peer -------------------------------------------------- 1.1.1.1 Server (configured) 4.4.4.4 Server (configured) 2.2.2.2 Server (configured) 5.5.5.5 Server (configured) ''' } golden_parsed_output_2 = { 'peer': { '10.1.0.63': { 'isconfigured': { 'True': { 'address': '10.1.0.63', 'isconfigured': True, 'type': 'server' } } }, '10.1.0.65': { 'isconfigured': { 'True': { 'address': '10.1.0.65', 'isconfigured': True, 'type': 'server' } } }, '10.100.4.156': { 'isconfigured': { 'True': { 'address': '10.100.4.156', 'isconfigured': True, 'type': 'peer' } } } } } golden_output_2 = { 'execute.return_value': '''\ -------------------------------------------------- Peer IP Address Serv/Peer -------------------------------------------------- 10.100.4.156 Peer (configured) 10.1.0.63 Server (configured) 10.1.0.65 Server (configured) ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpPeers(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_1(self): self.device = Mock(**self.golden_output_1) obj = ShowNtpPeers(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1) def test_golden_2(self): self.device = Mock(**self.golden_output_2) obj = ShowNtpPeers(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_2)
class test_show_ntp_peer_status(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'clock_state': { 'system_status': { 'associations_address': '1.1.1.1', 'clock_state': 'synchronized', 'clock_stratum': 8, 'root_delay': 0.01311 } }, 'vrf': { 'default': { 'peer': { '1.1.1.1': { 'delay': 0.01311, 'local': '0.0.0.0', 'mode': 'synchronized', 'poll': 16, 'reach': 377, 'remote': '1.1.1.1', 'stratum': 8, 'vrf': 'default' }, '2.2.2.2': { 'delay': 0.01062, 'local': '0.0.0.0', 'mode': 'client', 'poll': 16, 'reach': 377, 'remote': '2.2.2.2', 'stratum': 9, 'vrf': 'default' }, '5.5.5.5': { 'delay': 0.0, 'local': '0.0.0.0', 'mode': 'client', 'poll': 64, 'reach': 0, 'remote': '5.5.5.5', 'stratum': 16, 'vrf': 'default' } } }, 'VRF1': { 'peer': { '4.4.4.4': { 'delay': 0.0, 'local': '0.0.0.0', 'mode': 'client', 'poll': 256, 'reach': 0, 'remote': '4.4.4.4', 'stratum': 16, 'vrf': 'VRF1' } } }, }, 'total_peers': 4 } golden_parsed_output_2 = { 'clock_state': { 'system_status': { 'associations_address': '4.4.4.32', 'clock_state': 'synchronized', 'clock_stratum': 4, 'root_delay': 0.02588 } }, 'total_peers': 2, 'vrf': { 'default': { 'peer': { '127.127.1.0': { 'delay': 0.0, 'local': '10.100.100.1', 'mode': 'client', 'poll': 64, 'reach': 0, 'remote': '127.127.1.0', 'stratum': 8 }, '4.4.4.32': { 'delay': 0.02588, 'local': '10.100.100.1', 'mode': 'synchronized', 'poll': 64, 'reach': 377, 'remote': '4.4.4.32', 'stratum': 4, 'vrf': 'default' } } } } } golden_parsed_output_3 = { 'clock_state': { 'system_status': { 'clock_state': 'unsynchronized' } }, 'total_peers': 4, 'vrf': { 'VRF1': { 'peer': { '4.4.4.4': { 'delay': 0.0, 'local': '0.0.0.0', 'mode': 'client', 'poll': 256, 'reach': 0, 'remote': '4.4.4.4', 'stratum': 16, 'vrf': 'VRF1' } } }, 'default': { 'peer': { '1.1.1.1': { 'delay': 0.01311, 'local': '0.0.0.0', 'mode': 'client', 'poll': 16, 'reach': 377, 'remote': '1.1.1.1', 'stratum': 8, 'vrf': 'default' }, '2.2.2.2': { 'delay': 0.01062, 'local': '0.0.0.0', 'mode': 'client', 'poll': 16, 'reach': 377, 'remote': '2.2.2.2', 'stratum': 9, 'vrf': 'default' }, '5.5.5.5': { 'delay': 0.0, 'local': '0.0.0.0', 'mode': 'client', 'poll': 64, 'reach': 0, 'remote': '5.5.5.5', 'stratum': 16, 'vrf': 'default' } } } } } golden_output_1 = { 'execute.return_value': ''' Total peers : 4 * - selected for sync, + - peer mode(active), - - peer mode(passive), = - polled in client mode remote local st poll reach delay vrf ----------------------------------------------------------------------------------------------------------------------- *1.1.1.1 0.0.0.0 8 16 377 0.01311 default =4.4.4.4 0.0.0.0 16 256 0 0.00000 VRF1 =2.2.2.2 0.0.0.0 9 16 377 0.01062 default =5.5.5.5 0.0.0.0 16 64 0 0.00000 default ''' } golden_output_2 = { 'execute.return_value': ''' Total peers : 2 * - selected for sync, + - peer mode(active), - - peer mode(passive), = - polled in client mode remote local st poll reach delay vrf ------------------------------------------------------------------------------- =127.127.1.0 10.100.100.1 8 64 0 0.00000 *4.4.4.32 10.100.100.1 4 64 377 0.02588 default ''' } golden_output_3 = { 'execute.return_value': ''' Total peers : 4 * - selected for sync, + - peer mode(active), - - peer mode(passive), = - polled in client mode remote local st poll reach delay vrf ----------------------------------------------------------------------------------------------------------------------- =1.1.1.1 0.0.0.0 8 16 377 0.01311 default =4.4.4.4 0.0.0.0 16 256 0 0.00000 VRF1 =2.2.2.2 0.0.0.0 9 16 377 0.01062 default =5.5.5.5 0.0.0.0 16 64 0 0.00000 default ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpPeerStatus(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_1(self): self.maxDiff = None self.device = Mock(**self.golden_output_1) obj = ShowNtpPeerStatus(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1) def test_golden_2(self): self.maxDiff = None self.device = Mock(**self.golden_output_2) obj = ShowNtpPeerStatus(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_2) def test_golden_3(self): self.maxDiff = None self.device = Mock(**self.golden_output_3) obj = ShowNtpPeerStatus(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_3)
class test_show_isis_neighbors(unittest.TestCase): '''Unit test for "show isis neighbors"''' device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output1 = { 'isis': { 'test': { 'neighbors': { 'R2_xr': { 'type': { 'L1': { 'interface': 'Gi2.115', 'ip_address': '10.12.115.2', 'state': 'UP', 'holdtime': '7', 'circuit_id': 'R2_xr.01'}, 'L2': { 'interface': 'Gi2.115', 'ip_address': '10.12.115.2', 'state': 'UP', 'holdtime': '7', 'circuit_id': 'R2_xr.01'}}}, 'R3_nx': { 'type': { 'L1': { 'interface': 'Gi3.115', 'ip_address': '10.13.115.3', 'state': 'UP', 'holdtime': '28', 'circuit_id': 'R1_xe.02'}, 'L2': { 'interface': 'Gi3.115', 'ip_address': '10.13.115.3', 'state': 'UP', 'holdtime': '23', 'circuit_id': 'R1_xe.02'}}}}}, 'test1': { 'neighbors': { '2222.2222.2222': { 'type': { 'L1': { 'interface': 'Gi2.415', 'ip_address': '10.12.115.2', 'state': 'INIT', 'holdtime': '21', 'circuit_id': '2222.2222.2222.01'}, 'L2': { 'interface': 'Gi2.415', 'ip_address': '10.12.115.2', 'state': 'INIT', 'holdtime': '20', 'circuit_id': '2222.2222.2222.01'}}}, 'R3_nx': { 'type': { 'L1': { 'interface': 'Gi3.415', 'ip_address': '10.13.115.3', 'state': 'UP', 'holdtime': '21', 'circuit_id': 'R1_xe.02'}, 'L2': { 'interface': 'Gi3.415', 'ip_address': '10.13.115.3', 'state': 'UP', 'holdtime': '27', 'circuit_id': 'R1_xe.02'}}}}}}} golden_output1 = {'execute.return_value': ''' R1_xe#show isis neighbors Tag test: System Id Type Interface IP Address State Holdtime Circuit Id R2_xr L1 Gi2.115 10.12.115.2 UP 7 R2_xr.01 R2_xr L2 Gi2.115 10.12.115.2 UP 7 R2_xr.01 R3_nx L1 Gi3.115 10.13.115.3 UP 28 R1_xe.02 R3_nx L2 Gi3.115 10.13.115.3 UP 23 R1_xe.02 Tag test1: System Id Type Interface IP Address State Holdtime Circuit Id 2222.2222.2222 L1 Gi2.415 10.12.115.2 INIT 21 2222.2222.2222.01 2222.2222.2222 L2 Gi2.415 10.12.115.2 INIT 20 2222.2222.2222.01 R3_nx L1 Gi3.415 10.13.115.3 UP 21 R1_xe.02 R3_nx L2 Gi3.415 10.13.115.3 UP 27 R1_xe.02 '''} def test_show_isis_neighbors_empty(self): self.device = Mock(**self.empty_output) obj = ShowIsisNeighbors(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_show_isis_neighbors_golden1(self): self.maxDiff = None self.device = Mock(**self.golden_output1) obj = ShowIsisNeighbors(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output1)
class test_show_ip_traffic(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'arp_statistics': { 'arp_drops_input_full': 0, 'arp_in_other': 0, 'arp_in_replies': 25520, 'arp_in_requests': 26338, 'arp_in_reverse': 42, 'arp_out_proxy': 0, 'arp_out_replies': 1399, 'arp_out_requests': 123, 'arp_out_reverse': 0 }, 'bgp_statistics': { 'bgp_received_keepalives': 0, 'bgp_received_notifications': 0, 'bgp_received_opens': 0, 'bgp_received_route_refresh': 0, 'bgp_received_total': 0, 'bgp_received_unrecognized': 0, 'bgp_received_updates': 0, 'bgp_sent_keepalives': 0, 'bgp_sent_notifications': 0, 'bgp_sent_opens': 0, 'bgp_sent_route_refresh': 0, 'bgp_sent_total': 0, 'bgp_sent_updates': 0 }, 'eigrp_ipv4_statistics': { 'eigrp_ipv4_received_total': 0, 'eigrp_ipv4_sent_total': 0 }, 'icmp_statistics': { 'icmp_received_checksum_errors': 0, 'icmp_received_echo': 43838, 'icmp_received_echo_reply': 713, 'icmp_received_format_errors': 0, 'icmp_received_info_request': 0, 'icmp_received_irdp_advertisements': 0, 'icmp_received_irdp_solicitations': 0, 'icmp_received_mask_replies': 0, 'icmp_received_mask_requests': 0, 'icmp_received_other': 0, 'icmp_received_parameter': 0, 'icmp_received_quench': 0, 'icmp_received_redirects': 0, 'icmp_received_timestamp': 0, 'icmp_received_unreachable': 0, 'icmp_sent_echo': 730, 'icmp_sent_echo_reply': 43838, 'icmp_sent_info_reply': 0, 'icmp_sent_irdp_advertisements': 0, 'icmp_sent_irdp_solicitations': 0, 'icmp_sent_mask_replies': 0, 'icmp_sent_mask_requests': 0, 'icmp_sent_parameter_problem': 0, 'icmp_sent_quench': 0, 'icmp_sent_redirects': 0, 'icmp_sent_time_exceeded': 0, 'icmp_sent_timestamp': 0, 'icmp_sent_unreachable': 4 }, 'igmp_statistics': { 'igmp_checksum_errors': '0/0', 'igmp_dvmrp': '0/0', 'igmp_format_errors': '0/0', 'igmp_host_leaves': '0/0', 'igmp_host_queries': '0/0', 'igmp_host_reports': '0/0', 'igmp_pim': '0/0', 'igmp_total': '0/0' }, 'ip_statistics': { 'ip_bcast_received': 653921, 'ip_bcast_sent': 6, 'ip_drop_encap_failed': 10, 'ip_drop_forced_drop': 0, 'ip_drop_no_adj': 0, 'ip_drop_no_route': 0, 'ip_drop_opts_denied': 0, 'ip_drop_src_ip': 0, 'ip_drop_unicast_rpf': 0, 'ip_drop_unresolved': 0, 'ip_frags_fragmented': 0, 'ip_frags_no_fragmented': 0, 'ip_frags_no_reassembled': 0, 'ip_frags_reassembled': 0, 'ip_frags_timeouts': 0, 'ip_mcast_received': 0, 'ip_mcast_sent': 0, 'ip_opts_alert': 0, 'ip_opts_basic_security': 0, 'ip_opts_cipso': 0, 'ip_opts_end': 0, 'ip_opts_extended_security': 0, 'ip_opts_loose_src_route': 0, 'ip_opts_nop': 0, 'ip_opts_other': 0, 'ip_opts_record_route': 0, 'ip_opts_strct_src_route': 0, 'ip_opts_strm_id': 0, 'ip_opts_timestamp': 0, 'ip_opts_ump': 0, 'ip_rcvd_bad_hop': 811, 'ip_rcvd_bad_optns': 0, 'ip_rcvd_checksum_errors': 0, 'ip_rcvd_format_errors': 0, 'ip_rcvd_local_destination': 843331, 'ip_rcvd_not_gateway': 6, 'ip_rcvd_sec_failures': 0, 'ip_rcvd_total': 844148, 'ip_rcvd_unknwn_protocol': 0, 'ip_rcvd_with_optns': 0, 'ip_sent_forwarded': 0, 'ip_sent_generated': 212110 }, 'ospf_statistics': { 'ospf_received_checksum_errors': 0, 'ospf_received_database_desc': 0, 'ospf_received_hello': 0, 'ospf_received_link_state_req': 0, 'ospf_received_lnk_st_acks': 0, 'ospf_received_lnk_st_updates': 0, 'ospf_received_total': 0, 'ospf_sent_database_desc': 0, 'ospf_sent_hello': 0, 'ospf_sent_lnk_st_acks': 0, 'ospf_sent_lnk_st_updates': 0, 'ospf_sent_total': 0 }, 'pimv2_statistics': { 'pimv2_asserts': '0/0', 'pimv2_bootstraps': '0/0', 'pimv2_candidate_rp_advs': '0/0', 'pimv2_checksum_errors': 0, 'pimv2_format_errors': 0, 'pimv2_grafts': '0/0', 'pimv2_hellos': '0/0', 'pimv2_join_prunes': '0/0', 'pimv2_non_rp': 0, 'pimv2_non_sm_group': 0, 'pimv2_registers': '0/0', 'pimv2_registers_stops': '0/0', 'pimv2_state_refresh': '0/0', 'pimv2_total': '0/0' }, 'tcp_statistics': { 'tcp_received_checksum_errors': 0, 'tcp_received_no_port': 0, 'tcp_received_total': 116563, 'tcp_sent_total': 139252 }, 'udp_statistics': { 'udp_received_no_port': 289579, 'udp_received_total': 682217, 'udp_received_udp_checksum_errors': 0, 'udp_sent_fwd_broadcasts': 0, 'udp_sent_total': 28296 } } golden_output = { 'execute.return_value': ''' R5#show ip traffic IP statistics: Rcvd: 844148 total, 843331 local destination 0 format errors, 0 checksum errors, 811 bad hop count 0 unknown protocol, 6 not a gateway 0 security failures, 0 bad options, 0 with options Opts: 0 end, 0 nop, 0 basic security, 0 loose source route 0 timestamp, 0 extended security, 0 record route 0 stream ID, 0 strict source route, 0 alert, 0 cipso, 0 ump 0 other Frags: 0 reassembled, 0 timeouts, 0 couldn't reassemble 0 fragmented, 0 couldn't fragment Bcast: 653921 received, 6 sent Mcast: 0 received, 0 sent Sent: 212110 generated, 0 forwarded Drop: 10 encapsulation failed, 0 unresolved, 0 no adjacency 0 no route, 0 unicast RPF, 0 forced drop 0 options denied, 0 source IP address zero ICMP statistics: Rcvd: 0 format errors, 0 checksum errors, 0 redirects, 0 unreachable 43838 echo, 713 echo reply, 0 mask requests, 0 mask replies, 0 quench 0 parameter, 0 timestamp, 0 info request, 0 other 0 irdp solicitations, 0 irdp advertisements Sent: 0 redirects, 4 unreachable, 730 echo, 43838 echo reply 0 mask requests, 0 mask replies, 0 quench, 0 timestamp 0 info reply, 0 time exceeded, 0 parameter problem 0 irdp solicitations, 0 irdp advertisements BGP statistics: Rcvd: 0 total, 0 opens, 0 notifications, 0 updates 0 keepalives, 0 route-refresh, 0 unrecognized Sent: 0 total, 0 opens, 0 notifications, 0 updates 0 keepalives, 0 route-refresh TCP statistics: Rcvd: 116563 total, 0 checksum errors, 0 no port Sent: 139252 total EIGRP-IPv4 statistics: Rcvd: 0 total Sent: 0 total PIMv2 statistics: Sent/Received Total: 0/0, 0 checksum errors, 0 format errors Registers: 0/0 (0 non-rp, 0 non-sm-group), Register Stops: 0/0, Hellos: 0/0 Join/Prunes: 0/0, Asserts: 0/0, grafts: 0/0 Bootstraps: 0/0, Candidate_RP_Advertisements: 0/0 State-Refresh: 0/0 IGMP statistics: Sent/Received Total: 0/0, Format errors: 0/0, Checksum errors: 0/0 Host Queries: 0/0, Host Reports: 0/0, Host Leaves: 0/0 DVMRP: 0/0, PIM: 0/0 UDP statistics: Rcvd: 682217 total, 0 checksum errors, 289579 no port Sent: 28296 total, 0 forwarded broadcasts OSPF statistics: Rcvd: 0 total, 0 checksum errors 0 hello, 0 database desc, 0 link state req 0 link state updates, 0 link state acks Sent: 0 total 0 hello, 0 database desc, 0 link state req 0 link state updates, 0 link state acks ARP statistics: Rcvd: 26338 requests, 25520 replies, 42 reverse, 0 other Sent: 123 requests, 1399 replies (0 proxy), 0 reverse Drop due to input queue full: 0 ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowIpTraffic(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIpTraffic(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output)
class test_show_access_lists(unittest.TestCase): dev1 = Device(name='empty') dev_c3850 = Device(name='c3850') empty_output = {'execute.return_value': ' '} golden_parsed_output = { 'acl_name': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'ipv4': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'ipv4', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'ipv4': { 'established': False } } }, 'name': '10', 'statistics': { 'matched_packets': 10031 } } }, 'name': 'acl_name', 'type': 'ipv4-acl-type' }, 'ipv4_acl': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'tcp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'tcp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'tcp': { 'destination_port': { 'operator': { 'operator': 'eq', 'port': 80 } }, 'established': False } } }, 'name': '10' }, '20': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'tcp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'tcp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'tcp': { 'destination_port': { 'operator': { 'operator': 'eq', 'port': 22 } }, 'established': False } } }, 'name': '20' } }, 'name': 'ipv4_acl', 'type': 'ipv4-acl-type' }, 'test1': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-syslog' }, 'matches': { 'l3': { 'pim': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'dscp': 'default', 'protocol': 'pim', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'pim': { 'established': False } } }, 'name': '10' }, '20': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'icmp': { 'source_network': { '0.1.1.1 255.0.0.0': { 'source_network': '0.1.1.1 ' '255.0.0.0' } }, 'protocol': 'icmp', 'destination_network': { 'any': { 'destination_network': 'any' } } } }, 'l4': { 'icmp': { 'code': 66, 'established': False, 'type': 10 } } }, 'name': '20' } }, 'name': 'test1', 'type': 'ipv4-acl-type' }, 'test22': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-syslog' }, 'matches': { 'l3': { 'tcp': { 'source_network': { '192.168.1.0 0.0.0.255': { 'source_network': '192.168.1.0 ' '0.0.0.255' } }, 'protocol': 'tcp', 'destination_network': { 'host 1.1.1.1': { 'destination_network': 'host 1.1.1.1' } } } }, 'l4': { 'tcp': { 'established': True } } }, 'name': '10' }, '20': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'tcp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'precedence': 'network', 'protocol': 'tcp', 'source_network': { 'host 2.2.2.2': { 'source_network': 'host 2.2.2.2' } }, 'ttl': 255, 'ttl_operator': 'eq' } }, 'l4': { 'tcp': { 'established': False, 'source_port': { 'operator': { 'operator': 'eq', 'port': 'www telnet 443' } } } } }, 'name': '20' }, '30': { 'actions': { 'forwarding': 'deny', 'logging': 'log-none' }, 'matches': { 'l3': { 'ipv4': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'ipv4', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'ipv4': { 'established': False } } }, 'name': '30' }, '40': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'tcp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'tcp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'tcp': { 'established': False, 'source_port': { 'range': { 'lower_port': 20, 'upper_port': 179 } } } } }, 'name': '40' } }, 'name': 'test22', 'type': 'ipv4-acl-type' }, 'ipv6_acl': { 'aces': { '20': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'ipv6': { 'destination_network': { 'host 2001:1::2': { 'destination_network': 'host 2001:1::2' } }, 'protocol': 'ipv6', 'source_network': { 'host 2001::1': { 'source_network': 'host 2001::1' } } } }, 'l4': { 'ipv6': { 'established': False } } }, 'name': '20' }, '30': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'tcp': { 'destination_network': { 'host 2001:2::2': { 'destination_network': 'host 2001:2::2' } }, 'protocol': 'tcp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'tcp': { 'established': False, 'source_port': { 'operator': { 'operator': 'eq', 'port': 'www ' '8443' } } } } }, 'name': '30' }, '80': { 'actions': { 'forwarding': 'permit', 'logging': 'log-syslog' }, 'matches': { 'l3': { 'ipv6': { 'destination_network': { '1:1::1 6:6::6': { 'destination_network': '1:1::1 ' '6:6::6' } }, 'protocol': 'ipv6', 'source_network': { '3:3::3 4:4::4': { 'source_network': '3:3::3 ' '4:4::4' } } } }, 'l4': { 'ipv6': { 'established': False } } }, 'name': '80' } }, 'name': 'ipv6_acl', 'type': 'ipv6-acl-type' }, 'preauth_v6': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l3': { 'udp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'udp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'udp': { 'destination_port': { 'operator': { 'operator': 'eq', 'port': 53 } }, 'established': False } } }, 'name': '10' }, '20': { 'actions': { 'forwarding': 'permit', 'logging': 'log-syslog' }, 'matches': { 'l3': { 'esp': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'dscp': 'cs7', 'protocol': 'esp', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'esp': { 'established': False } } }, 'name': '20' }, '30': { 'actions': { 'forwarding': 'deny', 'logging': 'log-none' }, 'matches': { 'l3': { 'ipv6': { 'destination_network': { 'any': { 'destination_network': 'any' } }, 'protocol': 'ipv6', 'source_network': { 'any': { 'source_network': 'any' } } } }, 'l4': { 'ipv6': { 'established': False } } }, 'name': '30' } }, 'name': 'preauth_v6', 'per_user': True, 'type': 'ipv6-acl-type' }, 'mac_acl': { 'aces': { '10': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l2': { 'eth': { 'destination_mac_address': 'any', 'source_mac_address': 'any' } } }, 'name': '10' }, '20': { 'actions': { 'forwarding': 'deny', 'logging': 'log-none' }, 'matches': { 'l2': { 'eth': { 'destination_mac_address': 'any', 'ether_type': 'msdos', 'source_mac_address': 'any' } } }, 'name': '20' }, '30': { 'actions': { 'forwarding': 'deny', 'logging': 'log-none' }, 'matches': { 'l2': { 'eth': { 'destination_mac_address': 'any', 'source_mac_address': 'any', 'vlan': 10 } } }, 'name': '30' }, '40': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l2': { 'eth': { 'destination_mac_address': 'host 0003.0003.0003', 'lsap': '0x1 ' '0xD8FE', 'source_mac_address': 'host 0001.0002.0033' } } }, 'name': '40' }, '50': { 'actions': { 'forwarding': 'permit', 'logging': 'log-none' }, 'matches': { 'l2': { 'eth': { 'cos': 4, 'destination_mac_address': 'any', 'ether_type': 'aarp', 'source_mac_address': 'any', 'vlan': 20 } } }, 'name': '50' } }, 'name': 'mac_acl', 'type': 'eth-acl-type' } } golden_output = { 'execute.return_value': '''\ Extended IP access list acl_name 10 permit ip any any (10031 matches) Extended IP access list ipv4_acl 10 permit tcp any any eq www 20 permit tcp any any eq 22 Extended IP access list test1 10 permit pim any any dscp default option 222 log 20 permit icmp 0.1.1.1 255.0.0.0 any 10 66 Extended IP access list test22 10 permit tcp 192.168.1.0 0.0.0.255 host 1.1.1.1 established log 20 permit tcp host 2.2.2.2 eq www telnet 443 any precedence network ttl eq 255 30 deny ip any any 40 permit tcp any range ftp-data bgp any IPv6 access list ipv6_acl permit ipv6 host 2001::1 host 2001:1::2 sequence 20 permit tcp any eq www 8443 host 2001:2::2 sequence 30 permit ipv6 3:3::3 4:4::4 1:1::1 6:6::6 log sequence 80 IPv6 access list preauth_v6 (per-user) permit udp any any eq domain sequence 10 permit esp any any dscp cs7 log sequence 20 deny ipv6 any any sequence 30 Extended MAC access list mac_acl permit any any deny any any msdos deny any any vlan 10 permit host 0001.0002.0033 host 0003.0003.0003 lsap 0x1 0xD8FE permit any any aarp cos 4 vlan 20 ''' } def test_empty(self): self.dev1 = Mock(**self.empty_output) obj = ShowAccessLists(device=self.dev1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.maxDiff = None self.dev_c3850 = Mock(**self.golden_output) obj = ShowAccessLists(device=self.dev_c3850) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output)
class test_show_ip_arp(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'interfaces': { 'FastEthernet0': { 'ipv4': { 'neighbors': { '10.1.8.1': { 'age': '79', 'ip': '10.1.8.1', 'link_layer_address': '0012.7f57.ac80', 'origin': 'dynamic', 'protocol': 'Internet', 'type': 'ARPA' }, '10.1.8.146': { 'age': '-', 'ip': '10.1.8.146', 'link_layer_address': '843d.c638.b9b7', 'origin': 'static', 'protocol': 'Internet', 'type': 'ARPA' } } } }, 'Port-channel10': { 'ipv4': { 'neighbors': { '1.2.1.1': { 'age': '-', 'ip': '1.2.1.1', 'link_layer_address': '843d.c638.b9c6', 'origin': 'static', 'protocol': 'Internet', 'type': 'ARPA' } } } }, 'Vlan99': { 'ipv4': { 'neighbors': { '18.0.1.2': { 'age': '-', 'ip': '18.0.1.2', 'link_layer_address': '843d.c638.b9c1', 'origin': 'static', 'protocol': 'Internet', 'type': 'ARPA' } } } } } } golden_output = { 'execute.return_value': '''\ R5#show ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 10.1.8.1 79 0012.7f57.ac80 ARPA FastEthernet0 Internet 1.2.1.1 - 843d.c638.b9c6 ARPA Port-channel10 Internet 18.0.1.2 - 843d.c638.b9c1 ARPA Vlan99 Internet 10.1.8.146 - 843d.c638.b9b7 ARPA FastEthernet0 ''' } golden_parsed_output_1 = { 'interfaces': { 'FastEthernet0': { 'ipv4': { 'neighbors': { '10.1.8.1': { 'age': '79', 'ip': '10.1.8.1', 'link_layer_address': '0012.7f57.ac80', 'origin': 'dynamic', 'protocol': 'Internet', 'type': 'ARPA' }, '10.1.8.146': { 'age': '-', 'ip': '10.1.8.146', 'link_layer_address': '843d.c638.b9b7', 'origin': 'static', 'protocol': 'Internet', 'type': 'ARPA' } } } } } } golden_output_1 = { 'execute.return_value': '''\ R5#show ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 10.1.8.1 79 0012.7f57.ac80 ARPA FastEthernet0 Internet 10.1.8.146 - 843d.c638.b9b7 ARPA FastEthernet0 ''' } def test_empty(self): self.device1 = Mock(**self.empty_output) obj = ShowIpArp(device=self.device1) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.device = Mock(**self.golden_output) obj = ShowIpArp(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output) def test_golden_1(self): self.device = Mock(**self.golden_output_1) obj = ShowIpArp(device=self.device) parsed_output = obj.parse(vrf='Mgmt-vrf', intf_or_ip='FastEthernet0') self.assertEqual(parsed_output, self.golden_parsed_output_1)
class test_show_hsrp_summary(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'global_hsrp_bfd': 'enabled', 'intf_total': 1, 'nsf': 'enabled', 'nsf_time': 10, 'pkt_unknown_groups': 0, 'total_mts_rx': 85, 'stats': { 'total_groups': 3, 'active': 0, 'listen': 0, 'standby': 0, 'v1_ipv4': 0, 'v2_ipv4': 3, 'v2_ipv6': 0, 'v6_active': 0, 'v6_listen': 0, 'v6_standby': 0 }, 'total_packets': { 'rx_good': 0, 'tx_fail': 0, 'tx_pass': 0, } } golden_output = { 'execute.return_value': ''' HSRP Summary: Extended-hold (NSF) enabled, 10 seconds Global HSRP-BFD enabled Total Groups: 3 Version:: V1-IPV4: 0 V2-IPV4: 3 V2-IPV6: 0 State:: Active: 0 Standby: 0 Listen: 0 State:: V6-Active: 0 V6-Standby: 0 V6-Listen: 0 Total HSRP Enabled interfaces: 1 Total Packets: Tx - Pass: 0 Fail: 0 Rx - Good: 0 Packet for unknown groups: 0 Total MTS: Rx: 85 ''' } def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) hsrp_summary_obj = ShowHsrpSummary(device=self.device) parsed_output = hsrp_summary_obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output) def test_empty(self): self.device = Mock(**self.empty_output) hsrp_summary_obj = ShowHsrpSummary(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = hsrp_summary_obj.parse()
def setUp(self): self.device = Device(name='aDevice') self.device.os = 'iosxe' self.device.custom['abstraction'] = {'order': ['os']} self.device.mapping = {}
class test_show_ntp_status(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'clock_state': { 'system_status': { 'act_freq': 1000.4589, 'last_update': '182 sec ago', 'nom_freq': 1000.0003, 'offset': 27.0279, 'peerdispersion': 3.34, 'poll': 64, 'precision': '2**14', 'refid': '10.16.2.2', 'reftime': 'DFA02517.D2F7B9F6 ' '(13:40:23.824 EST Wed Nov ' '21 2018)', 'resolution': 1000, 'rootdelay': 5.61, 'rootdispersion': 273.61, 'status': 'synchronized', 'stratum': 4, 'uptime': '239700 (1/100 of seconds)' } } } golden_output_1 = { 'execute.return_value': '''\ iosv-1#show ntp status Clock is synchronized, stratum 4, reference is 10.16.2.2 nominal freq is 1000.0003 Hz, actual freq is 1000.4589 Hz, precision is 2**14 ntp uptime is 239700 (1/100 of seconds), resolution is 1000 reference time is DFA02517.D2F7B9F6 (13:40:23.824 EST Wed Nov 21 2018) clock offset is 27.0279 msec, root delay is 5.61 msec root dispersion is 273.61 msec, peer dispersion is 3.34 msec loopfilter state is 'CTRL' (Normal Controlled Loop), drift is -0.000458631 s/s system poll interval is 64, last update was 182 sec ago. ''' } golden_parsed_output_2 = { 'clock_state': { 'system_status': { 'act_freq': 1000.4923, 'last_update': '1301 sec ago', 'nom_freq': 1000.0003, 'offset': 0.0, 'peerdispersion': 0.0, 'poll': 64, 'precision': '2**13', 'reftime': 'DFA98D6B.F2F229A7 ' '(16:55:55.949 EST Wed Nov ' '28 2018)', 'resolution': 1000, 'rootdelay': 0.0, 'rootdispersion': 18.84, 'status': 'unsynchronized', 'stratum': 16, 'uptime': '1938800 (1/100 of seconds)' } } } golden_output_2 = { 'execute.return_value': '''\ show ntp status Clock is unsynchronized, stratum 16, no reference clock nominal freq is 1000.0003 Hz, actual freq is 1000.4923 Hz, precision is 2**13 ntp uptime is 1938800 (1/100 of seconds), resolution is 1000 reference time is DFA98D6B.F2F229A7 (16:55:55.949 EST Wed Nov 28 2018) clock offset is 0.0000 msec, root delay is 0.00 msec root dispersion is 18.84 msec, peer dispersion is 0.00 msec loopfilter state is 'SPIK' (Spike), drift is -0.000491998 s/s system poll interval is 64, last update was 1301 sec ago. iosv-1 ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpStatus(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_1(self): self.device = Mock(**self.golden_output_1) obj = ShowNtpStatus(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1) def test_golden_2(self): self.device = Mock(**self.golden_output_2) obj = ShowNtpStatus(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_2)
class test_show_vrf_all_detail(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "VRF1": { "description": "not set", "vrf_mode": "regular", "address_family": { "ipv6 unicast": { "route_target": { "400:1": { "rt_type": "import", "route_target": "400:1" }, "300:1": { "rt_type": "import", "route_target": "300:1" }, "200:1": { "rt_type": "both", "route_target": "200:1" }, "200:2": { "rt_type": "import", "route_target": "200:2" } } }, "ipv4 unicast": { "route_target": { "400:1": { "rt_type": "import", "route_target": "400:1" }, "300:1": { "rt_type": "import", "route_target": "300:1" }, "200:1": { "rt_type": "both", "route_target": "200:1" }, "200:2": { "rt_type": "import", "route_target": "200:2" } } } }, "route_distinguisher": "200:1", "interfaces": [ "GigabitEthernet0/0/0/1" ] }, "VRF2": { "description": "not set", "vrf_mode": "regular", "address_family": { "ipv6 unicast": { "route_target": { "200:2": { "rt_type": "both", "route_target": "200:2" } } }, "ipv4 unicast": { "route_target": { "200:2": { "rt_type": "both", "route_target": "200:2" } } } }, "route_distinguisher": "200:2", "interfaces": [ "GigabitEthernet0/0/0/2" ]} } golden_output = {'execute.return_value': ''' Mon Sep 18 09:36:51.507 PDT VRF VRF1; RD 200:1; VPN ID not set VRF mode: Regular Description not set Interfaces: GigabitEthernet0/0/0/1 Address family IPV4 Unicast Import VPN route-target communities: RT:200:1 RT:200:2 RT:300:1 RT:400:1 Export VPN route-target communities: RT:200:1 No import route policy No export route policy Address family IPV6 Unicast Import VPN route-target communities: RT:200:1 RT:200:2 RT:300:1 RT:400:1 Export VPN route-target communities: RT:200:1 No import route policy No export route policy VRF VRF2; RD 200:2; VPN ID not set VRF mode: Regular Description not set Interfaces: GigabitEthernet0/0/0/2 Address family IPV4 Unicast Import VPN route-target communities: RT:200:2 Export VPN route-target communities: RT:200:2 No import route policy No export route policy Address family IPV6 Unicast Import VPN route-target communities: RT:200:2 Export VPN route-target communities: RT:200:2 No import route policy No export route policy '''} def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowVrfAllDetail(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output) def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowVrfAllDetail(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse()
class test_show_ntp_config(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_1 = { 'vrf': { 'default': { 'address': { '10.16.2.2': { 'isconfigured': { 'True': { 'address': '10.16.2.2', 'isconfigured': True } }, 'type': { 'server': { 'address': '10.16.2.2', 'source': 'Loopback0', 'type': 'server', 'vrf': 'default' } } }, '10.36.3.3': { 'isconfigured': { 'True': { 'address': '10.36.3.3', 'isconfigured': True } }, 'type': { 'server': { 'address': '10.36.3.3', 'type': 'server', 'vrf': 'default' } } } } } } } golden_output_1 = { 'execute.return_value': '''\ iosv-1#show ntp config ntp server 10.16.2.2 source Loopback0 ntp server 10.36.3.3 ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowNtpConfig(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden_1(self): self.device = Mock(**self.golden_output_1) obj = ShowNtpConfig(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output_1)
class test_show_isis_lsp_log(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "tag": { "VRF1": { "lsp_log": { "level": { 1: { "index": { 1: { "when": "01:13:52", "count": 5, "triggers": "CONFIG OTVINFOCHG" }, 2: { "when": "00:25:46", "count": 1, "triggers": "ATTACHFLAG" }, 3: { "when": "00:25:44", "count": 2, "triggers": "ATTACHFLAG IPV6IA" } } }, 2: { "index": { 1: { "when": "01:13:52", "count": 5, "triggers": "CONFIG OTVINFOCHG" }, 2: { "when": "00:25:46", "count": 2, "triggers": "NEWADJ DIS", "interface": "GigabitEthernet4" }, 3: { "when": "00:25:45", "count": 1, "triggers": "ADJMTIDCHG", "interface": "GigabitEthernet4" } } } } } } } } golden_output = {'execute.return_value': '''\ R2#show isis lsp-log Tag VRF1: Level 1 LSP log When Count Interface Triggers 01:13:52 5 CONFIG OTVINFOCHG 00:25:46 1 ATTACHFLAG 00:25:44 2 ATTACHFLAG IPV6IA Level 2 LSP log When Count Interface Triggers 01:13:52 5 CONFIG OTVINFOCHG 00:25:46 2 GigabitEthernet4 NEWADJ DIS 00:25:45 1 GigabitEthernet4 ADJMTIDCHG ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowIsisLspLog(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIsisLspLog(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output)
class test_show_ipv6_neighbor_detail(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'interfaces': { 'Ethernet1/1': { 'interface': 'Ethernet1/1', 'neighbors': { '2001:db8:c56d:4::2': { 'ip': '2001:db8:c56d:4::2', 'link_layer_address': 'fa16.3e82.6320', 'age': '00:09:27', 'preference': 50, 'origin': 'other', 'physical_interface': 'Ethernet1/1', 'packet_count': 0, 'byte_count': 0, 'best': 'Yes', 'throttled': 'No', }, '2001:db8:c56d:4::33': { 'ip': '2001:db8:c56d:4::33', 'link_layer_address': 'aabb.beef.cccc', 'age': '2d15h', 'preference': 1, 'origin': 'static', 'physical_interface': 'Ethernet1/1', 'packet_count': 0, 'byte_count': 0, 'best': 'Yes', 'throttled': 'No', }, 'fe80::f816:3eff:fe82:6320': { 'ip': 'fe80::f816:3eff:fe82:6320', 'link_layer_address': 'fa16.3e82.6320', 'age': '00:05:42', 'preference': 50, 'origin': 'other', 'physical_interface': 'Ethernet1/1', 'packet_count': 0, 'byte_count': 0, 'best': 'Yes', 'throttled': 'No', }, '2001:db8:c56d:4::34': { 'ip': '2001:db8:c56d:4::34', 'link_layer_address': 'aaab.beef.ccce', 'age': '1d18h', 'preference': 1, 'origin': 'static', 'physical_interface': 'Ethernet1/1', 'packet_count': 0, 'byte_count': 0, 'best': 'Yes', 'throttled': 'No', }, }, }, 'Ethernet1/2': { 'interface': 'Ethernet1/2', 'neighbors': { '2001:db8:c8d1:4::33': { 'ip': '2001:db8:c8d1:4::33', 'link_layer_address': 'aaaa.bbbb.cccc', 'age': '2d15h', 'preference': 1, 'origin': 'static', 'physical_interface': 'Ethernet1/2', 'packet_count': 0, 'byte_count': 0, 'best': 'Yes', 'throttled': 'No', }, }, }, }, 'adjacency_hit': { 'GLEAN': { 'byte_count': 0, 'packet_count': 0 }, 'GLOBAL DROP': { 'byte_count': 0, 'packet_count': 0 }, 'GLOBAL GLEAN': { 'byte_count': 0, 'packet_count': 0 }, 'GLOBAL PUNT': { 'byte_count': 0, 'packet_count': 0 }, 'INVALID': { 'byte_count': 0, 'packet_count': 0 }, 'NORMAL': { 'byte_count': 0, 'packet_count': 0 } }, 'adjacency_statistics_last_updated_before': 'never', 'total_number_of_entries': 11 } golden_output = { 'execute.return_value': ''' n9kv-3# show ipv6 neighbor detail vrf all No. of Adjacency hit with type INVALID: Packet count 0, Byte count 0 No. of Adjacency hit with type GLOBAL DROP: Packet count 0, Byte count 0 No. of Adjacency hit with type GLOBAL PUNT: Packet count 0, Byte count 0 No. of Adjacency hit with type GLOBAL GLEAN: Packet count 0, Byte count 0 No. of Adjacency hit with type GLEAN: Packet count 0, Byte count 0 No. of Adjacency hit with type NORMAL: Packet count 0, Byte count 0 Adjacency statistics last updated before: never IPv6 Adjacency Table for all VRFs Total number of entries: 11 Address : 2001:db8:c56d:4::2 Age : 00:09:27 MacAddr : fa16.3e82.6320 Preference : 50 Source : icmpv6 Interface : Ethernet1/1 Physical Interface : Ethernet1/1 Packet Count : 0 Byte Count : 0 Best : Yes Throttled : No Address : 2001:db8:c56d:4::33 Age : 2d15h MacAddr : aabb.beef.cccc Preference : 1 Source : Static Interface : Ethernet1/1 Physical Interface : Ethernet1/1 Packet Count : 0 Byte Count : 0 Best : Yes Throttled : No Address : 2001:db8:c56d:4::34 Age : 1d18h MacAddr : aaab.beef.ccce Preference : 1 Source : Static Interface : Ethernet1/1 Physical Interface : Ethernet1/1 Packet Count : 0 Byte Count : 0 Best : Yes Throttled : No Address : fe80::f816:3eff:fe82:6320 Age : 00:05:42 MacAddr : fa16.3e82.6320 Preference : 50 Source : icmpv6 Interface : Ethernet1/1 Physical Interface : Ethernet1/1 Packet Count : 0 Byte Count : 0 Best : Yes Throttled : No Address : 2001:db8:c8d1:4::33 Age : 2d15h MacAddr : aaaa.bbbb.cccc Preference : 1 Source : Static Interface : Ethernet1/2 Physical Interface : Ethernet1/2 Packet Count : 0 Byte Count : 0 Best : Yes Throttled : No ''' } def test_show_ipv6_neighbor_detail_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIpv6NeighborDetail(device=self.device) parsed_output = obj.parse(vrf='all') self.assertEqual(parsed_output, self.golden_parsed_output) def test_show_ipv6_neighbor_detail_empty(self): self.device = Mock(**self.empty_output) obj = ShowIpv6NeighborDetail(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse()
class test_show_isis_hostname(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'tag':{ 'VRF1':{ 'hostname_db': { 'hostname': { '7777.7777.7777': { 'hostname': 'R7', 'level': 2, }, '2222.2222.2222':{ 'hostname': 'R2', 'local_router': True, } } } }, 'test':{ 'hostname_db': { 'hostname': { '9999.9999.9999': { 'hostname': 'R9', 'level': 2, }, '8888.8888.8888': { 'hostname': 'R8', 'level': 2, }, '7777.7777.7777': { 'hostname': 'R7', 'level': 2, }, '5555.5555.5555': { 'hostname': 'R5', 'level': 2, }, '3333.3333.3333': { 'hostname': 'R3', 'level': 2, }, '1111.1111.1111': { 'hostname': 'R1', 'level': 1, }, '2222.2222.2222': { 'hostname': 'R2', 'local_router': True, }, }, }, } } } golden_output = {'execute.return_value': '''\ R2#show isis hostname Level System ID Dynamic Hostname (VRF1) 2 7777.7777.7777 R7 * 2222.2222.2222 R2 Level System ID Dynamic Hostname (test) 2 9999.9999.9999 R9 2 8888.8888.8888 R8 2 7777.7777.7777 R7 2 5555.5555.5555 R5 2 3333.3333.3333 R3 1 1111.1111.1111 R1 * 2222.2222.2222 R2 ''' } def test_empty(self): self.device = Mock(**self.empty_output) obj = ShowIsisHostname(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIsisHostname(device=self.device) parsed_output = obj.parse() self.assertEqual(parsed_output,self.golden_parsed_output)
class test_show_ipv6_icmp_neighbor_detail(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_output = { 'execute.return_value': ''' n9kv-3# show ipv6 icmp neighbor detail vrf all Flags: + - Adjacencies synced via CFSoE # - Adjacencies Throttled for Glean ICMPv6 Adjacency Table for all VRFs Address Age MAC Address State Interface Phy-Interface 2001:db8:c56d:4::2 00:15:02 fa16.3e82.6320 STALE Eth1/1 Eth1/1 fe80::f816:3eff:fe82:6320 00:18:33 fa16.3e82.6320 STALE Eth1/1 Eth1/1 2001:db8:c8d1:4::2 00:03:30 fa16.3e8b.59c9 STALE Eth1/2 Eth1/2 fe80::f816:3eff:fe8b:59c9 00:14:19 fa16.3e8b.59c9 STALE Eth1/2 Eth1/2 2001:db8:c56d:1::1 00:15:31 fa16.3e19.8682 STALE Eth1/3 Eth1/3 fe80::f816:3eff:fe19:8682 00:15:31 fa16.3e19.8682 STALE Eth1/3 Eth1/3 2001:db8:c8d1:1::1 00:07:58 fa16.3ec7.8140 STALE Eth1/4 Eth1/4 fe80::f816:3eff:fec7:8140 00:02:41 fa16.3ec7.8140 STALE Eth1/4 Eth1/4 ''' } golden_parsed_output = { "interfaces": { "Ethernet1/4": { "neighbors": { "fe80::f816:3eff:fec7:8140": { "neighbor_state": "stale", "age": "00:02:41", "ip": "fe80::f816:3eff:fec7:8140", "link_layer_address": "fa16.3ec7.8140", "physical_interface": "Ethernet1/4" }, "2001:db8:c8d1:1::1": { "neighbor_state": "stale", "age": "00:07:58", "ip": "2001:db8:c8d1:1::1", "link_layer_address": "fa16.3ec7.8140", "physical_interface": "Ethernet1/4" } }, "interface": "Ethernet1/4" }, "Ethernet1/2": { "neighbors": { "2001:db8:c8d1:4::2": { "neighbor_state": "stale", "age": "00:03:30", "ip": "2001:db8:c8d1:4::2", "link_layer_address": "fa16.3e8b.59c9", "physical_interface": "Ethernet1/2" }, "fe80::f816:3eff:fe8b:59c9": { "neighbor_state": "stale", "age": "00:14:19", "ip": "fe80::f816:3eff:fe8b:59c9", "link_layer_address": "fa16.3e8b.59c9", "physical_interface": "Ethernet1/2" } }, "interface": "Ethernet1/2" }, "Ethernet1/1": { "neighbors": { "fe80::f816:3eff:fe82:6320": { "neighbor_state": "stale", "age": "00:18:33", "ip": "fe80::f816:3eff:fe82:6320", "link_layer_address": "fa16.3e82.6320", "physical_interface": "Ethernet1/1" }, "2001:db8:c56d:4::2": { "neighbor_state": "stale", "age": "00:15:02", "ip": "2001:db8:c56d:4::2", "link_layer_address": "fa16.3e82.6320", "physical_interface": "Ethernet1/1" } }, "interface": "Ethernet1/1" }, "Ethernet1/3": { "neighbors": { "2001:db8:c56d:1::1": { "neighbor_state": "stale", "age": "00:15:31", "ip": "2001:db8:c56d:1::1", "link_layer_address": "fa16.3e19.8682", "physical_interface": "Ethernet1/3" }, "fe80::f816:3eff:fe19:8682": { "neighbor_state": "stale", "age": "00:15:31", "ip": "fe80::f816:3eff:fe19:8682", "link_layer_address": "fa16.3e19.8682", "physical_interface": "Ethernet1/3" } }, "interface": "Ethernet1/3" } } } golden_parsed_output1 = { 'interfaces': { 'Ethernet1/1.390': { 'interface': 'Ethernet1/1.390', 'neighbors': { 'fe80::f816:3eff:fe59:8f2e': { 'ip': 'fe80::f816:3eff:fe59:8f2e', 'link_layer_address': 'fa16.3e59.8f2e', 'neighbor_state': 'stale', 'age': '00:00:49', 'physical_interface': 'Ethernet1/1.390', }, }, }, }, } golden_output1 = { 'execute.return_value': ''' R3_nx# show ipv6 icmp neighbor Eth1/1.390 detail vrf VRF1 Flags: + - Adjacencies synced via CFSoE # - Adjacencies Throttled for Glean ICMPv6 Adjacency Table for VRF VRF1 Address Age MAC Address State Interface Phy-Interface fe80::f816:3eff:fe59:8f2e 00:00:49 fa16.3e59.8f2e STALE Eth1/1.390 Eth1/1.390 ''' } def test_show_ipv6_icmp_neighbor_detail_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) obj = ShowIpv6IcmpNeighborDetail(device=self.device) parsed_output = obj.parse(vrf="all") self.assertEqual(parsed_output, self.golden_parsed_output) def test_show_nve_empty(self): self.device = Mock(**self.empty_output) obj = ShowIpv6IcmpNeighborDetail(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse() def test_golden1(self): self.maxDiff = None self.device = Mock(**self.golden_output1) obj = ShowIpv6IcmpNeighborDetail(device=self.device) parsed_output = obj.parse(vrf="VRF1", interface='Eth1/1.390') self.assertEqual(parsed_output, self.golden_parsed_output1)
class test_show_isis_database_detail(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { 'tag':{ 'VRF1':{ 'level':{ 1: { 'R2.00-00':{ 'lsp_sequence_num': '0x00000007', 'lsp_checksum': '0x8A6D', 'local_router': True, 'lsp_holdtime': '403', 'lsp_rcvd': '*', 'attach_bit': 1, 'p_bit': 0, 'overload_bit': 0, 'area_address': '49.0001', 'nlpid': '0xCC 0x8E', 'topology': { 'ipv4': { 'code':'0x0', }, 'ipv6': { 'code': '0x4002 ATT' } }, 'hostname': 'R2', 'ip_address': '10.84.66.66', '10.229.7.0/24': { 'ip': { 'metric': 10, }, }, '10.84.66.66/32':{ 'ip': { 'metric': 10, }, }, 'ipv6_address': '2001:DB8:66:66:66::66', '2001:DB8:20:2::/64': { 'ipv6': { 'metric': 10, 'mt_ipv6': True }, }, '2001:DB8:66:66:66::66/128': { 'ipv6':{ 'metric': 10, 'mt_ipv6': True }, }, }, }, 2: { 'R2.00-00': { 'lsp_sequence_num': '0x00000008', 'lsp_checksum': '0x621E', 'local_router': True, 'lsp_holdtime': '1158', 'lsp_rcvd': '*', 'attach_bit': 0, 'p_bit': 0, 'overload_bit': 0, 'area_address': '49.0001', 'nlpid': '0xCC 0x8E', 'topology': { 'ipv4': { 'code': '0x0', }, 'ipv6': { 'code': '0x2' } }, 'hostname': 'R2', 'R2.01': { 'is-extended': { 'metric': 10, }, 'is': { 'metric': 10, 'mt_ipv6': True, }, }, 'ip_address': '10.84.66.66', '10.229.7.0/24': { 'ip': { 'metric': 10, }, }, '10.84.66.66/32': { 'ip':{ 'metric': 10, }, }, 'ipv6_address': '2001:DB8:66:66:66::66', '2001:DB8:20:2::/64': { 'ipv6': { 'metric': 10, 'mt_ipv6': True }, }, '2001:DB8:66:66:66::66/128': { 'ipv6': { 'metric': 10, 'mt_ipv6': True } }, }, 'R2.01-00': { 'lsp_sequence_num': '0x00000002', 'lsp_checksum': '0x3334', 'local_router': True, 'lsp_holdtime': '414', 'lsp_rcvd': '*', 'attach_bit': 0, 'p_bit': 0, 'overload_bit': 0, 'R2.00': { 'is-extended': { 'metric': 0, }, }, 'R7.00': { 'is-extended': { 'metric': 0, }, }, }, 'R7.00-00': { 'lsp_sequence_num': '0x00000005', 'lsp_checksum': '0x056E', 'lsp_holdtime': '735', 'lsp_rcvd': '1199', 'attach_bit': 0, 'p_bit': 0, 'overload_bit': 0, 'area_address': '49.0002', 'nlpid': '0xCC 0x8E', 'router_id': '10.1.77.77', 'ip_address': '10.1.77.77', 'topology': { 'ipv4': { 'code': '0x0', }, 'ipv6': { 'code': '0x2' } }, 'hostname': 'R7', 'R2.01': { 'is-extended': { 'metric': 40, }, 'is': { 'metric': 40, 'mt_ipv6': True, }, }, '10.1.77.77/32':{ 'ip': { 'metric': 1 } }, '10.229.7.0/24': { 'ip': { 'metric': 40 } }, '2001:DB8:77:77:77::77/128': { 'ipv6': { 'metric': 1, 'mt_ipv6': True } }, '2001:DB8:20:2::/64': { 'ipv6': { 'metric': 40, 'mt_ipv6': True } }, }, } } } } } golden_output = {'execute.return_value': '''\ R2#show isis database detail Tag VRF1: IS-IS Level-1 Link State Database: LSPID LSP Seq Num LSP Checksum LSP Holdtime/Rcvd ATT/P/OL R2.00-00 * 0x00000007 0x8A6D 403/* 1/0/0 Area Address: 49.0001 NLPID: 0xCC 0x8E Topology: IPv4 (0x0) IPv6 (0x4002 ATT) Hostname: R2 IP Address: 10.84.66.66 Metric: 10 IP 10.229.7.0/24 Metric: 10 IP 10.84.66.66/32 IPv6 Address: 2001:DB8:66:66:66::66 Metric: 10 IPv6 (MT-IPv6) 2001:DB8:20:2::/64 Metric: 10 IPv6 (MT-IPv6) 2001:DB8:66:66:66::66/128 IS-IS Level-2 Link State Database: LSPID LSP Seq Num LSP Checksum LSP Holdtime/Rcvd ATT/P/OL R2.00-00 * 0x00000008 0x621E 1158/* 0/0/0 Area Address: 49.0001 NLPID: 0xCC 0x8E Topology: IPv4 (0x0) IPv6 (0x2) Hostname: R2 Metric: 10 IS-Extended R2.01 Metric: 10 IS (MT-IPv6) R2.01 IP Address: 10.84.66.66 Metric: 10 IP 10.229.7.0/24 Metric: 10 IP 10.84.66.66/32 IPv6 Address: 2001:DB8:66:66:66::66 Metric: 10 IPv6 (MT-IPv6) 2001:DB8:20:2::/64 Metric: 10 IPv6 (MT-IPv6) 2001:DB8:66:66:66::66/128 R2.01-00 * 0x00000002 0x3334 414/* 0/0/0 Metric: 0 IS-Extended R2.00 Metric: 0 IS-Extended R7.00 R7.00-00 0x00000005 0x056E 735/1199 0/0/0 Area Address: 49.0002 NLPID: 0xCC 0x8E Router ID: 10.1.77.77 IP Address: 10.1.77.77 Topology: IPv6 (0x2) IPv4 (0x0) Hostname: R7 Metric: 40 IS (MT-IPv6) R2.01 Metric: 40 IS-Extended R2.01 Metric: 1 IP 10.1.77.77/32 Metric: 40 IP 10.229.7.0/24 Metric: 1 IPv6 (MT-IPv6) 2001:DB8:77:77:77::77/128 Metric: 40 IPv6 (MT-IPv6) 2001:DB8:20:2::/64 ''' } def test_empty(self): self.device = Mock(**self.empty_output) platform_obj = ShowIsisDatabaseDetail(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = platform_obj.parse() def test_golden(self): self.maxDiff = None self.device = Mock(**self.golden_output) platform_obj = ShowIsisDatabaseDetail(device=self.device) parsed_output = platform_obj.parse() self.assertEqual(parsed_output, self.golden_parsed_output)
class test_show_ip_route_ios(unittest.TestCase): """ unit test for show ip route """ device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output_with_route = { "vrf": { "default": { "address_family": { "ipv4": { "routes": { "": { "active": True, "distance": 90, "mask": "24", "metric": 3072, "next_hop": { "next_hop_list": { 1: { "age": "3d04h", "from": "192.168.9.2", "hops": "1", "index": 1, "loading": "1/255", "metric": "3072", "minimum_bandwidth": "1000000", "minimum_mtu": "1500", "next_hop": "192.168.9.2", "outgoing_interface": "GigabitEthernet0/2.4", "reliability": "255/255", "share_count": "1", "total_delay": "20" } } }, "redist_via": "eigrp", "redist_via_tag": "1", "route": "192.168.234.0", "type": "internal", "update": { "age": "3d04h", "from": "192.168.9.2", "interface": "GigabitEthernet0/2.4" } } } } } } } } golden_output_with_route = { 'execute.return_value': ''' show ip route 192.168.234.0 Routing entry for 192.168.234.0/24 Known via "eigrp 1", distance 90, metric 3072, type internal Redistributing via eigrp 1 Last update from 192.168.9.2 on GigabitEthernet0/2.4, 3d04h ago Routing Descriptor Blocks: * 192.168.9.2, from 192.168.9.2, 3d04h ago, via GigabitEthernet0/2.4 Route metric is 3072, traffic share count is 1 Total delay is 20 microseconds, minimum bandwidth is 1000000 Kbit Reliability 255/255, minimum MTU 1500 bytes Loading 1/255, Hops 1 ''' } def test_empty_1(self): self.device = Mock(**self.empty_output) obj = ShowIpRoute(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = obj.parse(route='192.168.234.0') def test_show_ip_route_with_route(self): self.maxDiff = None self.device = Mock(**self.golden_output_with_route) obj = ShowIpRoute(device=self.device) parsed_output = obj.parse(route='192.168.234.0') self.assertEqual(parsed_output, self.golden_parsed_output_with_route)
class test_show_ipv6_interface(unittest.TestCase): device = Device(name='aDevice') empty_output = {'execute.return_value': ''} golden_parsed_output = { "GigabitEthernet0/1.1": { "mtu": 1500, "joined_group_addresses": [ "FF02::1", "FF02::1:FF01:1", "FF02::1:FF05:2", "FF02::1:FF4B:55FD", "FF02::2", "FF02::5", "FF02::6" ], "enabled": True, "addresses_config_method": "stateless autoconfig", "ipv6": { "enabled": True, "201::1:1/112": { "status": "valid", "ip": "201::1:1", "prefix_length": "112" }, "FE80::F816:3EFF:FE4B:55FD": { "status": "valid", "ip": "FE80::F816:3EFF:FE4B:55FD", "origin": "link_layer" }, "201::5:2/112": { "status": "valid", "ip": "201::5:2", "prefix_length": "112" }, "nd": { "dad_enabled": True, "advertised_default_router_preference": "Medium", "advertised_retransmit_interval": 0, "router_advertisements_interval": 200, "advertised_retransmit_interval_unspecified": True, "router_advertisements_live": 1800, "using_time": 30000, "dad_attempts": 1, "advertised_reachable_time_unspecified": True, "reachable_time": 30000, "advertised_reachable_time": 0 }, "icmp": { "redirects": True, "error_messages_limited": 100, "unreachables": "sent" } }, "oper_status": "up" }, "Loopback0": { "mtu": 1514, "joined_group_addresses": [ "FF02::1", "FF02::1:FF00:0", "FF02::1:FF01:1", "FF02::2", "FF02::5" ], "enabled": True, "addresses_config_method": "stateless autoconfig", "ipv6": { "100:1::1:1/112": { "status": "valid", "ip": "100:1::1:1", "prefix_length": "112" }, "enabled": True, "nd": { "advertised_default_router_preference": "Medium", "advertised_retransmit_interval": 0, "advertised_retransmit_interval_unspecified": True, "router_advertisements_live": 1800, "reachable_time": 30000, "using_time": 30000, "advertised_reachable_time": 0, "advertised_reachable_time_unspecified": True }, "FE80::5C00:C0FF:FE00:0": { "status": "valid", "ip": "FE80::5C00:C0FF:FE00:0", "origin": "link_layer" }, "icmp": { "redirects": True, "error_messages_limited": 100, "unreachables": "sent" } }, "oper_status": "up" } } golden_output = { 'execute.return_value': ''' GigabitEthernet0/1.1 is up, line protocol is up IPv6 is enabled, link-local address is FE80::F816:3EFF:FE4B:55FD No Virtual link-local address(es): Global unicast address(es): 201::1:1, subnet is 201::1:0/112 201::5:2, subnet is 201::5:0/112 Joined group address(es): FF02::1 FF02::2 FF02::5 FF02::6 FF02::1:FF01:1 FF02::1:FF05:2 FF02::1:FF4B:55FD MTU is 1500 bytes ICMP error messages limited to one every 100 milliseconds ICMP redirects are enabled ICMP unreachables are sent ND DAD is enabled, number of DAD attempts: 1 ND reachable time is 30000 milliseconds (using 30000) ND advertised reachable time is 0 (unspecified) ND advertised retransmit interval is 0 (unspecified) ND router advertisements are sent every 200 seconds ND router advertisements live for 1800 seconds ND advertised default router preference is Medium Hosts use stateless autoconfig for addresses. Loopback0 is up, line protocol is up IPv6 is enabled, link-local address is FE80::5C00:C0FF:FE00:0 No Virtual link-local address(es): Global unicast address(es): 100:1::1:1, subnet is 100:1::1:0/112 Joined group address(es): FF02::1 FF02::2 FF02::5 FF02::1:FF00:0 FF02::1:FF01:1 MTU is 1514 bytes ICMP error messages limited to one every 100 milliseconds ICMP redirects are enabled ICMP unreachables are sent ND DAD is not supported ND reachable time is 30000 milliseconds (using 30000) ND advertised reachable time is 0 (unspecified) ND advertised retransmit interval is 0 (unspecified) ND router advertisements live for 1800 seconds ND advertised default router preference is Medium ND RAs are suppressed (periodic) Hosts use stateless autoconfig for addresses. ''' } def test_empty(self): self.device = Mock(**self.empty_output) interface_obj = ShowIpv6Interface(device=self.device) with self.assertRaises(SchemaEmptyParserError): parsed_output = interface_obj.parse() def test_golden(self): self.device = Mock(**self.golden_output) interface_obj = ShowIpv6Interface(device=self.device) parsed_output = interface_obj.parse() self.maxDiff = None self.assertEqual(parsed_output, self.golden_parsed_output)