def test_profile_get_all(self): ids = ["profile1", "profile2"] for pid in ids: shared.create_profile(self.ctx, id=pid) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(2, len(profiles)) profile_ids = [p.id for p in profiles] for pid in ids: self.assertIn(pid, profile_ids) # test show_deleted here db_api.profile_delete(self.ctx, profiles[1].id) # after delete one of them profiles = db_api.profile_get_all(self.ctx) self.assertEqual(1, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=False) self.assertEqual(1, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=True) self.assertEqual(2, len(profiles)) # after delete both profiles db_api.profile_delete(self.ctx, profiles[0].id) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(0, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=True) self.assertEqual(2, len(profiles))
def test_profile_get_all(self): ids = ['profile1', 'profile2'] for pid in ids: shared.create_profile(self.ctx, id=pid) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(2, len(profiles)) profile_ids = [p.id for p in profiles] for pid in ids: self.assertIn(pid, profile_ids) # test show_deleted here db_api.profile_delete(self.ctx, profiles[1].id) # after delete one of them profiles = db_api.profile_get_all(self.ctx) self.assertEqual(1, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=False) self.assertEqual(1, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=True) self.assertEqual(2, len(profiles)) # after delete both profiles db_api.profile_delete(self.ctx, profiles[0].id) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(0, len(profiles)) profiles = db_api.profile_get_all(self.ctx, show_deleted=True) self.assertEqual(2, len(profiles))
def test_profile_delete_profile_used_by_node(self): profile = shared.create_profile(self.ctx) node = shared.create_node(self.ctx, None, profile) profile_id = profile.id ex = self.assertRaises(exception.ResourceBusyError, db_api.profile_delete, self.ctx, profile_id) self.assertEqual("The profile (%s) is busy now." % profile_id, six.text_type(ex)) db_api.node_delete(self.ctx, node.id) db_api.profile_delete(self.ctx, profile_id)
def test_profile_delete_profile_used_by_node(self): profile = shared.create_profile(self.ctx) node = shared.create_node(self.ctx, None, profile) profile_id = profile.id ex = self.assertRaises(exception.EResourceBusy, db_api.profile_delete, self.ctx, profile_id) self.assertEqual("The profile '%s' is busy now." % profile_id, str(ex)) db_api.node_delete(self.ctx, node.id) db_api.profile_delete(self.ctx, profile_id)
def test_profile_delete_profile_used_by_cluster(self): profile = shared.create_profile(self.ctx) cluster = shared.create_cluster(self.ctx, profile) profile_id = profile.id ex = self.assertRaises(exception.EResourceBusy, db_api.profile_delete, self.ctx, profile_id) self.assertEqual("The profile '%s' is busy now." % profile_id, str(ex)) db_api.cluster_delete(self.ctx, cluster.id) db_api.profile_delete(self.ctx, profile_id)
def test_profile_delete(self): profile = shared.create_profile(self.ctx) self.assertIsNotNone(profile) profile_id = profile.id db_api.profile_delete(self.ctx, profile_id) profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNone(profile) # not found in delete is okay res = db_api.profile_delete(self.ctx, profile_id) self.assertIsNone(res)
def test_profile_delete_profile_used_by_cluster(self): profile = shared.create_profile(self.ctx) cluster = shared.create_cluster(self.ctx, profile) profile_id = profile.id ex = self.assertRaises(exception.ResourceBusyError, db_api.profile_delete, self.ctx, profile_id) self.assertEqual('The profile (%s) is busy now.' % profile_id, six.text_type(ex)) db_api.cluster_delete(self.ctx, cluster.id) db_api.profile_delete(self.ctx, profile_id)
def test_profile_delete_profile_used_by_node(self): profile = shared.create_profile(self.ctx) node = shared.create_node(self.ctx, None, profile) profile_id = profile.id ex = self.assertRaises(exception.ResourceBusyError, db_api.profile_delete, self.ctx, profile_id) self.assertEqual('The profile (%s) is busy now.' % profile_id, six.text_type(ex)) db_api.node_delete(self.ctx, node.id) db_api.profile_delete(self.ctx, profile_id)
def test_profile_get_by_name_show_deleted(self): profile_name = "my_best_profile" profile_id = shared.create_profile(self.ctx, name=profile_name).id db_api.profile_delete(self.ctx, profile_id) # default case profile = db_api.profile_get_by_name(self.ctx, profile_name) self.assertIsNone(profile) # explicit false profile = db_api.profile_get_by_name(self.ctx, profile_name, show_deleted=False) self.assertIsNone(profile) # explicit true profile = db_api.profile_get_by_name(self.ctx, profile_name, show_deleted=True) self.assertIsNotNone(profile) self.assertEqual(profile_id, profile.id)
def test_profile_get_show_deleted(self): profile_id = shared.create_profile(self.ctx).id # check created profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNotNone(profile) # Now, delete it db_api.profile_delete(self.ctx, profile_id) # default equivalent to false profile = db_api.profile_get(self.ctx, profile_id) self.assertIsNone(profile) # explicit false profile = db_api.profile_get(self.ctx, profile_id, show_deleted=False) self.assertIsNone(profile) # explicit true profile = db_api.profile_get(self.ctx, profile_id, show_deleted=True) self.assertIsNotNone(profile) self.assertEqual(profile_id, profile.id)
def test_profile_get_all(self): ids = ['profile1', 'profile2'] for pid in ids: shared.create_profile(self.ctx, id=pid) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(2, len(profiles)) profile_ids = [p.id for p in profiles] for pid in ids: self.assertIn(pid, profile_ids) db_api.profile_delete(self.ctx, profiles[1].id) # after delete one of them profiles = db_api.profile_get_all(self.ctx) self.assertEqual(1, len(profiles)) # after delete both profiles db_api.profile_delete(self.ctx, profiles[0].id) profiles = db_api.profile_get_all(self.ctx) self.assertEqual(0, len(profiles))
def test_profile_get_by_name_show_deleted(self): profile_name = 'my_best_profile' profile_id = shared.create_profile(self.ctx, name=profile_name).id db_api.profile_delete(self.ctx, profile_id) # default case profile = db_api.profile_get_by_name(self.ctx, profile_name) self.assertIsNone(profile) # explicit false profile = db_api.profile_get_by_name(self.ctx, profile_name, show_deleted=False) self.assertIsNone(profile) # explicit true profile = db_api.profile_get_by_name(self.ctx, profile_name, show_deleted=True) self.assertIsNotNone(profile) self.assertEqual(profile_id, profile.id)