def test_single_line_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']) intf2 = Interface(name='Ethernet3/9', device=dev1, aliases=['PE1_2']) subif1 = Interface(name='Ethernet3/6.10', device=dev1, aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'test' intf1.enabled = False # intf1.shutdown = False intf1.link_up_down_trap_enable = True intf1.mtu = 1492 intf1.vrf = vrf intf1.mac_address = 'aabb.ccdd.eeff' intf1.bandwidth = 8192 intf1.link_status = True intf1.load_interval = 33 intf1.dhcp = True intf1.unnumbered_intf_ref = 'Ethernet3/6.10' intf1.ipv6_autoconf = True intf1.switchport_mode = 'access' intf1.medium = 'p2p' intf1.delay = 11 intf1.access_vlan = '19' intf1.auto_negotiate = False # make intf2 as L2 interface intf1.switchport_enable = True intf2.enabled = True intf2.switchport_enable = True intf2.switchport_mode = 'trunk' intf2.trunk_add_vlans = '1,2,3' # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' medium p2p', ' bandwidth 8192', ' delay 11', ' description test', ' mtu 1492', ' shutdown', ' snmp trap link-status', ' vrf member test', ' logging event port link-status', ' ip address dhcp', ' ip unnumbered Ethernet3/6.10', ' ipv6 address autoconfig', ' switchport', ' switchport mode access', ' load-interval 33', ' mac-address aabb.ccdd.eeff', ' switchport access vlan 19', ' no speed', ' no duplex', ' exit' ])) cfgs = intf2.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/9', ' no shutdown', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan add 1,2,3', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={ 'mtu': True, 'enabled': True }) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join( ['interface Ethernet3/7', ' no mtu', ' no shutdown', ' exit'])) uncfgs = intf2.build_unconfig(apply=False, attributes={'trunk_add_vlans': True}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet3/9', ' switchport trunk allowed vlan remove 1,2,3', ' exit' ]))
def test_all_ethernet(self): testbed = Testbed() Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Defining attributes section intf1.description = 'test desc' intf1.enabled = True intf1.link_up_down_trap_enable = True intf1.mtu = 500 intf1.vrf = vrf intf1.vrf_downstream = 'vrf_downstream_test' intf1.mac_address = 'aaaa.bbbb.cccc' intf1.bandwidth = 768 intf1.link_status = True intf1.load_interval = 30 intf1.encapsulation = 'dot1q' intf1.first_dot1q = '20' intf1.second_dot1q = '30' 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) 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) ipv6b.ipv6_anycast = True intf1.dhcp = True intf1.dhcp_client_id = '10' intf1.dhcp_hostname = 'dhcp-host' intf1.unnumbered_intf_ref = 'GigabitEthernet0/0/2.20' intf1.ipv6_unnumbered_intf_ref = 'GigabitEthernet0/0/3.100' intf1.ipv6_enabled = True intf1.ipv6_autoconf = True intf1.ipv6_autoconf_default = True intf1.medium = "broadcast" intf1.delay = 100 intf1.port_speed = '1000' intf1.auto_negotiate = True intf1.duplex_mode = "full" intf1.flow_control_receive = True intf1.flow_control_send = False # Check config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' encapsulation dot1q 20 second-dot1q 30', ' vrf forwarding test downstream vrf_downstream_test', ' description test desc', ' bandwidth 768', ' mtu 500', ' no shutdown', ' snmp trap link-status', ' logging event link-status', ' load-interval 30', ' ipv6 enable', ' ipv6 address autoconfig default', ' ip unnumbered GigabitEthernet0/0/2.20', ' ipv6 unnumbered GigabitEthernet0/0/3.100', ' speed 1000', ' negotiation auto', ' duplex full', ' flowcontrol receive on', ' flowcontrol send off', ' ip address dhcp client-id 10 hostname dhcp-host', ' medium broadcast', ' delay 100', ' ip address 192.168.1.1 255.255.255.0', ' ip address 192.168.1.2 255.255.255.0 secondary', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64 anycast', ' mac-address aaaa.bbbb.cccc', ' exit', ])) # Check unconfig without attribtues uncfg = intf1.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'default interface GigabitEthernet0/0/1', 'interface GigabitEthernet0/0/1', 'shutdown', ])) # Check ipv4 unconfig uncfg = intf1.build_unconfig(apply=False, attributes="ipv4addr") self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no ip address 192.168.1.1 255.255.255.0', ' no ip address 192.168.1.2 255.255.255.0 secondary', ' exit', ])) # Check encapsulation unconfig uncfg = intf1.build_unconfig(apply=False, attributes={ "encapsulation": None, "first_dot1q": None }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no encapsulation dot1q', ' exit', ]))