示例#1
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)
示例#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)
    def _get_new_baremetal_portchannel_id(self, nexus_ip_list):
        # Gets initial channel group id for list of nexus switches.
        #
        # :param nexus_ip_list: list of nexus switch to allocate vpcid
        # :returns ch_grp:      vpc_id allocated

        # When allocating vpcid, it must be unique for
        # all switches in the set; else error out.
        ch_grp = nxos_db.alloc_vpcid(nexus_ip_list)
        if ch_grp == 0:
            nexus_ip_list.sort()
            ip_str_list = ','.join('%s' % ip for ip in nexus_ip_list)
            raise cexc.NexusVPCAllocFailure(switches=ip_str_list)

        return ch_grp