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)
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 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)
def test_vpc_config_db_results_with_old_config3(self): """Config valid vpc-pool compare with pre-existing entries.""" # 1 no add, already exists # 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) self._run_vpc_config_test('1.1.1.1', '1-4, 6-9, 11', 9, 1, 11)
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)
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)
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)
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)
def test_vpcalloc_min_max(self): # Initialize 3 switch vpc entries nexus_db_v2.init_vpc_entries('1.1.1.1', self._make_vpc_list(1001, 2000)) nexus_db_v2.init_vpc_entries('2.2.2.2', self._make_vpc_list(2001, 3000)) nexus_db_v2.init_vpc_entries('3.3.3.3', self._make_vpc_list(3001, 4000)) # Verify get_switch_vpc_count_min_max() returns correct # count, min, max values for all 3 switches. count, min, max = nexus_db_v2.get_switch_vpc_count_min_max('1.1.1.1') self.assertEqual(count, 1000) self.assertEqual(min, 1001) self.assertEqual(max, 2000) count, min, max = nexus_db_v2.get_switch_vpc_count_min_max('2.2.2.2') self.assertEqual(count, 1000) self.assertEqual(min, 2001) self.assertEqual(max, 3000) count, min, max = nexus_db_v2.get_switch_vpc_count_min_max('3.3.3.3') self.assertEqual(count, 1000) self.assertEqual(min, 3001) self.assertEqual(max, 4000)
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([])