def _deleted_cluster_existance(self, ctx, clusters, existing, deleted): for s in existing: self.assertIsNotNone(db_api.cluster_get(ctx, clusters[s].id, show_deleted=True)) for s in deleted: self.assertIsNone(db_api.cluster_get(ctx, clusters[s].id, show_deleted=True))
def test_cluster_get_from_different_project(self): cluster = shared.create_cluster(self.ctx, self.profile) self.ctx.project = 'abc' ret_cluster = db_api.cluster_get(self.ctx, cluster.id, project_safe=False) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name) cluster = db_api.cluster_get(self.ctx, cluster.id) self.assertIsNone(cluster)
def test_cluster_get_from_different_tenant(self): cluster = shared.create_cluster(self.ctx, self.profile) self.ctx.tenant_id = 'abc' ret_cluster = db_api.cluster_get(self.ctx, cluster.id, show_deleted=False, tenant_safe=False) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name) cluster = db_api.cluster_get(self.ctx, cluster.id, show_deleted=False) self.assertIsNone(cluster)
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_cluster_get_with_admin_context(self): cluster = shared.create_cluster(self.ctx, self.profile) admin_ctx = utils.dummy_context(project='another-project', is_admin=True) ret_cluster = db_api.cluster_get(admin_ctx, cluster.id, project_safe=True) self.assertIsNone(ret_cluster) ret_cluster = db_api.cluster_get(admin_ctx, cluster.id, project_safe=False) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name)
def test_cluster_remove_dependents(self): deps = {'profiles': ['profile1', 'profile2']} cluster = shared.create_cluster(self.ctx, self.profile, dependents=deps) db_api.cluster_remove_dependents(self.ctx, cluster.id, 'profile1') res = db_api.cluster_get(self.ctx, cluster.id) deps = {'profiles': ['profile2']} self.assertEqual(deps, res.dependents) db_api.cluster_remove_dependents(self.ctx, cluster.id, 'profile2') res = db_api.cluster_get(self.ctx, cluster.id) deps = {} self.assertEqual(deps, res.dependents)
def test_cluster_next_index(self): cluster = shared.create_cluster(self.ctx, self.profile) cluster_id = cluster.id res = db_api.cluster_get(self.ctx, cluster_id) self.assertEqual(1, res.next_index) res = db_api.cluster_next_index(self.ctx, cluster_id) self.assertEqual(1, res) res = db_api.cluster_get(self.ctx, cluster_id) self.assertEqual(2, res.next_index) res = db_api.cluster_next_index(self.ctx, cluster_id) self.assertEqual(2, res) res = db_api.cluster_get(self.ctx, cluster_id) self.assertEqual(3, res.next_index)
def test_node_delete(self): node = shared.create_node(self.ctx, self.cluster, self.profile) node_id = node.id cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(1, cluster.size) db_api.node_delete(self.ctx, node_id) res = db_api.node_get(self.ctx, node_id) self.assertIsNone(res) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(0, cluster.size)
def test_cluster_get_returns_a_cluster(self): cluster = shared.create_cluster(self.ctx, self.profile) ret_cluster = db_api.cluster_get(self.ctx, cluster.id, show_deleted=False) self.assertIsNotNone(ret_cluster) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name)
def test_store_for_create(self): cluster = clusterm.Cluster('test-cluster', 0, 'PROFILE_ID', user=self.context.user, project=self.context.project) mock_load = self.patchobject(cluster, '_load_runtime_data') self.assertIsNone(cluster.id) cluster_id = cluster.store(self.context) self.assertIsNotNone(cluster_id) mock_load.assert_called_once_with(self.context) result = db_api.cluster_get(self.context, cluster_id=cluster_id) self.assertIsNotNone(result) self.assertEqual('test-cluster', result.name) self.assertEqual('PROFILE_ID', result.profile_id) self.assertEqual(self.context.user, result.user) self.assertEqual(self.context.project, result.project) self.assertEqual(self.context.domain, result.domain) self.assertIsNotNone(result.init_at) self.assertIsNone(result.created_at) self.assertIsNone(result.updated_at) self.assertEqual(0, result.min_size) self.assertEqual(-1, result.max_size) self.assertEqual(0, result.desired_capacity) self.assertEqual(1, result.next_index) self.assertEqual(cfg.CONF.default_action_timeout, result.timeout) self.assertEqual('INIT', result.status) self.assertEqual('Initializing', result.status_reason) self.assertEqual({}, result.data) self.assertEqual({}, result.meta_data)
def test_cluster_get_with_admin_context(self): cluster = shared.create_cluster(self.ctx, self.profile) admin_ctx = utils.dummy_context(project='another-project', is_admin=True) ret_cluster = db_api.cluster_get(admin_ctx, cluster.id, project_safe=True) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name)
def test_cluster_add_dependents(self): cluster = shared.create_cluster(self.ctx, self.profile) profile_id = 'profile1' db_api.cluster_add_dependents(self.ctx, cluster.id, profile_id) res = db_api.cluster_get(self.ctx, cluster.id) self.assertEqual(['profile1'], res.dependents['profiles']) deps = {} cluster = shared.create_cluster(self.ctx, self.profile, dependents=deps) db_api.cluster_add_dependents(self.ctx, cluster.id, profile_id) res = db_api.cluster_get(self.ctx, cluster.id) deps = {'profiles': ['profile1']} self.assertEqual(deps, res.dependents) db_api.cluster_add_dependents(self.ctx, cluster.id, 'profile2') res = db_api.cluster_get(self.ctx, cluster.id) deps = {'profiles': ['profile1', 'profile2']} self.assertEqual(deps, res.dependents)
def test_node_migrate_to_none(self): node = shared.create_node(self.ctx, self.cluster, self.profile) timestamp = datetime.datetime.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, None, timestamp) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(timestamp, node_new.updated_time) self.assertIsNone(node_new.cluster_id) self.assertEqual(0, cluster.size)
def test_node_migrate_between_clusters(self): cluster1 = shared.create_cluster(self.ctx, self.profile) cluster2 = shared.create_cluster(self.ctx, self.profile) node = shared.create_node(self.ctx, cluster1, self.profile) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) self.assertEqual(2, cluster1.next_index) self.assertEqual(1, cluster2.next_index) timestamp = tu.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_at) self.assertEqual(cluster2.id, node_new.cluster_id) self.assertIsNone(node_new.role) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(0, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(1, len(nodes)) self.assertEqual(2, cluster1.next_index) self.assertEqual(2, cluster2.next_index) # Migrate it back! timestamp = tu.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id, timestamp, 'FAKE-ROLE') cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_at) self.assertEqual(cluster1.id, node_new.cluster_id) self.assertEqual('FAKE-ROLE', node_new.role) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) self.assertEqual(3, cluster1.next_index) self.assertEqual(2, cluster2.next_index)
def test_node_migrate_between_clusters(self): cluster1 = shared.create_cluster(self.ctx, self.profile) cluster2 = shared.create_cluster(self.ctx, self.profile) node = shared.create_node(self.ctx, cluster1, self.profile) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) self.assertEqual(2, cluster1.next_index) self.assertEqual(1, cluster2.next_index) timestamp = tu.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_time) self.assertEqual(cluster2.id, node_new.cluster_id) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(0, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(1, len(nodes)) self.assertEqual(2, cluster1.next_index) self.assertEqual(2, cluster2.next_index) # Migrate it back! timestamp = tu.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_time) self.assertEqual(cluster1.id, node_new.cluster_id) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) self.assertEqual(3, cluster1.next_index) self.assertEqual(2, cluster2.next_index)
def test_node_migrate_from_none(self): node_orphan = shared.create_node(self.ctx, None, self.profile) timestamp = datetime.datetime.utcnow() node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id, timestamp) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(timestamp, node.updated_time) self.assertEqual(self.cluster.id, node.cluster_id) self.assertEqual(2, cluster.next_index) self.assertEqual(1, cluster.size)
def test_node_migrate_from_none(self): node_orphan = shared.create_node(self.ctx, None, self.profile) timestamp = tu.utcnow() node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id, timestamp) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(timestamp, node.updated_time) self.assertEqual(self.cluster.id, node.cluster_id) self.assertEqual(2, cluster.next_index) nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id) self.assertEqual(1, len(nodes))
def test_node_create(self): cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(0, cluster.size) res = shared.create_node(self.ctx, self.cluster, self.profile) node = db_api.node_get(self.ctx, res.id) self.assertIsNotNone(node) self.assertEqual('test_node_name', node.name) self.assertEqual(UUID1, node.physical_id) self.assertEqual(0, node.index) self.assertIsNone(node.role) self.assertIsNone(node.created_time) self.assertIsNone(node.updated_time) self.assertIsNone(node.deleted_time) self.assertEqual('ACTIVE', node.status) self.assertEqual('create complete', node.status_reason) self.assertEqual('{"foo": "123"}', json.dumps(node.tags)) self.assertEqual('{"key1": "value1"}', json.dumps(node.data)) self.assertEqual(self.cluster.id, node.cluster_id) self.assertEqual(self.profile.id, node.profile_id) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(1, cluster.size)
def test_node_migrate_from_none(self): node_orphan = shared.create_node(self.ctx, None, self.profile) timestamp = tu.utcnow() node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id, timestamp, 'NEW-ROLE') cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual(timestamp, node.updated_at) self.assertEqual(self.cluster.id, node.cluster_id) self.assertEqual(2, cluster.next_index) nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id) self.assertEqual(1, len(nodes)) self.assertEqual('NEW-ROLE', nodes[0].role)
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)
def test_node_update_cluster_status_updated(self): cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual('INIT', cluster.status) node = shared.create_node(self.ctx, self.cluster, self.profile) new_attributes = { 'name': 'new_name', 'status': 'ERROR', 'status_reason': 'Something is wrong', } db_api.node_update(self.ctx, node.id, new_attributes) node = db_api.node_get(self.ctx, node.id) self.assertEqual('new_name', node.name) self.assertEqual('ERROR', node.status) self.assertEqual('Something is wrong', node.status_reason) cluster = db_api.cluster_get(self.ctx, self.cluster.id) self.assertEqual('WARNING', cluster.status) reason = 'Node new_name: Something is wrong' self.assertEqual(reason, cluster.status_reason)
def test_node_migrate_between_clusters(self): cluster1 = shared.create_cluster(self.ctx, self.profile) cluster2 = shared.create_cluster(self.ctx, self.profile) node = shared.create_node(self.ctx, cluster1, self.profile) self.assertEqual(1, cluster1.size) self.assertEqual(0, cluster2.size) self.assertEqual(2, cluster1.next_index) self.assertEqual(1, cluster2.next_index) timestamp = datetime.datetime.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_time) self.assertEqual(cluster2.id, node_new.cluster_id) self.assertEqual(0, cluster1.size) self.assertEqual(1, cluster2.size) self.assertEqual(2, cluster1.next_index) self.assertEqual(2, cluster2.next_index) # Migrate it back! timestamp = datetime.datetime.utcnow() node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_time) self.assertEqual(cluster1.id, node_new.cluster_id) self.assertEqual(1, cluster1.size) self.assertEqual(0, cluster2.size) self.assertEqual(3, cluster1.next_index) self.assertEqual(2, cluster2.next_index)
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(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_get_next_index(self): cluster = shared.create_cluster(self.ctx, self.profile, name='cluster_next_index') index = db_api.cluster_get_next_index(self.ctx, cluster.id) self.assertEqual(1, index) index = db_api.cluster_get_next_index(self.ctx, cluster.id) self.assertEqual(2, index) cluster = db_api.cluster_get(self.ctx, cluster.id) self.assertEqual(3, cluster.next_index) index = db_api.cluster_get_next_index(self.ctx, 'bad-id') self.assertIsNone(index)
def test_cluster_update(self): cluster = shared.create_cluster(self.ctx, self.profile) values = { 'name': 'db_test_cluster_name2', 'status': 'ERROR', 'status_reason': "update failed", 'timeout': 90, } db_api.cluster_update(self.ctx, cluster.id, values) cluster = db_api.cluster_get(self.ctx, cluster.id) self.assertEqual('db_test_cluster_name2', cluster.name) self.assertEqual('ERROR', cluster.status) self.assertEqual('update failed', cluster.status_reason) self.assertEqual(90, cluster.timeout) self.assertRaises(exception.ClusterNotFound, db_api.cluster_update, self.ctx, UUID2, values)
def test_cluster_update(self): cluster = shared.create_cluster(self.ctx, self.profile) values = { 'name': 'db_test_cluster_name2', 'status': 'ERROR', 'status_reason': "update failed", 'timeout': 90, } db_api.cluster_update(self.ctx, cluster.id, values) cluster = db_api.cluster_get(self.ctx, cluster.id) self.assertEqual('db_test_cluster_name2', cluster.name) self.assertEqual('ERROR', cluster.status) self.assertEqual('update failed', cluster.status_reason) self.assertEqual(90, cluster.timeout) self.assertRaises(exception.ResourceNotFound, db_api.cluster_update, self.ctx, UUID2, values)
def test_cluster_store_update(self): mock_info = self.patchobject(eventm, 'info') cluster = clusterm.Cluster('test-cluster', 0, self.profile.id, user=self.context.user, project=self.context.project) self.assertIsNone(cluster.id) cluster_id = cluster.store(self.context) self.assertIsNotNone(cluster_id) mock_info.assert_called_once_with(self.context, cluster, 'create') mock_info.reset_mock() # do an update cluster.name = 'test-cluster-1' cluster.parent = 'another-cluster' cluster.min_size = 1 cluster.max_size = 3 cluster.desired_capacity = 2 cluster.timeout = 120 cluster.data = {'FOO': 'BAR'} cluster.metadata = {'KEY': 'VALUE'} new_id = cluster.store(self.context) self.assertEqual(cluster_id, new_id) result = db_api.cluster_get(self.context, cluster_id) self.assertIsNotNone(result) self.assertEqual('test-cluster-1', result.name) self.assertEqual(self.context.user, result.user) self.assertEqual(self.context.project, result.project) self.assertEqual('another-cluster', result.parent) self.assertEqual(1, result.min_size) self.assertEqual(3, result.max_size) self.assertEqual(2, result.desired_capacity) self.assertEqual(120, result.timeout) self.assertEqual({'FOO': 'BAR'}, result.data) self.assertEqual({'KEY': 'VALUE'}, result.meta_data) mock_info.assert_called_once_with(self.context, cluster, 'update')
def test_cluster_store_update(self): mock_info = self.patchobject(eventm, "info") cluster = clusterm.Cluster( "test-cluster", 0, self.profile.id, user=self.context.user, project=self.context.project ) self.assertIsNone(cluster.id) cluster_id = cluster.store(self.context) self.assertIsNotNone(cluster_id) mock_info.assert_called_once_with(self.context, cluster, "create") mock_info.reset_mock() # do an update cluster.name = "test-cluster-1" cluster.parent = "another-cluster" cluster.min_size = 1 cluster.max_size = 3 cluster.desired_capacity = 2 cluster.timeout = 120 cluster.data = {"FOO": "BAR"} cluster.metadata = {"KEY": "VALUE"} new_id = cluster.store(self.context) self.assertEqual(cluster_id, new_id) result = db_api.cluster_get(self.context, cluster_id) self.assertIsNotNone(result) self.assertEqual("test-cluster-1", result.name) self.assertEqual(self.context.user, result.user) self.assertEqual(self.context.project, result.project) self.assertEqual("another-cluster", result.parent) self.assertEqual(1, result.min_size) self.assertEqual(3, result.max_size) self.assertEqual(2, result.desired_capacity) self.assertEqual(120, result.timeout) self.assertEqual({"FOO": "BAR"}, result.data) self.assertEqual({"KEY": "VALUE"}, result.meta_data) mock_info.assert_called_once_with(self.context, cluster, "update")
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_node_migrate_between_clusters(self): cluster1 = shared.create_cluster(self.ctx, self.profile) cluster2 = shared.create_cluster(self.ctx, self.profile) node = shared.create_node(self.ctx, cluster1, self.profile) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) # Refresh cluster1 and cluster2 cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(2, cluster1.next_index) self.assertEqual(1, cluster2.next_index) timestamp = tu.utcnow(True) node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id, timestamp) cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_at) self.assertEqual(cluster2.id, node_new.cluster_id) self.assertIsNone(node_new.role) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(0, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(1, len(nodes)) self.assertEqual(2, cluster1.next_index) self.assertEqual(2, cluster2.next_index) # Migrate it back! timestamp = tu.utcnow(True) node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id, timestamp, 'FAKE-ROLE') cluster1 = db_api.cluster_get(self.ctx, cluster1.id) cluster2 = db_api.cluster_get(self.ctx, cluster2.id) self.assertEqual(timestamp, node_new.updated_at) self.assertEqual(cluster1.id, node_new.cluster_id) self.assertEqual('FAKE-ROLE', node_new.role) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id) self.assertEqual(1, len(nodes)) nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id) self.assertEqual(0, len(nodes)) self.assertEqual(3, cluster1.next_index) self.assertEqual(2, cluster2.next_index)
def test_store_for_update(self): cluster = clusterm.Cluster('test-cluster', 0, 'PROFILE_ID', user=self.context.user, project=self.context.project) mock_load = self.patchobject(cluster, '_load_runtime_data') self.assertIsNone(cluster.id) cluster_id = cluster.store(self.context) self.assertIsNotNone(cluster_id) mock_load.assert_called_once_with(self.context) # do an update cluster.name = 'test-cluster-1' cluster.min_size = 1 cluster.max_size = 3 cluster.desired_capacity = 2 cluster.timeout = 120 cluster.data = {'FOO': 'BAR'} cluster.metadata = {'KEY': 'VALUE'} new_id = cluster.store(self.context) self.assertEqual(cluster_id, new_id) result = db_api.cluster_get(self.context, cluster_id) self.assertIsNotNone(result) self.assertEqual('test-cluster-1', result.name) self.assertEqual(self.context.user, result.user) self.assertEqual(self.context.project, result.project) self.assertEqual(1, result.min_size) self.assertEqual(3, result.max_size) self.assertEqual(2, result.desired_capacity) self.assertEqual(120, result.timeout) self.assertEqual({'FOO': 'BAR'}, result.data) self.assertEqual({'KEY': 'VALUE'}, result.meta_data)
def test_cluster_store_init(self): mock_info = self.patchobject(eventm, 'info') cluster = clusterm.Cluster('test-cluster', 0, self.profile.id, user=self.context.user, project=self.context.project) self.assertIsNone(cluster.id) cluster_id = cluster.store(self.context) self.assertIsNotNone(cluster_id) result = db_api.cluster_get(self.context, cluster_id=cluster_id) self.assertIsNotNone(result) self.assertEqual('test-cluster', result.name) self.assertEqual(self.profile.id, result.profile_id) self.assertEqual(self.context.user, result.user) self.assertEqual(self.context.project, result.project) self.assertEqual('', result.domain) self.assertEqual('', result.parent) self.assertIsNotNone(result.init_time) self.assertIsNone(result.created_time) self.assertIsNone(result.updated_time) self.assertIsNone(result.deleted_time) self.assertEqual(0, result.min_size) self.assertEqual(-1, result.max_size) self.assertEqual(0, result.desired_capacity) self.assertEqual(1, result.next_index) self.assertEqual(cfg.CONF.default_action_timeout, result.timeout) self.assertEqual('INIT', result.status) self.assertEqual('Initializing', result.status_reason) self.assertEqual({}, result.data) self.assertEqual({}, result.meta_data) mock_info.assert_called_once_with(self.context, cluster, 'create')
def test_cluster_get_not_found(self): cluster = db_api.cluster_get(self.ctx, UUID1, show_deleted=False) self.assertIsNone(cluster)
def test_cluster_get_returns_a_cluster(self): cluster = shared.create_cluster(self.ctx, self.profile) ret_cluster = db_api.cluster_get(self.ctx, cluster.id) self.assertIsNotNone(ret_cluster) self.assertEqual(cluster.id, ret_cluster.id) self.assertEqual('db_test_cluster_name', ret_cluster.name)
def test_cluster_get_not_found(self): cluster = db_api.cluster_get(self.ctx, UUID1) self.assertIsNone(cluster)