def test_update_cluster_deleting_invalid_id(self): """Tests delete from Cluster objects API with invalid cluster id.""" func_utils.create_object_cluster(self.context) invalid_cluster_id = '17efe8ae-e93c-11e4-b02c-1681e6b88ec1' self.assertRaises(exception.NotFound, objects.Cluster.update_cluster_deleting, self.context, invalid_cluster_id)
def test_get_nonexistent_cluster(self): """Tests get cluster from Cluster objects API for nonexistent cluster. """ func_utils.create_object_cluster(self.context) nonexistent_cluster_id = '17efe8ae-e93c-11e4-b02c-1681e6b88ec1' self.assertRaises(exception.NotFound, objects.Cluster.get_cluster_by_id, self.context, nonexistent_cluster_id)
def test_get_node_by_id(self): """Tests get nodes by node id from Nodes objects API.""" new_cluster = func_utils.create_object_cluster(self.context) db_node = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) obj_node = objects.Node._from_db_object(objects.Node(), db_node[0]) node = objects.Node.get_node_by_id(self.context, obj_node.id) self.validate_node_values(obj_node, node)
def test_update_cluster_deleting(self): """Tests delete from Cluster objects API.""" new_cluster = func_utils.create_object_cluster(self.context) objects.Cluster.update_cluster_deleting(self.context, new_cluster.id) deleted_cluster = self.dbapi.get_cluster_by_id(self.context, new_cluster.id) self.assertEqual('DELETING', deleted_cluster.status)
def test_get_nodes_by_cluster_id(self): """Tests get nodes by cluster id from Node objects API.""" new_cluster = func_utils.create_object_cluster(self.context, size=2) db_nodes = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) node_list = objects.Node.get_nodes_by_cluster_id(self.context, new_cluster.id) for db_node, node in zip(db_nodes, node_list): self.validate_node_values(db_node, node)
def test_update_cluster_deleting_forbidden(self): """Tests delete from Cluster objects API with invalid tenant.""" api_cluster = func_utils.create_object_cluster(self.context) tenant_b = self.get_context(tenant='b') with mock.patch.object(objects.Cluster.dbapi, 'get_cluster_by_id', return_value=api_cluster): with testtools.ExpectedException(exception.NotAuthorized): cluster.delete_complete_cluster(tenant_b, api_cluster.id)
def test_get_endpoints_by_node_id(self): """Tests get endpoint by node id from Endpoint objects API.""" new_cluster = func_utils.create_object_cluster(self.context, size=1) cluster_node = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) node_id = cluster_node[0].id new_endpoint = self.create_object_endpoint(node_id) endpoint_list = objects.Endpoint.get_endpoints_by_node_id( self.context, new_endpoint.node_id) for endpoint in endpoint_list: self.validate_endpoint_values(endpoint, new_endpoint)
def test_update_node_size_one(self): """Tests update node from Node objects API.""" new_cluster = func_utils.create_object_cluster(self.context, size=1, flavor='flavor1') db_node = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) new_node = objects.Node._from_db_object(objects.Node(), db_node[0]) new_node.flavor = 'flavor2' new_node.update(self.context, new_node.id) updated_node = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id)[0] self.assertEqual('flavor2', updated_node.flavor)
def test_create_endpoint(self): """Tests create endpoint from Endpoint objects API.""" new_cluster = func_utils.create_object_cluster(self.context) cluster_nodes = self.dbapi.get_nodes_in_cluster( self.context, new_cluster.id) endpoint_dict = func_utils.get_test_endpoint_dict( node_id=cluster_nodes[0].id) endpoint = objects.Endpoint(**endpoint_dict) self.validate_endpoint_values(endpoint_dict, endpoint) endpoint.create(self.context) new_endpoint = self.dbapi.get_endpoints_in_node( self.context, endpoint.node_id) self.validate_endpoint_values(endpoint, new_endpoint[0])
def test_get_cluster_list_size_three(self): """Tests list Clusters of size three from Cluster objects API.""" cluster_list = list() for list_size in range(3): new_cluster = func_utils.create_object_cluster(self.context, id=str( uuid.uuid4())) cluster_list.append(new_cluster) returned_cluster_list = objects.Cluster.get_clusters(self.context) for returned_clusterobj, clusterobj in zip(returned_cluster_list, cluster_list): test_utils.validate_cluster_values(self, returned_clusterobj, clusterobj)
def test_update_endpoint_by_node_id(self): """Tests update endpoint by node id from Endpoint objects API.""" new_cluster = func_utils.create_object_cluster(self.context, size=1) cluster_node = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) cluster_node_id = cluster_node[0].id new_endpoint = self.create_object_endpoint(cluster_node_id, uri='10.0.0.1:5672', type='AMQP') endpoint_values = {'uri': '10.0.0.2:5672', 'type': 'XMPP'} objects.Endpoint.update_by_node_id(self.context, new_endpoint.node_id, endpoint_values) endpoints = self.dbapi.get_endpoints_in_node(self.context, new_endpoint.node_id) for endpoint in endpoints: self.assertEqual('XMPP', endpoint.type) self.assertEqual('10.0.0.2:5672', endpoint.uri)
def test_update_node_size_three(self): """Tests update three nodes from Node objects API.""" new_cluster = func_utils.create_object_cluster(self.context, size=3, flavor='flavor1') db_nodes = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) # check if cluster size is 3 self.assertEqual(3, len(db_nodes)) for current_node in db_nodes: current_node = objects.Node._from_db_object(objects.Node(), current_node) current_node.flavor = 'flavor2' current_node.update(self.context, current_node.id) updated_nodes = self.dbapi.get_nodes_in_cluster(self.context, new_cluster.id) for nodes in updated_nodes: self.assertEqual('flavor2', nodes.flavor)
def test_update_cluster(self): """Tests update cluster from Cluster objects API.""" new_cluster = func_utils.create_object_cluster(self.context, name='test_cluster', flavor='flavor1') new_cluster.flavor = 'flavor2' new_cluster.name = 'test_cluster1' new_cluster.update(self.context, new_cluster.id) updated_cluster = self.dbapi.get_cluster_by_id(self.context, new_cluster.id) # check update fields self.assertEqual('flavor2', updated_cluster.flavor) self.assertEqual('test_cluster1', updated_cluster.name) # check unchanged fields fields self.assertEqual(new_cluster.id, updated_cluster.id) self.assertEqual(new_cluster.network_id, updated_cluster.network_id) self.assertEqual(new_cluster.status, updated_cluster.status) self.assertEqual(new_cluster.size, updated_cluster.size)
def test_get_cluster_by_id(self): """Tests get Cluster by id from Cluster objects API.""" new_cluster = func_utils.create_object_cluster(self.context) test_cluster = objects.Cluster.get_cluster_by_id( self.context, new_cluster.id) test_utils.validate_cluster_values(self, new_cluster, test_cluster)
def test_get_cluster_list_size_one(self): """Tests list Cluster of size one from Cluster objects API.""" new_cluster = func_utils.create_object_cluster(self.context) cluster_list = objects.Cluster.get_clusters(self.context) test_utils.validate_cluster_values(self, cluster_list[0], new_cluster)