def test_SpirentParsedInterfaceName(self): d_parsed = SpirentParsedInterfaceName(' 11/22 ') self.assertEqual(d_parsed.slot, '11') self.assertEqual(d_parsed.port, '22') self.assertEqual(d_parsed.subintf_sep, None) self.assertEqual(d_parsed.subintf, None) self.assertEqual(d_parsed.reconstruct(), '11/22') d_parsed = SpirentParsedInterfaceName(' 11/22.33 ') self.assertEqual(d_parsed.slot, '11') self.assertEqual(d_parsed.port, '22') self.assertEqual(d_parsed.subintf_sep, '.') self.assertEqual(d_parsed.subintf, '33') self.assertEqual(d_parsed.reconstruct(), '11/22.33') Genie.testbed = Testbed() dev1 = Device(name='TGEN', os='spirent') intf1 = Interface(device=dev1, name='11/22') d_parsed = intf1.parse_interface_name() self.assertEqual(d_parsed.number, '11/22') self.assertEqual(d_parsed.slot, '11') self.assertEqual(d_parsed.port, '22') self.assertEqual(d_parsed.subintf_sep, None) self.assertEqual(d_parsed.subintf, None) self.assertEqual(d_parsed.reconstruct(), intf1.name)
def test_nve_interface_simple(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='BL1', testbed=testbed, os='nxos') intf1 = Interface(name='nve1', device=dev1) # Apply configuration intf1.enabled = False # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join(['interface nve1', ' shutdown', ' exit'])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'enabled': { False: None }}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join(['interface nve1', ' no shutdown', ' exit']))
def test_SubInterface(self): Genie.testbed = Testbed() dev1 = Device(name='TGEN', os='spirent') intf1 = Interface(device=dev1, name='11/22') intf2 = Interface(device=dev1, name='11/33') sub1 = intf1.generate_sub_interface() self.assertEqual(sub1.name, '{}.0'.format(intf1.name)) self.assertIsInstance(sub1, spirentSubInterface) self.assertNotIsInstance(sub1, spirentPhysicalInterface) self.assertNotIsInstance(sub1, EmulatedInterface) d_parsed = sub1.parse_interface_name() self.assertEqual(d_parsed.number, '11/22') self.assertEqual(d_parsed.slot, '11') self.assertEqual(d_parsed.port, '22') self.assertEqual(d_parsed.subintf_sep, '.') self.assertEqual(d_parsed.subintf, '0') self.assertEqual(d_parsed.reconstruct(), sub1.name) self.assertIs(sub1.parent_interface, intf1) self.assertEqual(sub1.build_config(), '') self.assertEqual(sub1.build_unconfig(), '')
def test_vlan_interface_configuration(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1) intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2) intf3 = Interface(name='GigabitEthernet0/0/3', device=dev1) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() link.add_feature(vlan) vlan.device_attr[dev1] vlan.device_attr[dev2] vlan.device_attr[dev1].interface_attr[intf1] vlan.device_attr[dev1].interface_attr[intf1].eth_encap_type1 = 'dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val1 = 2 vlan.device_attr[dev1].interface_attr[ intf1].eth_encap_type2 = 'second-dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val2 = 5 cfg1 = vlan.build_config(apply=False) self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(cfg1['PE1']), '\n'.join([ 'interface GigabitEthernet0/0/1', ' encapsulation dot1q 2 second-dot1q 5', ' exit', ]))
def test_init(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') intf1 = Interface(name='GigabitEthernet0/0/1',device=dev1) intf2 = Interface(name='GigabitEthernet0/0/2',device=dev2) intf3 = Interface(name='Vlan100',device=dev1) link = Link(name='1_2_1',testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) self.assertSetEqual( set(link.find_interfaces()), set([intf1, intf2])) self.assertSetEqual( set(dev1.find_interfaces()), set([intf1, intf3])) self.assertSetEqual( set(dev2.find_interfaces()), set([intf2])) vlan = Vlan() self.assertSetEqual(set(vlan.devices), set([])) self.assertSetEqual(set(vlan.links), set([])) link.add_feature(vlan) self.assertCountEqual(vlan.devices, [dev1, dev2]) self.assertSetEqual(set(vlan.links), set([link])) self.assertSetEqual(set(vlan.interfaces), set([intf1, intf2])) with self.assertRaises(AttributeError): vlan.access_map_id with self.assertRaises(AttributeError): vlan.vlan_configuration_id
def test_cfg_as(self): ''' Test 4-byte AS support''' Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24', ipv6='2001::1') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') with self.assertNoWarnings(): Genie.testbed = testbed bgp = Bgp(bgp_id='304.304') self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(bgp_id='304.304') self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.maxDiff = None self.assertEqual(str(cfgs[dev1.name]), '\n'.join( ['router bgp 304.304', ' exit', ]))
def test_uncfg_as(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') with self.assertNoWarnings(): Genie.testbed = testbed bgp = Bgp(bgp_id='304.304') self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(bgp_id='304.304') self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no router bgp 304.304', ]))
def test_native_vlans(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='BL1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet2/22', device=dev1, description='Native vlan testing', enabled=True, switchport_mode='trunk', trunk_vlans='101-120,131-140,151-170,200-209', native_vlan='1', switchport_enable=True) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet2/22', ' description Native vlan testing', ' no shutdown', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan 101-120,131-140,151-170,200-209', ' switchport trunk native vlan 1', ' exit' ]))
def setUp(self): pass testbed = Genie.testbed = Testbed() self.dev1 = Device(testbed=testbed, name='PE1', os='iosxe') self.dev2 = Device(testbed=testbed, name='PE2', os='iosxe') self.intf1 = Interface(name='GigabitEthernet0/0/1', device=self.dev1) self.intf2 = Interface(name='GigabitEthernet0/0/2', device=self.dev2) self.link = Link(name='1_2_1', testbed=testbed) self.link.connect_interface(interface=self.intf1) self.link.connect_interface(interface=self.intf2) self.assertSetEqual(set(self.link.find_interfaces()), set([self.intf1, self.intf2])) self.assertSetEqual(set(self.dev1.find_interfaces()), set([self.intf1])) self.assertSetEqual(set(self.dev2.find_interfaces()), set([self.intf2])) isis = Isis("core") self.assertSetEqual(set(isis.devices), set([])) self.assertSetEqual(set(isis.links), set([])) self.link.add_feature(isis) for intf_iter in self.link.interfaces: intf_iter.add_feature(isis) self.assertCountEqual(isis.devices, [self.dev1, self.dev2]) self.assertSetEqual(set(isis.links), set([self.link])) self.assertSetEqual(set(isis.interfaces), set([self.intf1, self.intf2]))
def test_basic_cfg(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe', context='yang') dev2 = Device(testbed=testbed, name='PE2', os='iosxe', context='yang') intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1) intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2) intf3 = Interface(name='Vlan100', device=dev1) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() for dev in testbed.devices: dev.connections = Mock() dev.connections = {'netconf': NetconfConnectionInfo()} link.add_feature(vlan) vlan.vlan_id = 100 cfg1 = vlan.build_config(apply=False) self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2']) compare = "" for i in cfg1['PE1']: compare += str(i) self.assertMultiLineEqual( compare, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n' ' <id>100</id>\n' ' </vlan-list>\n' ' </vlan>\n' ' </config>\n' '</edit-config>\n' ])) compare = "" for i in cfg1['PE2']: compare += str(i) self.assertMultiLineEqual( compare, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n' ' <id>100</id>\n' ' </vlan-list>\n' ' </vlan>\n' ' </config>\n' '</edit-config>\n' ]))
def test_dot1q_tunnel_interface(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='BL1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet2/22', device=dev1, description='dot1q tunnel testing', enabled=True, switchport_mode='dot1q-tunnel', dot1q_access_vlan='1301', switchport_enable=True) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet2/22', ' description dot1q tunnel testing', ' no shutdown', ' switchport', ' switchport mode dot1q-tunnel', ' switchport access vlan 1301', ' exit' ]))
def test_enabled_switchport_enabled(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') # Defining attributes section intf1.switchport_enable = True intf1.enabled = True # Check config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no shutdown', ' switchport', ' exit', ])) # Check unconfig uncfg = intf1.build_unconfig(apply=False, attributes={ "switchport_enable": True, "enabled": True }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' shutdown', ' no switchport', ' exit', ])) # Defining attributes section intf1.switchport_enable = False intf1.enabled = False # Check config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' shutdown', ' no switchport', ' exit', ])) # Check unconfig uncfg = intf1.build_unconfig(apply=False, attributes={ "switchport_enable": True, "enabled": True }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no shutdown', ' switchport', ' exit', ]))
def test_vlan_interface_configuration(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr', context='yang') dev2 = Device(testbed=testbed, name='PE2', os='iosxr', context='yang') intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1, context='yang') intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2, context='yang') intf3 = Interface(name='GigabitEthernet0/0/3', device=dev1, context='yang') link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() for dev in testbed.devices: dev.connections = Mock() dev.connections = {'netconf': NetconfConnectionInfo()} link.add_feature(vlan) vlan.device_attr[dev1] vlan.device_attr[dev2] vlan.device_attr[dev1].interface_attr[intf1] vlan.device_attr[dev1].interface_attr[intf1].eth_encap_type1 = 'dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val1 = 2 vlan.device_attr[dev1].interface_attr[ intf1].eth_encap_type2 = 'second-dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val2 = 5
def test_switchport_enable_config(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1, aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # make intf2 as L2 interface intf1.switchport_enable = True # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join(['interface Ethernet3/7', ' switchport', ' exit'])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ]))
def test_ipv4_multiple_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' ipv4a = IPv4Addr(device=dev1) ipv4a.ipv4 = IPv4Address('192.168.1.1') ipv4a.prefix_length = '24' intf1.add_ipv4addr(ipv4a) ipv4b = IPv4Addr(device=dev1) ipv4b.ipv4 = IPv4Address('192.168.1.2') ipv4b.prefix_length = '24' ipv4b.ipv4_secondary = True intf1.add_ipv4addr(ipv4b) intf1.enabled = True # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' ipv4 address 192.168.1.1/24', ' ipv4 address 192.168.1.2/24 secondary', ' description multiple lines config', ' no shutdown', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'ipv4addr':None, 'enabled': True, 'description': True}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' no ipv4 address 192.168.1.1/24', ' no ipv4 address 192.168.1.2/24 secondary', ' no description', ' shutdown', ' exit' ]))
def test_init(self): self.assertTrue(issubclass(ixiaInterface, Interface)) self.assertTrue(issubclass(ixiaInterface, hltapiInterface)) self.assertTrue(issubclass(ixiaInterface, tgenInterface)) self.assertTrue(issubclass(ixiaPhysicalInterface, ixiaInterface)) self.assertTrue( issubclass(ixiaPhysicalInterface, hltapiPhysicalInterface)) self.assertTrue( issubclass(ixiaPhysicalInterface, tgenPhysicalInterface)) self.assertFalse(issubclass(ixiaPhysicalInterface, EmulatedInterface)) self.assertFalse(issubclass(ixiaPhysicalInterface, VirtualInterface)) self.assertTrue(issubclass(ixiaEmulatedInterface, ixiaInterface)) self.assertTrue( issubclass(ixiaEmulatedInterface, hltapiEmulatedInterface)) self.assertTrue( issubclass(ixiaEmulatedInterface, tgenEmulatedInterface)) self.assertFalse( issubclass(ixiaEmulatedInterface, ixiaPhysicalInterface)) self.assertFalse( issubclass(ixiaEmulatedInterface, hltapiPhysicalInterface)) self.assertFalse( issubclass(ixiaEmulatedInterface, tgenPhysicalInterface)) self.assertFalse(issubclass(ixiaEmulatedInterface, VirtualInterface)) self.assertTrue(issubclass(ixiaVirtualInterface, ixiaInterface)) self.assertTrue( issubclass(ixiaVirtualInterface, hltapiVirtualInterface)) self.assertTrue(issubclass(ixiaVirtualInterface, tgenVirtualInterface)) self.assertFalse( issubclass(ixiaVirtualInterface, ixiaPhysicalInterface)) self.assertFalse( issubclass(ixiaVirtualInterface, hltapiPhysicalInterface)) self.assertFalse( issubclass(ixiaVirtualInterface, tgenPhysicalInterface)) self.assertFalse(issubclass(ixiaVirtualInterface, EmulatedInterface)) self.assertTrue(issubclass(ixiaSubInterface, ixiaInterface)) self.assertTrue(issubclass(ixiaSubInterface, ixiaVirtualInterface)) self.assertTrue(issubclass(ixiaSubInterface, hltapiSubInterface)) self.assertTrue(issubclass(ixiaSubInterface, tgenSubInterface)) self.assertFalse(issubclass(ixiaSubInterface, ixiaPhysicalInterface)) self.assertFalse(issubclass(ixiaSubInterface, hltapiPhysicalInterface)) self.assertFalse(issubclass(ixiaSubInterface, tgenPhysicalInterface)) self.assertFalse(issubclass(ixiaSubInterface, EmulatedInterface)) Genie.testbed = Testbed() dev1 = Device(name='TGEN', os='ixia') intf1 = Interface(device=dev1, name='11/22') intf2 = Interface(device=dev1, name='11/33') self.assertIsInstance(intf1, ixiaPhysicalInterface) self.assertNotIsInstance(intf1, EmulatedInterface) self.assertNotIsInstance(intf1, VirtualInterface) self.assertNotIsInstance(intf1, SubInterface)
def _write_connections_to_testbed(self, connection_dict, testbed): '''Writes the connections found in the connection_dict into the testbed Args: connection_dict ('dict'): Dictionary with connections found earlier testbed ('testbed'): testbed to write connections into ''' # filter to strip out the numbers from an interface to create a type name # example: ethernet0/3 becomes ethernet interface_filter = re.compile(r'[a-zA-Z]+') log.debug('Adding connections to testbed') for device in connection_dict: log.debug(' Writing connections found in {}'.format(device)) for interface_name in connection_dict[device]: #if connecting interface is not in the testbed, create the interface if interface_name not in testbed.devices[device].interfaces: type_name = interface_filter.match(interface_name) interface = Interface(interface_name, type=type_name[0].lower()) interface.device = testbed.devices[device] else: # get the interface found in the connection on the device searched interface = testbed.devices[device].interfaces[ interface_name] # if the interface is not already part of a link get a list of # all interfaces involved in the link and create a new link # object with the associated interfaces if interface.link is None: int_list = [interface] for entry in connection_dict[device][interface_name]: dev = entry['dest_host'] dest_int = entry['dest_port'] if testbed.devices[dev].interfaces[ dest_int] not in int_list: int_list.append( testbed.devices[dev].interfaces[dest_int]) if len(int_list) > 1: link = Link( 'Link_{num}'.format(num=len(testbed.links)), interfaces=int_list) # if the interface is already part of the link go over the # other interfaces found in the connection_dict and add them to the link # if they are not already there else: link = interface.link for entry in connection_dict[device][interface_name]: dev = entry['dest_host'] dest_int = entry['dest_port'] if testbed.devices[dev].interfaces[ dest_int] not in link.interfaces: link.connect_interface( testbed.devices[dev].interfaces[dest_int])
def setUp(self): testbed = Genie.testbed = Testbed() self.dev1 = Device(testbed=testbed, name='PE1', os='iosxr') self.dev2 = Device(testbed=testbed, name='PE2', os='iosxr') self.intf1 = Interface(name='GigabitEthernet0/0/0/1', device=self.dev1) self.intf2 = Interface(name='GigabitEthernet0/0/0/2', device=self.dev2) self.link = Link(name='1_2_1', testbed=testbed) self.link.connect_interface(interface=self.intf1) self.link.connect_interface(interface=self.intf2)
def test_uncfg_interface(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1) intf2 = Interface(name='Vlan100', device=dev1) # vrf = Vrf(name='test', testbed=testbed) # dev1.add_feature(vrf) # make intf2 as L2 interface intf2.mtu = 500 intf1.mtu = 500 # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' mtu 500', ' exit' ])) cfgs = intf2.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Vlan100', ' mtu 500', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ])) uncfgs = intf2.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'no interface Vlan100', ]))
def test_basic_cfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') rpl1 = RoutePolicy(policy_definition='rpl1', route_disposition='permit') dev1.add_feature(rpl1) rpl1.device_attr[dev1].statement_attr['10'] rpl1.device_attr[dev1].statement_attr['10'].match_med_eq = 5 cfgs = rpl1.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join(['route-map rpl1 permit 10', ' match metric 5', ' exit'])) # import pdb; pdb.set_trace() rpl2 = RoutePolicy(policy_definition='rpl2', route_disposition='deny') dev2.add_feature(rpl2) rpl2.device_attr[dev2].statement_attr['20'] rpl2.device_attr[dev2].statement_attr['20'].set_metric_type = \ 'internal' rpl2.device_attr[dev2].statement_attr['20'].set_ext_community_rt = \ ['100:100','200:200'] rpl2.device_attr[dev2].statement_attr['20'].\ set_ext_community_rt_additive = True cfgs = rpl2.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev2.name]) self.assertMultiLineEqual( str(cfgs[dev2.name]), '\n'.join([ "route-map rpl2 deny 20", " set extcommunity rt ['100:100', '200:200'] additive", " set metric-type internal", " exit" ]))
def test_ipv6_multiple_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' intf1.enabled = False ipv6a = IPv6Addr(device=dev1) ipv6a.ipv6 = IPv6Address('2001:db1:1::1') ipv6a.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6a) ipv6b = IPv6Addr(device=dev1) ipv6b.ipv6 = IPv6Address('2001:db1:2::2') ipv6b.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6b) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64', ' description multiple lines config', ' shutdown', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'ipv6addr':None}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' no ipv6 address 2001:db1:1::1/64', ' no ipv6 address 2001:db1:2::2/64', ' exit' ]))
def test_NveInterface_L3vni(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(name='nve1', device=dev1) # Defining attributes section intf1.nve_bgp_host_reachability = True intf1.nve_src_intf_loopback = 'Loopback0' intf1.nve_vni = '30000' intf1.nve_vni_vrf = 'red' # Build config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface nve1', ' host-reachability protocol bgp', ' source-interface Loopback0', ' member vni 30000 vrf red', ' exit' ])) # Build unconfig uncfg = intf1.build_unconfig(apply=False, attributes={'nve_vni': '20000'}) # Check config build correctly self.assertMultiLineEqual( str(uncfg), '\n'.join(['interface nve1', ' no member vni 30000', ' exit']))
def test_VlanInterface(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(name='Vlan100', device=dev1) # Defining attributes section intf1.mtu = 500 intf1.ipv4 = '201.0.12.1' intf1.ipv4.netmask = '255.255.255.0' intf1.ipv6 = '2001::12:1' cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Vlan100', ' ip address 201.0.12.1 255.255.255.0', ' ipv6 address 2001::12:1/128', ' mtu 500', ' exit', ])) uncfg = intf1.build_unconfig(apply=False) self.assertMultiLineEqual(str(uncfg), '\n'.join([ 'no interface Vlan100', ])) partial_uncfg = intf1.build_unconfig(apply=False, attributes="mtu") self.assertMultiLineEqual( str(partial_uncfg), '\n'.join([ 'interface Vlan100', ' no mtu 500', ' exit', ]))
def setUp(self): tb = Genie.testbed = Testbed() self.dev1 = Device(testbed=tb, name='PE1', os='iosxe') self.dev2 = Device(testbed=tb, name='PE2', os='iosxe') self.i1 = Interface(name='GigabitEthernet0/0/1', device=self.dev1) self.i2 = Interface(name='GigabitEthernet0/0/2', device=self.dev2) self.i3 = Interface(name='GigabitEthernet0/0/3', device=self.dev1) self.i4 = Interface(name='GigabitEthernet0/0/4', device=self.dev2) self.i5 = Interface(name='GigabitEthernet0/0/5', device=self.dev1) self.i6 = Interface(name='GigabitEthernet0/0/6', device=self.dev2) self.i7 = Interface(name='GigabitEthernet0/0/7', device=self.dev1) self.i8 = Interface(name='GigabitEthernet0/0/8', device=self.dev2) self.link = Link(name='1_2_1') self.link.connect_interface(interface=self.i1) self.link.connect_interface(interface=self.i2) self.link2 = Link(name='1_2_2') self.link2.connect_interface(interface=self.i3) self.link2.connect_interface(interface=self.i4) self.link3 = Link(name='1_2_3') self.link3.connect_interface(interface=self.i5) self.link3.connect_interface(interface=self.i6) self.link4 = Link(name='1_2_4') self.link4.connect_interface(interface=self.i7) self.link4.connect_interface(interface=self.i8) self.assertCountEqual(self.link.find_interfaces(), [self.i1, self.i2]) self.assertCountEqual(self.dev1.find_interfaces(), [self.i1, self.i3, self.i5, self.i7]) self.assertCountEqual(self.dev2.find_interfaces(), [self.i2, self.i4, self.i6, self.i8])
def test_init(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') with self.assertNoWarnings(): Genie.testbed = None with self.assertRaises(TypeError): evpn = Evpn() evpn = Evpn(testbed=testbed) self.assertIs(evpn.testbed, testbed) Genie.testbed = testbed evpn = Evpn() self.assertIs(evpn.testbed, Genie.testbed) self.assertIs(evpn.testbed, testbed) self.assertIsNone(getattr(dev1, 'evpn', None)) self.assertIsNone(getattr(intf1, 'evpn', None)) intf1.add_feature(evpn) self.assertIs(intf1.evpn, evpn) # TODO self.assertIs(dev1.evpn, evpn) self.assertIsNone(getattr(dev1, 'evpn', None)) dev1.add_feature(evpn) self.assertIs(dev1.evpn, evpn)
def test_vxlan_interface(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1) # Defining attributes section intf1.evpn_multisite_fabric_tracking = True intf1.evpn_multisite_dci_tracking = True intf1.ip_forward = True cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Ethernet0/0/1', ' evpn multisite dci-tracking', ' evpn multisite fabric-tracking', ' ip forward', ' exit', ])) partial_uncfg = intf1.build_unconfig( apply=False, attributes={ "evpn_multisite_fabric_tracking": True, "evpn_multisite_dci_tracking": True, "ip_forward": True }) self.assertMultiLineEqual( str(partial_uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no evpn multisite dci-tracking', ' no evpn multisite fabric-tracking', ' no ip forward', ' exit', ]))
def test_EFPInterface(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') efp = Interface(device=dev1, name='GigabitEthernet0/0/1.20', service_instance=20) efp.eth_encap_val1 = 20 efp.rewrite_ingress = 'pop 1 symmetric' cfg = efp.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' service instance 20 ethernet', ' encapsulation dot1q 20', ' rewrite ingress tag pop 1 symmetric', ' exit', ' exit', ])) uncfg = efp.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no service instance 20 ethernet', ' exit', ]))
def test_EthernetSubInterface(self): """Test subinterface support without usage of service_instance""" Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') sub_intf = Interface(device=dev1, name='GigabitEthernet0/0/1.20') sub_intf.ipv4 = '10.10.0.1/24' sub_intf.eth_encap_type1 = 'dot1q' sub_intf.eth_encap_val1 = 20 cfg = sub_intf.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1.20', ' encapsulation dot1q 20', ' ip address 10.10.0.1 255.255.255.0', ' exit', ])) uncfg = sub_intf.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'no interface GigabitEthernet0/0/1.20', ]))
def test_remove_vrf_af(self): # Add a device to it tb = Genie.testbed = Testbed() dev1 = Device(testbed=tb, name='dev1', os='nxos') dev2 = Device(testbed=tb, name='dev2', os='nxos') vrf1 = Vrf(name='blue') intf1 = Interface(device=dev1, name='Ethernet0/0', vrf=vrf1) rip = Rip(instance_id=5) rip.add_force_vrf(None) dev1.add_feature(rip) dev2.add_feature(rip) intf1.add_feature(rip) # Configure rip rip.device_attr['dev1'].vrf_attr['blue'].address_family_attr['ipv4 unicast'].distance = 5 output = rip.build_config(apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' exit\n' ' vrf blue\n' ' address-family ipv4 unicast\n' ' distance 5\n' ' exit\n' ' exit\n' ' exit', 'dev2': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' exit\n' ' exit'}) output = rip.build_unconfig(\ attributes='device_attr__dev1__vrf_attr__blue__address_family_attr__ipv4 unicast', apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'router rip 5\n' ' vrf blue\n' ' no address-family ipv4 unicast\n' ' exit\n' ' exit'})
def test_lisp_partial_unconfig(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create Interface object intf1 = Interface(name='GigabitEthernet2', device=dev1) # Create LISP object lisp1 = Lisp() # DeviceAttributes # InterfaceAttributes lisp1.device_attr[dev1].intf_attr[ intf1].if_mobility_liveness_test_disabled = True # Add LISP to the device dev1.add_feature(lisp1) # Build config cfgs = lisp1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'interface GigabitEthernet2', ' no lisp mobility liveness test', ' exit', ])) # Unconfig a specific attribute attr_unconfig = lisp1.build_unconfig( apply=False, attributes={ 'device_attr': { dev1.name: { 'intf_attr': { intf1.name: { 'if_mobility_liveness_test_disabled': None }, }, }, } }) # Check unconfig string for attribute is built correctly self.assertMultiLineEqual( str(attr_unconfig[dev1.name]), '\n'.join([ 'interface GigabitEthernet2', ' lisp mobility liveness test', ' exit', ]))