Пример #1
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 _configure_learned_port_channel(self, nexus_ip_list, ch_grp):
        # Handle baremetal interfaces when vpc-id was learned from Nexus.
        #
        #:param nexus_ip_list: list of nexus switch to allocate vpcid
        #:param ch_grp: learned ch_grp

        try:
            nxos_db.update_vpc_entry(nexus_ip_list, ch_grp, True, True)
        except cexc.NexusVPCAllocNotFound:
            # Valid to get this error if learned ch_grp
            # not part of configured vpc_pool
            pass
Пример #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_vpc_config_db_results_with_old_config2(self):
        """Config valid vpc-pool compare with pre-existing entries."""

        # 1 no add, already exists
        # 6 remove not active
        # 8 no remove, ACTIVE
        # 11 no add, already exists
        old_list = [1, 6, 8, 11]

        # Pretend these already existed and make 8 active
        nxos_db.init_vpc_entries('1.1.1.1', old_list)
        nxos_db.update_vpc_entry(['1.1.1.1'], 8, True, True)

        self._run_vpc_config_test('1.1.1.1', '1-4, 9, 11', 7, 1, 11)
Пример #5
0
    def test_vpc_config_db_results_with_old_config1(self):
        """Config valid vpc-pool compare with pre-existing entries."""

        # 1 will be removed,
        # 3 no add, already exists
        # 4 no add, already exists
        # 11 will not be removed since active
        old_list = [1, 3, 4, 11]

        # Pretend these already existed and make 11 active
        nxos_db.init_vpc_entries('1.1.1.1', old_list)
        nxos_db.update_vpc_entry(['1.1.1.1'], 11, True, True)

        self._run_vpc_config_test('1.1.1.1', '2-5, 8', 6, 2, 11)
Пример #6
0
    def test_vpc_config_db_results_bad_config_keep_old(self):
        """Verify on config error, existing db entries stay intact."""

        old_list = [1, 6, 8, 11]

        # Pretend these already existed and make 8 active
        nxos_db.init_vpc_entries('1.1.1.1', old_list)
        nxos_db.update_vpc_entry(['1.1.1.1'], 8, True, True)

        # valid port-channel values are 1-4096 on Nexus 9K

        # ERROR: range starts with 0
        bad_min = str(const.MINVPC - 1) + '-1001, 1002'
        self._run_vpc_config_test('1.1.1.1', bad_min, 4, 1, 11)
Пример #7
0
    def test_vpc_config_db_results_removal(self):
        """Allow user to remove config but only non-active."""

        # 1 no add, already exists
        # 6 remove not active
        # 8 no remove, ACTIVE
        # 11 no add, already exists
        old_list = [1, 6, 8, 11]

        # Pretend these already existed and make 8 active
        nxos_db.init_vpc_entries('1.1.1.1', old_list)
        nxos_db.update_vpc_entry(['1.1.1.1'], 8, True, True)

        self._run_vpc_config_test('1.1.1.1', '', 1, 8, 8)

        # Make 8 inactive and try again.
        nxos_db.update_vpc_entry(['1.1.1.1'], 8, False, False)
        self._run_vpc_config_test('1.1.1.1', '', 0, None, None)
Пример #8
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)