def test_populate_policy_profile_delete(self): # Patch the Client class with the TestClient class with mock.patch(n1kv_client.__name__ + ".Client", new=fake_client.TestClient): # Patch the _get_total_profiles() method to return a custom value with mock.patch(fake_client.__name__ + '.TestClient._get_total_profiles') as obj_inst: # Return 3 policy profiles obj_inst.return_value = 3 plugin = manager.NeutronManager.get_plugin() plugin._populate_policy_profiles() db_session = db.get_session() profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000001') # Verify that DB contains only 3 policy profiles self.assertEqual('pp-1', profile['name']) profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000002') self.assertEqual('pp-2', profile['name']) profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000003') self.assertEqual('pp-3', profile['name']) self.assertRaises(c_exc.PolicyProfileIdNotFound, n1kv_db_v2.get_policy_profile, db_session, '00000000-0000-0000-0000-000000000004') # Return 2 policy profiles obj_inst.return_value = 2 plugin._populate_policy_profiles() # Verify that the third policy profile is deleted self.assertRaises(c_exc.PolicyProfileIdNotFound, n1kv_db_v2.get_policy_profile, db_session, '00000000-0000-0000-0000-000000000003')
def test_populate_policy_profile_delete(self): # Patch the Client class with the TestClient class with patch(n1kv_client.__name__ + ".Client", new=fake_client.TestClient): # Patch the _get_total_profiles() method to return a custom value with patch(fake_client.__name__ + '.TestClient._get_total_profiles') as obj_inst: # Return 3 policy profiles obj_inst.return_value = 3 plugin = manager.NeutronManager.get_plugin() plugin._populate_policy_profiles() db_session = db.get_session() profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000001') # Verify that DB contains only 3 policy profiles self.assertEqual('pp-1', profile['name']) profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000002') self.assertEqual('pp-2', profile['name']) profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000003') self.assertEqual('pp-3', profile['name']) self.assertRaises(c_exc.PolicyProfileIdNotFound, n1kv_db_v2.get_policy_profile, db_session, '00000000-0000-0000-0000-000000000004') # Return 2 policy profiles obj_inst.return_value = 2 plugin._populate_policy_profiles() # Verify that the third policy profile is deleted self.assertRaises(c_exc.PolicyProfileIdNotFound, n1kv_db_v2.get_policy_profile, db_session, '00000000-0000-0000-0000-000000000003')
def test_create_port_with_default_n1kv_policy_profile_id(self): """Test port create without passing policy profile id.""" with self.port() as port: db_session = db.get_session() pp = n1kv_db_v2.get_policy_profile( db_session, port['port'][n1kv.PROFILE_ID]) self.assertEqual(pp['name'], 'service_profile')
def test_create_port_with_default_n1kv_policy_profile_id(self): """Test port create without passing policy profile id.""" with self.port() as port: db_session = db.get_session() pp = n1kv_db_v2.get_policy_profile(db_session, port['port'][n1kv.PROFILE_ID]) self.assertEqual(pp['name'], 'service_profile')
def test_populate_policy_profile(self): client_patch = mock.patch(n1kv_client.__name__ + ".Client", new=fake_client.TestClient) client_patch.start() instance = n1kv_neutron_plugin.N1kvNeutronPluginV2() instance._populate_policy_profiles() db_session = db.get_session() profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000001') self.assertEqual('pp-1', profile['name']) client_patch.stop()
def test_populate_policy_profile(self): client_patch = patch(n1kv_client.__name__ + ".Client", new=fake_client.TestClient) client_patch.start() instance = n1kv_neutron_plugin.N1kvNeutronPluginV2() instance._populate_policy_profiles() db_session = db.get_session() profile = n1kv_db_v2.get_policy_profile( db_session, '00000000-0000-0000-0000-000000000001') self.assertEqual('pp-1', profile['name']) client_patch.stop()
def _send_create_port_request(self, context, port): """ Send create port request to VSM. Create a VM network for a network and policy profile combination. If the VM network already exists, bind this port to the existing VM network and increment its port count. :param context: neutron api request context :param port: port dictionary """ LOG.debug(_('_send_create_port_request: %s'), port) try: vm_network = n1kv_db_v2.get_vm_network( context.session, port[n1kv_profile.PROFILE_ID], port['network_id']) except cisco_exceptions.VMNetworkNotFound: policy_profile = n1kv_db_v2.get_policy_profile( context.session, port[n1kv_profile.PROFILE_ID]) network = self.get_network(context, port['network_id']) vm_network_name = (c_const.VM_NETWORK_NAME_PREFIX + str(port[n1kv_profile.PROFILE_ID]) + "_" + str(port['network_id'])) port_count = 1 n1kv_db_v2.add_vm_network(context.session, vm_network_name, port[n1kv_profile.PROFILE_ID], port['network_id'], port_count) n1kvclient = n1kv_client.Client() n1kvclient.create_vm_network(port, vm_network_name, policy_profile, network['name']) n1kvclient.create_n1kv_port(port, vm_network_name) else: vm_network_name = vm_network['name'] n1kvclient = n1kv_client.Client() n1kvclient.create_n1kv_port(port, vm_network_name) vm_network['port_count'] += 1 n1kv_db_v2.update_vm_network_port_count( context.session, vm_network_name, vm_network['port_count'])
def _send_create_port_request(self, context, port): """ Send create port request to VSM. Create a VM network for a network and policy profile combination. If the VM network already exists, bind this port to the existing VM network and increment its port count. :param context: neutron api request context :param port: port dictionary """ LOG.debug(_('_send_create_port_request: %s'), port) try: vm_network = n1kv_db_v2.get_vm_network( context.session, port[n1kv_profile.PROFILE_ID], port['network_id']) except cisco_exceptions.VMNetworkNotFound: policy_profile = n1kv_db_v2.get_policy_profile( context.session, port[n1kv_profile.PROFILE_ID]) network = self.get_network(context, port['network_id']) vm_network_name = (c_const.VM_NETWORK_NAME_PREFIX + str(port[n1kv_profile.PROFILE_ID]) + "_" + str(port['network_id'])) port_count = 1 n1kv_db_v2.add_vm_network(context.session, vm_network_name, port[n1kv_profile.PROFILE_ID], port['network_id'], port_count) n1kvclient = n1kv_client.Client() n1kvclient.create_vm_network(port, vm_network_name, policy_profile, network['name']) n1kvclient.create_n1kv_port(port, vm_network_name) else: vm_network_name = vm_network['name'] n1kvclient = n1kv_client.Client() n1kvclient.create_n1kv_port(port, vm_network_name) vm_network['port_count'] += 1 n1kv_db_v2.update_vm_network_port_count(context.session, vm_network_name, vm_network['port_count'])
def test_get_policy_profile(self): profile = _create_test_policy_profile_if_not_there(self.session) got_profile = n1kv_db_v2.get_policy_profile(self.session, profile.id) self.assertEqual(profile.id, got_profile.id) self.assertEqual(profile.name, got_profile.name)