示例#1
0
    def test_automated_port_channel_creation_deletion(self):
        """Basic creation and deletion test of 1 auto port-channel."""

        data_json = {'rest_get.side_effect': self.get_init_side_effect2}
        self.mock_ncclient.configure_mock(**data_json)

        switch_list = ['1.1.1.1', '2.2.2.2']
        for switch_ip in switch_list:
            self._cisco_mech_driver._nexus_switches[switch_ip,
                                                    const.VPCPOOL] = (
                                                        '1001-1025, 1030')
        self._cisco_mech_driver._initialize_vpc_alloc_pools()

        self._basic_create_verify_port_vlan(
            'test_config_vPC',
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_add1'),
            nbr_of_bindings=2)

        for switch_ip in switch_list:
            self.assertEqual(
                25, len(nxos_db.get_free_switch_vpc_allocs(switch_ip)))

        # Clean all the ncclient mock_calls so we can evaluate
        # results of delete operations.
        self.mock_ncclient.reset_mock()

        self._basic_delete_verify_port_vlan(
            'test_config_vPC',
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_del1'))

        for switch_ip in switch_list:
            self.assertEqual(
                26, len(nxos_db.get_free_switch_vpc_allocs(switch_ip)))
示例#2
0
    def test_vpcalloc_test_alloc_collision(self):

        def new_get_free_vpcids_on_switches(nexus_ips):
            results = nexus_db_v2.get_free_switch_vpc_allocs('4.4.4.4')
            return results

        nexus_ips = ['1.1.1.1', '2.2.2.2', '3.3.3.3']

        for this_ip in nexus_ips:
            nexus_db_v2.init_vpc_entries(
                this_ip, self._make_vpc_list(1001, 1025))
        # IP 4.4.4.4 is added only to return a list of vpc ids
        # in same format as sql will return.
        nexus_db_v2.init_vpc_entries(
                '4.4.4.4', self._make_vpc_list(1001, 1003))
        mock.patch.object(nexus_db_v2,
                         '_get_free_vpcids_on_switches',
                          new=new_get_free_vpcids_on_switches).start()

        # configure '3.3.3.3', vpcid 1001 so alloc_vpcid will fail
        # on 1001 after updating 1.1.1.1 and 2.2.2.2 and rollback
        # occurs.  Then moves onto successfully allocating 1002.
        nexus_db_v2.update_vpc_entry(['3.3.3.3'], 1001, False, True)
        vpc_id = nexus_db_v2.alloc_vpcid(nexus_ips)
        self.assertEqual(vpc_id, 1002)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('1.1.1.1')
        self.assertEqual(len(allocs), 24)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('2.2.2.2')
        self.assertEqual(len(allocs), 24)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('3.3.3.3')
        self.assertEqual(len(allocs), 23)
示例#3
0
    def test_vpcalloc_rollback(self):

        nexus_ips = ['1.1.1.1', '2.2.2.2', '3.3.3.3']

        for this_ip in nexus_ips:
            nexus_db_v2.init_vpc_entries(this_ip,
                                         self._make_vpc_list(1001, 1025))

        nexus_db_v2.update_vpc_entry(nexus_ips, 1001, False, True)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('1.1.1.1')
        self.assertEqual(len(allocs), 24)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('2.2.2.2')
        self.assertEqual(len(allocs), 24)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('3.3.3.3')
        self.assertEqual(len(allocs), 24)

        nexus_db_v2.update_vpc_entry(nexus_ips, 1001, False, False)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('1.1.1.1')
        self.assertEqual(len(allocs), 25)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('2.2.2.2')
        self.assertEqual(len(allocs), 25)
        allocs = nexus_db_v2.get_free_switch_vpc_allocs('3.3.3.3')
        self.assertEqual(len(allocs), 25)

        nexus_db_v2.update_vpc_entry(['3.3.3.3'], 1001, False, True)
        try:
            nexus_db_v2.update_vpc_entry(nexus_ips, 1001, False, True)
        except exceptions.NexusVPCAllocNotFound:
            allocs = nexus_db_v2.get_free_switch_vpc_allocs('1.1.1.1')
            self.assertEqual(len(allocs), 25)
            allocs = nexus_db_v2.get_free_switch_vpc_allocs('2.2.2.2')
            self.assertEqual(len(allocs), 25)
            allocs = nexus_db_v2.get_free_switch_vpc_allocs('3.3.3.3')
            self.assertEqual(len(allocs), 24)
示例#4
0
    def test_vpcalloc_init(self):

        nexus_ips = ['1.1.1.1', '2.2.2.2', '3.3.3.3']

        for this_ip in nexus_ips:
            nexus_db_v2.init_vpc_entries(
                this_ip, self._make_vpc_list(1001, 1025))
            allocs = nexus_db_v2.get_free_switch_vpc_allocs(this_ip)
            self.assertEqual(len(allocs), 25)

        nexus_db_v2.update_vpc_entry(['1.1.1.1'], 1001, False, True)
        nexus_db_v2.update_vpc_entry(['2.2.2.2'], 1002, False, True)
        nexus_db_v2.update_vpc_entry(['3.3.3.3'], 1003, False, True)

        # Verify this update fails since entry already active
        self.assertRaises(
            exceptions.NexusVPCAllocNotFound,
            nexus_db_v2.update_vpc_entry,
            ['3.3.3.3'], 1003, False, True)

        new_vpcid = nexus_db_v2.alloc_vpcid(nexus_ips)
        self.assertEqual(new_vpcid, 1004)

        nexus_db_v2.free_vpcid_for_switch(1002, '2.2.2.2')
        nexus_db_v2.free_vpcid_for_switch_list(1004, nexus_ips)

        # verify vpc 1002 can now be reused
        new_vpcid = nexus_db_v2.alloc_vpcid(nexus_ips)
        self.assertEqual(new_vpcid, 1002)
示例#5
0
    def test_replay_automated_port_channel_w_user_cfg(self):
        """Basic replay of auto-port-channel creation with user config."""

        data_json = {'rest_get.side_effect': self.get_init_side_effect2}
        self.mock_ncclient.configure_mock(**data_json)

        switch_list = ['1.1.1.1', '2.2.2.2']

        for switch_ip in switch_list:
            self._cisco_mech_driver._nexus_switches[switch_ip,
                                                    const.VPCPOOL] = (
                                                        '1001-1025')
        self._cisco_mech_driver._initialize_vpc_alloc_pools()

        self._cfg_vPC_user_commands(
            switch_list, "spanning-tree port type edge trunk ;no lacp "
            "suspend-individual")

        # _init_port_channel is not called so the vpc nbr gets created.

        def replay_complete():
            # Add same together cause this  accounts for the initial add
            # as well as add during replay.
            myresults = (
                self.results.get_test_results(
                    'driver_result_unique_auto_vPC_add_usr_cmd_nxapi_cli') +
                self.results.get_test_results(
                    'driver_result_unique_auto_vPC_add_usr_cmd_nxapi_cli'))
            self._verify_nxapi_results(myresults)

        first_add = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_add1_w_user_cfg'),
            'nbr_db_entries':
            2
        }
        second_del = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_del1'),
            'nbr_db_entries':
            0
        }

        self._process_replay(
            'test_replay_unique_vPC',
            None, [],
            first_add,
            None,
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_add1_w_user_cfg_replay'),
            None,
            second_del,
            replay_complete=replay_complete)

        for switch_ip in switch_list:
            self.assertEqual(
                25, len(nxos_db.get_free_switch_vpc_allocs(switch_ip)))
示例#6
0
    def test_replay_automated_vPC_ports_and_vm(self):
        """Provides replay data and result data for unique ports. """

        data_json = {'rest_get.side_effect': self.get_init_side_effect2}
        self.mock_ncclient.configure_mock(**data_json)

        switch_list = ['1.1.1.1', '2.2.2.2']

        for switch_ip in switch_list:
            self._cisco_mech_driver._nexus_switches[switch_ip,
                                                    const.VPCPOOL] = (
                                                        '1001-1025')
        self._cisco_mech_driver._initialize_vpc_alloc_pools()

        # _init_port_channel is not called so the vpc nbr is created

        first_add = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_add1'),
            'nbr_db_entries':
            2
        }
        second_add = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_vm_add1'),
            'nbr_db_entries':
            4
        }
        first_del = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_vm_del1'),
            'nbr_db_entries':
            2
        }
        second_del = {
            'driver_results':
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_del1'),
            'nbr_db_entries':
            0
        }

        self._process_replay(
            'test_replay_unique_vPC', 'test_config_vm', [], first_add,
            second_add,
            self.results.get_test_results(
                'driver_result_unique_auto_vPC_2vlan_replay'), first_del,
            second_del)

        for switch_ip in switch_list:
            self.assertEqual(
                25, len(nxos_db.get_free_switch_vpc_allocs(switch_ip)))
示例#7
0
 def new_get_free_vpcids_on_switches(nexus_ips):
     results = nexus_db_v2.get_free_switch_vpc_allocs('4.4.4.4')
     return results
示例#8
0
    def test_failure_inconsistent_new_chgrp(self):
        """Started as newly created chgrp but one if had chgrp configured."""

        # First interface Nexus returns there's no ch_grp
        # so treat as port-channel create.
        # Second interface Nexus returns ch_grp so so process
        # reset procedure which checks that .....
        #   - port-channel deleted from Nexus for first interface
        #   - ch_grp removed from Nexus on first interface
        #   - free-up vpcid allocated on first interface
        #   - raised cexc.NexusVPCExpectedNoChgrp

        LOCAL_GET_PORT_CH_RESPONSE = {
            "totalCount":
            "1",
            "imdata": [{
                "pcRsMbrIfs": {
                    "attributes": {
                        "parentSKey": "po470",
                        "tSKey": "eth1/20",
                    }
                }
            }]
        }

        def local_get_init_side_effect(action,
                                       ipaddr=None,
                                       body=None,
                                       headers=None):

            eth_path = 'api/mo/sys/intf/phys-'
            port_chan_path = 'api/mo/sys/intf/aggr-'

            if action == snipp.PATH_GET_NEXUS_TYPE:
                return base.GET_NEXUS_TYPE_RESPONSE
            elif action in snipp.PATH_GET_PC_MEMBERS:
                return LOCAL_GET_PORT_CH_RESPONSE
            elif eth_path in action:
                return base.GET_INTERFACE_RESPONSE
            elif port_chan_path in action:
                return GET_INTERFACE_PCHAN_NO_TRUNK_RESPONSE

            return {}

        # Substitute init_port_channel() with the following
        # since this is a one time test scenario.
        data_json = {'rest_get.side_effect': local_get_init_side_effect}
        self.mock_ncclient.configure_mock(**data_json)

        switch_list = ['1.1.1.1', '2.2.2.2']

        for switch_ip in switch_list:
            nxos_db.init_vpc_entries(switch_ip,
                                     self._make_vpc_list(1001, 1025))
            allocs = nxos_db.get_free_switch_vpc_allocs(switch_ip)
            self.assertEqual(len(allocs), 25)

        e = self.assertRaises(exceptions.NexusVPCExpectedNoChgrp,
                              self._create_port,
                              self.test_configs['test_config_vPC'])
        # Check that appropriate string in exception string
        x = six.u(str(e))
        self.assertIn("first interface 1.1.1.1, ethernet:1/10, vpc=None", x)
        self.assertIn("second interface 2.2.2.2, ethernet:1/20, vpc=470", x)

        # Verify vpcid initially allocated is now free
        for switch_ip in switch_list:
            allocs = nxos_db.get_free_switch_vpc_allocs(switch_ip)
            self.assertEqual(len(allocs), 25)

        # Verify no attempt to create port-channels
        self._verify_results([])