def test_create_profile_binding(self): test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "network" n1kv_db_v2.create_profile_binding(self.session, test_tenant_id, test_profile_id, test_profile_type) try: self.session.query(n1kv_models_v2.ProfileBinding).filter_by( profile_type=test_profile_type, tenant_id=test_tenant_id, profile_id=test_profile_id ).one() except s_exc.MultipleResultsFound: self.fail("Bindings must be unique") except s_exc.NoResultFound: self.fail("Could not create Profile Binding")
def test_create_profile_binding(self): test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "network" n1kv_db_v2.create_profile_binding(self.session, test_tenant_id, test_profile_id, test_profile_type) try: self.session.query(n1kv_models_v2.ProfileBinding).filter_by( profile_type=test_profile_type, tenant_id=test_tenant_id, profile_id=test_profile_id).one() except s_exc.MultipleResultsFound: self.fail("Bindings must be unique") except s_exc.NoResultFound: self.fail("Could not create Profile Binding")
def test_default_tenant_replace(self): ctx = context.get_admin_context() ctx.tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "policy" n1kv_db_v2.create_profile_binding(self.session, c_const.TENANT_ID_NOT_SET, test_profile_id, test_profile_type) network_profile = {"network_profile": TEST_NETWORK_PROFILE} self.create_network_profile(ctx, network_profile) binding = n1kv_db_v2.get_profile_binding(self.session, ctx.tenant_id, test_profile_id) self.assertRaises(c_exc.ProfileTenantBindingNotFound, n1kv_db_v2.get_profile_binding, self.session, c_const.TENANT_ID_NOT_SET, test_profile_id) self.assertNotEqual(binding.tenant_id, c_const.TENANT_ID_NOT_SET)
def test_update_profile_binding(self): test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "network" n1kv_db_v2.create_profile_binding(self.session, test_tenant_id, test_profile_id, test_profile_type) new_tenants = [ 'd434dd90-76ec-11e2-bcfd-0800200c9a67', 'd434dd90-76ec-11e2-bcfd-0800200c9a68', 'd434dd90-76ec-11e2-bcfd-0800200c9a69' ] n1kv_db_v2.update_profile_binding(self.session, test_profile_id, new_tenants, test_profile_type) result = self.session.query(n1kv_models_v2.ProfileBinding).filter_by( profile_type=test_profile_type, profile_id=test_profile_id).all() self.assertEqual(3, len(result))
def test_default_tenant_replace(self): ctx = context.get_admin_context() ctx.tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "policy" n1kv_db_v2.create_profile_binding(cisco_constants.TENANT_ID_NOT_SET, test_profile_id, test_profile_type) network_profile = {"network_profile": TEST_NETWORK_PROFILE} test_network_profile = self.create_network_profile( ctx, network_profile) binding = n1kv_db_v2.get_profile_binding(ctx.tenant_id, test_profile_id) self.assertIsNone( n1kv_db_v2.get_profile_binding(cisco_constants.TENANT_ID_NOT_SET, test_profile_id)) self.assertNotEqual(binding.tenant_id, cisco_constants.TENANT_ID_NOT_SET) n1kv_db_v2.delete_network_profile(self.session, test_network_profile['id'])
def test_default_tenant_replace(self): ctx = context.get_admin_context() ctx.tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "policy" n1kv_db_v2.create_profile_binding( self.session, cisco_constants.TENANT_ID_NOT_SET, test_profile_id, test_profile_type ) network_profile = {"network_profile": TEST_NETWORK_PROFILE} self.create_network_profile(ctx, network_profile) binding = n1kv_db_v2.get_profile_binding(self.session, ctx.tenant_id, test_profile_id) self.assertRaises( c_exc.ProfileTenantBindingNotFound, n1kv_db_v2.get_profile_binding, self.session, cisco_constants.TENANT_ID_NOT_SET, test_profile_id, ) self.assertNotEqual(binding.tenant_id, cisco_constants.TENANT_ID_NOT_SET)
def _create_test_binding_if_not_there(self, tenant_id, profile_id, profile_type): try: _binding = ( self.session.query(n1kv_models_v2.ProfileBinding) .filter_by(profile_type=profile_type, tenant_id=tenant_id, profile_id=profile_id) .one() ) except s_exc.NoResultFound: _binding = n1kv_db_v2.create_profile_binding(self.session, tenant_id, profile_id, profile_type) return _binding
def test_default_tenant_replace(self): ctx = context.get_admin_context() ctx.tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "AAAAAAAA-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "policy" n1kv_db_v2.create_profile_binding(cisco_constants.TENANT_ID_NOT_SET, test_profile_id, test_profile_type) network_profile = {"network_profile": TEST_NETWORK_PROFILE} test_network_profile = self.create_network_profile(ctx, network_profile) binding = n1kv_db_v2.get_profile_binding(ctx.tenant_id, test_profile_id) self.assertIsNone(n1kv_db_v2.get_profile_binding( cisco_constants.TENANT_ID_NOT_SET, test_profile_id)) self.assertNotEqual(binding.tenant_id, cisco_constants.TENANT_ID_NOT_SET) n1kv_db_v2.delete_network_profile(self.session, test_network_profile['id'])
def test_update_profile_binding(self): test_tenant_id = "d434dd90-76ec-11e2-bcfd-0800200c9a66" test_profile_id = "dd7b9741-76ec-11e2-bcfd-0800200c9a66" test_profile_type = "network" n1kv_db_v2.create_profile_binding(self.session, test_tenant_id, test_profile_id, test_profile_type) new_tenants = ['d434dd90-76ec-11e2-bcfd-0800200c9a67', 'd434dd90-76ec-11e2-bcfd-0800200c9a68', 'd434dd90-76ec-11e2-bcfd-0800200c9a69'] n1kv_db_v2.update_profile_binding(self.session, test_profile_id, new_tenants, test_profile_type) result = self.session.query(n1kv_models_v2.ProfileBinding).filter_by( profile_type=test_profile_type, profile_id=test_profile_id).all() self.assertEqual(3, len(result))
def _create_test_binding_if_not_there(self, tenant_id, profile_id, profile_type): try: _binding = (self.session.query( n1kv_models_v2.ProfileBinding).filter_by( profile_type=profile_type, tenant_id=tenant_id, profile_id=profile_id).one()) except s_exc.NoResultFound: _binding = n1kv_db_v2.create_profile_binding( self.session, tenant_id, profile_id, profile_type) return _binding