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_cluster_get_show_deleted(self): cluster = shared.create_cluster(self.ctx, self.profile) result = db_api.cluster_get(self.ctx, cluster.id) self.assertEqual(cluster.id, result.id) db_api.cluster_delete(self.ctx, cluster.id) result = db_api.cluster_get(self.ctx, cluster.id) self.assertIsNone(result) result = db_api.cluster_get(self.ctx, cluster.id, show_deleted=True) self.assertEqual(cluster.id, result.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_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_nested_cluster_get_by_name(self): cluster1 = shared.create_cluster(self.ctx, self.profile, name='cluster1') cluster2 = shared.create_cluster(self.ctx, self.profile, name='cluster2', parent=cluster1.id) result = db_api.cluster_get_by_name(self.ctx, 'cluster2') self.assertEqual(cluster2.id, result.id) db_api.cluster_delete(self.ctx, cluster2.id) result = db_api.cluster_get_by_name(self.ctx, 'cluster2') self.assertIsNone(result)
def test_cluster_get_all_show_deleted(self): clusters = [shared.create_cluster(self.ctx, self.profile) for x in range(3)] results = db_api.cluster_get_all(self.ctx) self.assertEqual(3, len(results)) db_api.cluster_delete(self.ctx, clusters[0].id) results = db_api.cluster_get_all(self.ctx) self.assertEqual(2, len(results)) results = db_api.cluster_get_all(self.ctx, show_deleted=True) self.assertEqual(3, len(results))
def test_cluster_count_all(self): clusters = [shared.create_cluster(self.ctx, self.profile) for i in range(3)] cl_db = db_api.cluster_count_all(self.ctx) self.assertEqual(3, cl_db) db_api.cluster_delete(self.ctx, clusters[0].id) cl_db = db_api.cluster_count_all(self.ctx) self.assertEqual(2, cl_db) db_api.cluster_delete(self.ctx, clusters[1].id) cl_db = db_api.cluster_count_all(self.ctx) self.assertEqual(1, cl_db)
def test_cluster_delete(self): cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id node = shared.create_node(self.ctx, cluster, self.profile) db_api.cluster_delete(self.ctx, cluster_id) self.assertIsNone(db_api.cluster_get(self.ctx, cluster_id)) res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res) self.assertRaises(exception.ResourceNotFound, db_api.cluster_delete, self.ctx, cluster_id) # Testing child nodes deletion res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res)
def test_cluster_delete(self): cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id node = shared.create_node(self.ctx, cluster, self.profile) db_api.cluster_delete(self.ctx, cluster_id) self.assertIsNone(db_api.cluster_get(self.ctx, cluster_id)) res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res) self.assertRaises(exception.ClusterNotFound, db_api.cluster_delete, self.ctx, cluster_id) # Testing child nodes deletion res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res)
def test_cluster_delete_policies_deleted(self): # create cluster cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id # create policy policy_data = { 'name': 'test_policy', 'type': 'ScalingPolicy', 'user': self.ctx.user, 'project': self.ctx.project, 'spec': {'foo': 'bar'}, 'level': 50, 'cooldown': 60, 'data': None, } policy = db_api.policy_create(self.ctx, policy_data) self.assertIsNotNone(policy) # attach policy fields = { 'enabled': True, 'priority': 77, } db_api.cluster_policy_attach(self.ctx, cluster_id, policy.id, fields) binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id) self.assertIsNotNone(binding) # now we delete the cluster db_api.cluster_delete(self.ctx, cluster_id) res = db_api.cluster_get(self.ctx, cluster_id) self.assertIsNone(res) # we check the cluster-policy binding binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id) self.assertIsNone(binding) # but the policy is not deleted result = db_api.policy_get(self.ctx, policy.id) self.assertIsNotNone(result)
def test_cluster_delete_policies_deleted(self): # create cluster cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id # create policy policy_data = { 'name': 'test_policy', 'type': 'ScalingPolicy', 'user': self.ctx.user_id, 'project': self.ctx.project_id, 'spec': { 'foo': 'bar' }, 'data': None, } policy = db_api.policy_create(self.ctx, policy_data) self.assertIsNotNone(policy) # attach policy fields = { 'enabled': True, } db_api.cluster_policy_attach(self.ctx, cluster_id, policy.id, fields) binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id) self.assertIsNotNone(binding) # now we delete the cluster db_api.cluster_delete(self.ctx, cluster_id) res = db_api.cluster_get(self.ctx, cluster_id) self.assertIsNone(res) # we check the cluster-policy binding binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id) self.assertIsNone(binding) # but the policy is not deleted result = db_api.policy_get(self.ctx, policy.id) self.assertIsNotNone(result)
def test_cluster_to_dict(self): cluster = self._create_cluster('CLUSTER123') self.assertIsNotNone(cluster.id) expected = { 'id': cluster.id, 'name': cluster.name, 'profile_id': cluster.profile_id, 'user': cluster.user, 'project': cluster.project, 'domain': cluster.domain, 'parent': cluster.parent, 'init_time': cluster.init_time, 'created_time': cluster.created_time, 'updated_time': cluster.updated_time, 'deleted_time': cluster.deleted_time, 'min_size': cluster.min_size, 'max_size': cluster.max_size, 'desired_capacity': cluster.desired_capacity, 'timeout': cluster.timeout, 'status': cluster.status, 'status_reason': cluster.status_reason, 'metadata': cluster.meta_data, 'data': cluster.data, 'nodes': [], 'policies': [], 'profile_name': self.profile.name, } result = clusterm.Cluster.load(self.context, cluster_id='CLUSTER123') self.assertEqual(expected, result.to_dict()) db_api.cluster_delete(self.context, cluster_id='CLUSTER123') result = clusterm.Cluster.load(self.context, cluster_id='CLUSTER123', show_deleted=True) expected.update({'profile_name': None}) expected.update({'status': 'DELETED'}) expected.update({'deleted_time': cluster.deleted_time.isoformat()}) expected.update({'status_reason': 'Cluster deletion succeeded'}) self.assertEqual(expected, result.to_dict())
def test_cluster_to_dict(self): cluster = self._create_cluster("CLUSTER123") self.assertIsNotNone(cluster.id) expected = { "id": cluster.id, "name": cluster.name, "profile_id": cluster.profile_id, "user": cluster.user, "project": cluster.project, "domain": cluster.domain, "parent": cluster.parent, "init_time": cluster.init_time, "created_time": cluster.created_time, "updated_time": cluster.updated_time, "deleted_time": cluster.deleted_time, "min_size": cluster.min_size, "max_size": cluster.max_size, "desired_capacity": cluster.desired_capacity, "timeout": cluster.timeout, "status": cluster.status, "status_reason": cluster.status_reason, "metadata": cluster.meta_data, "data": cluster.data, "nodes": [], "policies": [], "profile_name": self.profile.name, } result = clusterm.Cluster.load(self.context, cluster_id="CLUSTER123") self.assertEqual(expected, result.to_dict()) db_api.cluster_delete(self.context, cluster_id="CLUSTER123") result = clusterm.Cluster.load(self.context, cluster_id="CLUSTER123", show_deleted=True) expected.update({"profile_name": None}) expected.update({"status": "DELETED"}) expected.update({"deleted_time": cluster.deleted_time.isoformat()}) expected.update({"status_reason": "Cluster deletion succeeded"}) self.assertEqual(expected, result.to_dict())
def test_cluster_delete(self): cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id node = shared.create_node(self.ctx, cluster, self.profile) db_api.cluster_delete(self.ctx, cluster_id) self.assertIsNone(db_api.cluster_get(self.ctx, cluster_id, show_deleted=False)) res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res) self.assertRaises(exception.ClusterNotFound, db_api.cluster_delete, self.ctx, cluster_id) # Testing soft delete ret_cluster = db_api.cluster_get(self.ctx, cluster_id, show_deleted=True) self.assertIsNotNone(ret_cluster) self.assertEqual(cluster_id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name) # Testing child nodes deletion res = db_api.node_get(self.ctx, node.id) self.assertIsNone(res)