def initialize(self): # Extend extension to service mapping dict # TODO(sakvarma) Check if this mapping can be removed p_const.EXT_TO_SERVICE_MAPPING['cisco_n1kv_profile'] = (n1kv_const. CISCO_N1KV) self.n1kvclient = n1kv_client.Client() self.sync_obj = n1kv_sync.N1kvSyncDriver(db_base_plugin_v2. NeutronDbPluginV2()) eventlet.spawn(self.sync_obj.do_sync) # Get VLAN/VXLAN network profiles name self.netp_name = {p_const.TYPE_VLAN: ( n1kv_const.DEFAULT_VLAN_NETWORK_PROFILE_NAME), p_const.TYPE_VXLAN: ( n1kv_const.DEFAULT_VXLAN_NETWORK_PROFILE_NAME)} # Ensure network profiles are created on the VSM try: self._ensure_network_profiles_created_on_vsm() except (n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError): LOG.error(_LE("VSM failed to create default network profiles.")) self.vif_type = portbindings.VIF_TYPE_OVS self.vif_details = {portbindings.CAP_PORT_FILTER: True, portbindings.OVS_HYBRID_PLUG: True} self.supported_network_types = [p_const.TYPE_VLAN, p_const.TYPE_VXLAN]
def test_create_port_non_default_profile_unrestricted(self): """ Test port creation with a test policy profile, and unrestricted access to policy profiles. """ port_profiles = n1kv_client.Client().list_port_profiles() test_port_profile = port_profiles[test_cisco_n1kv_mech.TEST_PP][ 'properties'] ml2_config.cfg.CONF.set_override( 'restrict_policy_profiles', False, 'ml2_cisco_n1kv') with self.network() as network: res = self._create_port( self.fmt, network['network']['id'], expected_res_status=webob.exc.HTTPCreated.code, tenant_id=network['network']['tenant_id'], set_context=True, arg_list=('n1kv:profile',), **{n1kv_const.N1KV_PROFILE: test_cisco_n1kv_mech.TEST_PP}) port = self.deserialize(self.fmt, res) # assert that binding for port-profile exists port_tenant = port['port']['tenant_id'] self.assert_profile_binding_exists( binding='policy_profile_bindings', tenant_id=port_tenant, profile_id=test_port_profile['id'] )
def __init__(self, db_base_plugin_obj): self.n1kvclient = n1kv_client.Client() self.db_base_plugin = db_base_plugin_obj self.sync_resource = { NETWORK_PROFILES: False, NETWORKS: False, SUBNETS: False, PORTS: False } self.sync_sleep_duration = cfg.CONF.ml2_cisco_n1kv.sync_interval self.bd_names = []
def __init__(self, db_base_plugin_obj): self.n1kvclient = n1kv_client.Client() self.db_base_plugin = db_base_plugin_obj self.sync_resource = {n1kv_const.NETWORK_PROFILES: False, n1kv_const.NETWORKS: False, n1kv_const.SUBNETS: False, n1kv_const.PORTS: False} self.sync_sleep_duration = cfg.CONF.ml2_cisco_n1kv.sync_interval # default to True so that BDs for all VSMs are synced at a neutron # restart self.sync_bds = {vsm_ip: True for vsm_ip in config.get_vsm_hosts()} self.bd_names = set()
def test_vsm_retry(self): """Test retry count for VSM REST API.""" max_retries = 3 ml2_config.cfg.CONF.set_override('max_vsm_retries', max_retries, 'ml2_cisco_n1kv') with mock.patch.object(fake_client.TestClientVSMRetry, '_fake_pool_spawn') as mock_method: # Mock the fake HTTP conn method to generate timeouts mock_method.side_effect = Exception("Conn timeout") # Create client instance client = n1kv_client.Client() # Test that the GET API for profiles is retried self.assertRaises(n1kv_exc.VSMConnectionFailed, client.list_port_profiles) # Verify that number of attempts = 1 + max_retries self.assertEqual(1 + max_retries, mock_method.call_count)
def test_create_port_non_default_profile_restricted(self): """ Test port creation with a test policy profile, and restricted access to policy profiles. """ port_profiles = n1kv_client.Client().list_port_profiles() test_port_profile = port_profiles[test_cisco_n1kv_mech.TEST_PP][ 'properties'] ml2_config.cfg.CONF.set_override( 'restrict_policy_profiles', True, 'ml2_cisco_n1kv') with self.network() as network: # test port-create with non-admin tenant self._create_port( self.fmt, network['network']['id'], expected_res_status=webob.exc.HTTPBadRequest.code, tenant_id=network['network']['tenant_id'], set_context=True, arg_list=('n1kv:profile',), **{n1kv_const.N1KV_PROFILE: test_cisco_n1kv_mech.TEST_PP}) self.assert_profile_binding_absent( binding='policy_profile_bindings', tenant_id=network['network']['tenant_id'], profile_id=test_port_profile['id']) # test port-create with admin tenant port_data = { 'port': {'network_id': network['network']['id'], 'tenant_id': self.admin_tenant, n1kv_const.N1KV_PROFILE: test_cisco_n1kv_mech.TEST_PP}} self.create_resource( resource='ports', data=port_data, tenant_id=self.admin_tenant, is_admin=True, expected_status=webob.exc.HTTPCreated.code, api=self.api) self.assert_profile_binding_exists( binding='policy_profile_bindings', tenant_id=self.admin_tenant, profile_id=test_port_profile['id'])
def test_update_policy_profile(self): """ Test policy profile updation including both adding new tenants, and removing existing ones from a policy profile. """ ml2_config.cfg.CONF.set_override('restrict_policy_profiles', True, 'ml2_cisco_n1kv') port_profiles = n1kv_client.Client().list_port_profiles() test_port_profile = port_profiles[TEST_PP]['properties'] tenant_ids = ['tenant1', 'tenant2'] # test pp update with new tenant additions self.update_assert_profile(profile_type='policy', profile_id=test_port_profile['id'], add_tenants=tenant_ids) # test pp update with existing tenant deletions self.update_assert_profile(profile_type='policy', profile_id=test_port_profile['id'], remove_tenants=tenant_ids)
def __init__(self): super(PolicyProfilePlugin, self).__init__() api_extensions.append_api_extensions_path(extensions.__path__) # Initialize N1KV client self.n1kvclient = n1kv_client.Client() eventlet.spawn(self._poll_policy_profiles)
def __init__(self): super(NetworkProfilePlugin, self).__init__() api_extensions.append_api_extensions_path(extensions.__path__) # Initialize N1KV client self.n1kvclient = n1kv_client.Client()