<s> import webob . exc <EOL> from networking_cisco . plugins . ml2 . drivers . cisco . n1kv import ( <EOL> constants as n1kv_const ) <EOL> from networking_cisco . plugins . ml2 . drivers . cisco . n1kv import ( <EOL> exceptions as n1kv_exc ) <EOL> from networking_cisco . plugins . ml2 . drivers . cisco . n1kv import ( <EOL> n1kv_client ) <EOL> from networking_cisco . plugins . ml2 . drivers . cisco . n1kv import ( <EOL> n1kv_db ) <EOL> from networking_cisco . plugins . ml2 . drivers . cisco . n1kv import ( <EOL> policy_profile_service ) <EOL> from networking_cisco . tests . unit . ml2 . drivers . cisco . n1kv import ( <EOL> test_cisco_n1kv_mech ) <EOL> from neutron . extensions import portbindings <EOL> from neutron . plugins . ml2 import config as ml2_config <EOL> from neutron . tests . unit . db import test_db_base_plugin_v2 <EOL> class TestN1KVMechDriverPortsV2 ( test_db_base_plugin_v2 . TestPortsV2 , <EOL> test_cisco_n1kv_mech . TestN1KVMechanismDriver ) : <EOL> VIF_TYPE = portbindings . VIF_TYPE_OVS <EOL> HAS_PORT_FILTER = True <EOL> def setUp ( self ) : <EOL> self . load_policy_profile_extension = True <EOL> super ( TestN1KVMechDriverPortsV2 , self ) . setUp ( ) <EOL> pp = policy_profile_service . PolicyProfilePlugin ( ) <EOL> pp . _populate_policy_profiles ( ) <EOL> def test_create_port_with_default_n1kv_policy_profile_id ( <EOL> self , restrict_policy_profiles = False ) : <EOL> """<STR_LIT>""" <EOL> ml2_config . cfg . CONF . set_override ( <EOL> '<STR_LIT>' , <EOL> restrict_policy_profiles , <EOL> '<STR_LIT>' ) <EOL> with self . port ( ) as port : <EOL> pp = n1kv_db . get_policy_profile_by_name ( <EOL> test_cisco_n1kv_mech . DEFAULT_PP ) <EOL> profile_binding = n1kv_db . get_policy_binding ( port [ '<STR_LIT:port>' ] [ '<STR_LIT:id>' ] ) <EOL> self . assertEqual ( profile_binding . profile_id , pp [ '<STR_LIT:id>' ] ) <EOL> port_tenant = port [ '<STR_LIT:port>' ] [ '<STR_LIT>' ] <EOL> self . assert_profile_binding_exists ( <EOL> binding = '<STR_LIT>' , <EOL> tenant_id = port_tenant , <EOL> profile_id = pp [ '<STR_LIT:id>' ] <EOL> ) <EOL> def test_create_port_with_default_n1kv_policy_profile_id_restricted ( self ) : <EOL> """<STR_LIT>""" <EOL> self . test_create_port_with_default_n1kv_policy_profile_id ( <EOL> restrict_policy_profiles = True ) <EOL> def test_create_port_non_default_profile_restricted ( self ) : <EOL> """<STR_LIT>""" <EOL> port_profiles = n1kv_client . Client ( ) . list_port_profiles ( ) <EOL> test_port_profile = port_profiles [ test_cisco_n1kv_mech . TEST_PP ] [ <EOL> '<STR_LIT>' ] <EOL> ml2_config . cfg . CONF . set_override ( <EOL> '<STR_LIT>' , <EOL> True , <EOL> '<STR_LIT>' ) <EOL> with self . network ( ) as network : <EOL> self . _create_port ( <EOL> self . fmt , <EOL> network [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> expected_res_status = webob . exc . HTTPBadRequest . code , <EOL> tenant_id = network [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> set_context = True , <EOL> arg_list = ( '<STR_LIT>' , ) , <EOL> ** { n1kv_const . N1KV_PROFILE : test_cisco_n1kv_mech . TEST_PP } ) <EOL> self . assert_profile_binding_absent ( <EOL> binding = '<STR_LIT>' , <EOL> tenant_id = network [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> profile_id = test_port_profile [ '<STR_LIT:id>' ] ) <EOL> port_data = { <EOL> '<STR_LIT:port>' : { '<STR_LIT>' : network [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> '<STR_LIT>' : self . admin_tenant , <EOL> n1kv_const . N1KV_PROFILE : <EOL> test_cisco_n1kv_mech . TEST_PP } } <EOL> self . create_resource ( <EOL> resource = '<STR_LIT>' , <EOL> data = port_data , <EOL> tenant_id = self . admin_tenant , <EOL> is_admin = True , <EOL> expected_status = webob . exc . HTTPCreated . code , <EOL> api = self . api ) <EOL> self . assert_profile_binding_exists ( <EOL> binding = '<STR_LIT>' , <EOL> tenant_id = self . admin_tenant , <EOL> profile_id = test_port_profile [ '<STR_LIT:id>' ] ) <EOL> def test_create_port_non_default_profile_unrestricted ( self ) : <EOL> """<STR_LIT>""" <EOL> port_profiles = n1kv_client . Client ( ) . list_port_profiles ( ) <EOL> test_port_profile = port_profiles [ test_cisco_n1kv_mech . TEST_PP ] [ <EOL> '<STR_LIT>' ] <EOL> ml2_config . cfg . CONF . set_override ( <EOL> '<STR_LIT>' , <EOL> False , <EOL> '<STR_LIT>' ) <EOL> with self . network ( ) as network : <EOL> res = self . _create_port ( <EOL> self . fmt , <EOL> network [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> expected_res_status = webob . exc . HTTPCreated . code , <EOL> tenant_id = network [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> set_context = True , <EOL> arg_list = ( '<STR_LIT>' , ) , <EOL> ** { n1kv_const . N1KV_PROFILE : test_cisco_n1kv_mech . TEST_PP } ) <EOL> port = self . deserialize ( self . fmt , res ) <EOL> port_tenant = port [ '<STR_LIT:port>' ] [ '<STR_LIT>' ] <EOL> self . assert_profile_binding_exists ( <EOL> binding = '<STR_LIT>' , <EOL> tenant_id = port_tenant , <EOL> profile_id = test_port_profile [ '<STR_LIT:id>' ] <EOL> ) <EOL> def test_delete_port_with_default_n1kv_policy_profile_id ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . network ( ) as network : <EOL> res = self . _create_port ( self . fmt , network [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> webob . exc . HTTPCreated . code , <EOL> tenant_id = network [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> set_context = True ) <EOL> port = self . deserialize ( self . fmt , res ) <EOL> req = self . new_delete_request ( '<STR_LIT>' , port [ '<STR_LIT:port>' ] [ '<STR_LIT:id>' ] ) <EOL> req . get_response ( self . api ) <EOL> self . assertRaises ( n1kv_exc . PortBindingNotFound , <EOL> n1kv_db . get_policy_binding , <EOL> port [ '<STR_LIT:port>' ] [ '<STR_LIT:id>' ] ) </s>
