Example #1
0
    def test_basic_cfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')
        dev2 = Device(testbed=testbed, name='PE2', os='nxos')
        intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3)
        intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2)
        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.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev2].interface_attr[intf2]
        vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \
            L2_type.TRUNK
        vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.egress_load_balance = True
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True

        intf1.ipv4 = '201.0.12.1'
        intf1.ipv4.netmask = '255.255.255.0'
        intf1.speed = 1000
        intf1.mtu = 500
        intf1.ipv6 = '2001::12:1'

        cfg1 = vlan.build_config(apply=False)
        cfg2 = intf1.build_config(apply=False)
        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])

        self.assertMultiLineEqual(
            str(cfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' exit',
                'vlan access-map ed',
                ' action drop',
                ' exit',
                'vlan configuration 3',
                ' egress port-channel load-balance random',
                ' exit',
                'interface Ethernet0/0/1',
                ' mtu 500',
                ' ip address 201.0.12.1 255.255.255.0',
                ' ipv6 address 2001::12:1/128',
                ' speed 1000',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg1['PE2']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' exit',
                'vlan access-map ed',
                ' exit',
                'vlan configuration 3',
                ' egress port-channel load-balance random',
                ' exit',
                'interface Ethernet0/0/2',
                ' switchport mode trunk',
                ' switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg2),
            '\n'.join([
                'interface Ethernet0/0/1',
                ' mtu 500',
                ' ip address 201.0.12.1 255.255.255.0',
                ' ipv6 address 2001::12:1/128',
                ' speed 1000',
                ' exit',
            ]))
Example #2
0
    def test_basic_cfg(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)
        vlan = Vlan()
        link.add_feature(vlan)
        vlan.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].interface_attr[intf1].switchport_mode = \
            'trunk'
        vlan.device_attr[dev1].interface_attr[intf1].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.accounting_type = 'input'
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True
        vlan.private_vlan_type = 'association'
        vlan.private_vlan_association_action = 'add'
        vlan.private_vlan_association_ids = '201,205'

        cfg1 = vlan.build_config(apply=False)

        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])

        self.assertMultiLineEqual(
            str(cfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' private-vlan association add 201,205',
                ' exit',
                'vlan accounting input',
                'vlan access-map ed',
                ' action drop',
                ' exit',
                'vlan configuration 3',
                ' datalink flow monitor',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' switchport mode trunk',
                ' switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg1['PE2']),
            '\n'.join([
                'vlan 100',
                ' media enet',
                ' no shutdown',
                ' private-vlan association add 201,205',
                ' exit',
                'vlan accounting input',
                'vlan access-map ed',
                ' exit',
                'vlan configuration 3',
                ' datalink flow monitor',
                ' exit',
            ]))
Example #3
0
    def test_basic_uncfg(self):
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='nxos')
        dev2 = Device(testbed=testbed, name='PE2', os='nxos')
        intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3)
        intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2)
        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.vlan_id = 100
        access_map_id = 'ed'
        vlan_configuration_id = '3'

        vlan.device_attr[dev1]
        vlan.device_attr[dev2]
        vlan.device_attr[dev1].access_map_attr[access_map_id]
        vlan.device_attr[dev2].access_map_attr[access_map_id]
        vlan.device_attr[dev1].interface_attr[intf1]
        vlan.device_attr[dev2].interface_attr[intf2]
        vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \
            L2_type.TRUNK
        vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \
            '200-201'
        vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id]
        vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id]

        # Defining attributes section
        vlan.shutdown = False
        with self.assertRaises(ValueError):
            vlan.media = 'invalid'
        vlan.media = 'enet'
        self.assertIs(type(vlan.media), Vlan.Media)
        vlan.egress_port_channel_load_balance_random = True
        vlan.device_attr[dev1].access_map_action = 'drop'
        vlan.datalink_flow_monitor = True

        # Unconfig testing
        # Set a mock
        dev1.cli = Mock()
        dev1.configure = Mock()
        dev2.cli = Mock()
        dev2.configure = Mock()
        dev1.add_feature(vlan)
        dev2.add_feature(vlan)
        # Mock config

        output = vlan.build_config(apply=True)

        uncfg1 = vlan.build_unconfig(apply=False)
        self.assertCountEqual(uncfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(uncfg1['PE1']),
            '\n'.join([
                'no vlan 100',
                'no vlan access-map ed',
                'no vlan configuration 3',
            ]))

        self.assertMultiLineEqual(
            str(uncfg1['PE2']),
            '\n'.join([
                'no vlan 100',
                'no vlan access-map ed',
                'no vlan configuration 3',
                'interface Ethernet0/0/2',
                ' no switchport mode trunk',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        partial_uncfg1 = vlan.build_unconfig(apply=False,
                                             attributes={'device_attr': \
                                                             {'*': "media"}})
        self.assertCountEqual(partial_uncfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_uncfg1['PE1']),
            '\n'.join([
                'vlan 100',
                ' no media enet',
                ' exit',
            ]))

        partial_unconfigure = vlan.build_unconfig(apply=False,
                                                  attributes={'device_attr': \
                                                                  {'*': {'access_map_attr': \
                                                                             {'*': "access_map_action"}}}})
        self.assertCountEqual(partial_unconfigure.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_unconfigure['PE1']),
            '\n'.join([
                'vlan access-map ed',
                ' no action drop',
                ' exit',
            ]))

        all_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                       attributes={ \
                                                           'device_attr': {'*': { \
                                                               'interface_attr': '*'}}})
        self.assertCountEqual(all_vlan_interface_uncfg.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(all_vlan_interface_uncfg['PE2']),
            '\n'.join([
                'interface Ethernet0/0/2',
                ' no switchport mode trunk',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))

        partial_vlan_interface_uncfg = vlan.build_unconfig(apply=False,
                                                           attributes={ \
                                                               'device_attr': {'*': \
                                                                                   {'interface_attr': \
                                                                                        {
                                                                                            '*': "sw_trunk_allowed_vlan"}}}})
        self.assertCountEqual(partial_vlan_interface_uncfg.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(partial_vlan_interface_uncfg['PE2']),
            '\n'.join([
                'interface Ethernet0/0/2',
                ' no switchport trunk allowed vlan 200-201',
                ' exit',
            ]))