def process_create_port(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" port_id = result.get('id') policy_profile_attr = data.get(constants.N1KV_PROFILE) if not attributes.is_attr_set(policy_profile_attr): policy_profile_attr = (cfg.CONF.ml2_cisco_n1kv. default_policy_profile) with context.session.begin(subtransactions=True): try: n1kv_db.get_policy_binding(port_id, context.session) except n1kv_exc.PortBindingNotFound: if not uuidutils.is_uuid_like(policy_profile_attr): policy_profile = n1kv_db.get_policy_profile_by_name( policy_profile_attr, context.session) if policy_profile: policy_profile_attr = policy_profile.id else: LOG.error(_LE("Policy Profile %(profile)s does " "not exist."), {"profile": policy_profile_attr}) raise ml2_exc.MechanismDriverError() elif not (n1kv_db.get_policy_profile_by_uuid( context.session, policy_profile_attr)): LOG.error(_LE("Policy Profile %(profile)s does not " "exist."), {"profile": policy_profile_attr}) raise ml2_exc.MechanismDriverError() n1kv_db.add_policy_binding(port_id, policy_profile_attr, context.session) result[constants.N1KV_PROFILE] = policy_profile_attr
def process_create_port(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" port_id = result.get('id') policy_profile_attr = data.get(constants.N1KV_PROFILE) if not attributes.is_attr_set(policy_profile_attr): policy_profile_attr = ( cfg.CONF.ml2_cisco_n1kv.default_policy_profile) with context.session.begin(subtransactions=True): try: n1kv_db.get_policy_binding(port_id, context.session) except n1kv_exc.PortBindingNotFound: if not uuidutils.is_uuid_like(policy_profile_attr): policy_profile = n1kv_db.get_policy_profile_by_name( policy_profile_attr, context.session) if policy_profile: policy_profile_attr = policy_profile.id else: LOG.error( _LE("Policy Profile %(profile)s does " "not exist."), {"profile": policy_profile_attr}) raise ml2_exc.MechanismDriverError() elif not (n1kv_db.get_policy_profile_by_uuid( context.session, policy_profile_attr)): LOG.error( _LE("Policy Profile %(profile)s does not " "exist."), {"profile": policy_profile_attr}) raise ml2_exc.MechanismDriverError() n1kv_db.add_policy_binding(port_id, policy_profile_attr, context.session) result[constants.N1KV_PROFILE] = policy_profile_attr
def test_add_and_get_profile_binding(self): with self.port() as port: TEST_PORT_ID = port['port']['id'] self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID) p = _create_test_policy_profile_if_not_there(self.session) n1kv_db.add_policy_binding(TEST_PORT_ID, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID, binding.port_id) self.assertEqual(p.id, binding.profile_id)
def test_add_and_get_profile_binding(self): with self.port() as port: TEST_PORT_ID = port['port']['id'] self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID) p = _create_test_policy_profile_if_not_there(self.session) n1kv_db.add_policy_binding(TEST_PORT_ID, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID, binding.port_id) self.assertEqual(p.id, binding.profile_id)
def process_create_port(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" port_id = result.get('id') policy_profile_attr = data.get(constants.N1KV_PROFILE) tenant_id = context.tenant_id or data.get('tenant_id') default_policy_profile_name = (cfg.CONF.ml2_cisco_n1kv. default_policy_profile) if not bc_attr.is_attr_set(policy_profile_attr): policy_profile_attr = default_policy_profile_name with context.session.begin(subtransactions=True): try: if not uuidutils.is_uuid_like(policy_profile_attr): policy_profile = n1kv_db.get_policy_profile_by_name( policy_profile_attr, context.session) else: policy_profile = (n1kv_db.get_policy_profile_by_uuid( context.session, policy_profile_attr)) n1kv_db.get_profile_binding(db_session=context.session, tenant_id=tenant_id, profile_id=policy_profile.id) except n1kv_exc.PolicyProfileNotFound: LOG.error(_LE("Policy Profile %(profile)s does " "not exist."), {"profile": policy_profile_attr}) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') except n1kv_exc.ProfileTenantBindingNotFound: if context.is_admin: session = context.session n1kv_db.update_policy_profile_binding_with_tenant_id( policy_profile.id, tenant_id, session) elif (cfg.CONF.ml2_cisco_n1kv.restrict_policy_profiles and policy_profile.name != default_policy_profile_name): LOG.error(_LE("Policy Profile %s is " "not owned by this tenant.") % policy_profile_attr) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') n1kv_db.add_policy_binding(port_id, policy_profile.id, context.session) result[constants.N1KV_PROFILE] = policy_profile.id
def process_create_port(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" port_id = result.get('id') policy_profile_attr = data.get(constants.N1KV_PROFILE) tenant_id = context.tenant_id or data.get('tenant_id') default_policy_profile_name = (cfg.CONF.ml2_cisco_n1kv. default_policy_profile) if not bc.is_attr_set(policy_profile_attr): policy_profile_attr = default_policy_profile_name with context.session.begin(subtransactions=True): try: if not uuidutils.is_uuid_like(policy_profile_attr): policy_profile = n1kv_db.get_policy_profile_by_name( policy_profile_attr, context.session) else: policy_profile = (n1kv_db.get_policy_profile_by_uuid( context.session, policy_profile_attr)) n1kv_db.get_profile_binding(db_session=context.session, tenant_id=tenant_id, profile_id=policy_profile.id) except n1kv_exc.PolicyProfileNotFound: LOG.error("Policy Profile %(profile)s does " "not exist.", {"profile": policy_profile_attr}) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') except n1kv_exc.ProfileTenantBindingNotFound: if context.is_admin: session = context.session n1kv_db.update_policy_profile_binding_with_tenant_id( policy_profile.id, tenant_id, session) elif (cfg.CONF.ml2_cisco_n1kv.restrict_policy_profiles and policy_profile.name != default_policy_profile_name): LOG.error("Policy Profile %s is " "not owned by this tenant." % policy_profile_attr) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') n1kv_db.add_policy_binding(port_id, policy_profile.id, context.session) result[constants.N1KV_PROFILE] = policy_profile.id
def test_add_and_get_multiple_profile_bindings(self): with self.subnet() as subnet: with self.port(subnet=subnet) as port1: with self.port(subnet=subnet) as port2: TEST_PORT_ID1 = port1['port']['id'] TEST_PORT_ID2 = port2['port']['id'] self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID1) self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID2) p = _create_test_policy_profile_if_not_there(self.session) n1kv_db.add_policy_binding(TEST_PORT_ID1, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID1) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID1, binding.port_id) self.assertEqual(p.id, binding.profile_id) n1kv_db.add_policy_binding(TEST_PORT_ID2, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID2) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID2, binding.port_id) self.assertEqual(p.id, binding.profile_id)
def test_add_and_get_multiple_profile_bindings(self): with self.subnet() as subnet: with self.port(subnet=subnet) as port1: with self.port(subnet=subnet) as port2: TEST_PORT_ID1 = port1['port']['id'] TEST_PORT_ID2 = port2['port']['id'] self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID1) self.assertRaises(c_exc.PortBindingNotFound, n1kv_db.get_policy_binding, TEST_PORT_ID2) p = _create_test_policy_profile_if_not_there(self.session) n1kv_db.add_policy_binding(TEST_PORT_ID1, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID1) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID1, binding.port_id) self.assertEqual(p.id, binding.profile_id) n1kv_db.add_policy_binding(TEST_PORT_ID2, p.id) binding = n1kv_db.get_policy_binding(TEST_PORT_ID2) self.assertIsNotNone(binding) self.assertEqual(TEST_PORT_ID2, binding.port_id) self.assertEqual(p.id, binding.profile_id)