def test_from_db_object_to_cluster_object(self): """test conversion of database object to Cluster object.""" cluster = self.get_test_cluster() cue_cluster = objects.Cluster() db_cluster = models.Cluster() db_cluster.update(cluster) objects.Cluster._from_db_object(cue_cluster, db_cluster) test_utils.validate_cluster_values(self, cluster, cue_cluster)
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_create_cluster_size_three(self): """Tests create cluster of size three from Cluster objects API.""" test_cluster_dict = func_utils.get_test_cluster(size=3) new_cluster = objects.Cluster(**test_cluster_dict) test_utils.validate_cluster_values(self, test_cluster_dict, new_cluster) new_cluster.create(self.context) db_cluster = self.dbapi.get_cluster_by_id(self.context, new_cluster.id) test_utils.validate_cluster_values(self, new_cluster, db_cluster) cluster_nodes = self.dbapi.get_nodes_in_cluster( self.context, db_cluster.id) for nodes in cluster_nodes: self.assertEqual(db_cluster.id, nodes.cluster_id) self.assertEqual(db_cluster.flavor, nodes.flavor) self.assertEqual(db_cluster.status, nodes.status)
def test_create_cluster_size_one(self): """Tests create cluster from Cluster objects API.""" test_cluster_dict = func_utils.get_test_cluster(size=1) new_cluster = objects.Cluster(**test_cluster_dict) test_utils.validate_cluster_values(self, test_cluster_dict, new_cluster) new_cluster.create(self.context) db_cluster = self.dbapi.get_cluster_by_id(self.context, new_cluster.id) test_utils.validate_cluster_values(self, new_cluster, db_cluster) cluster_node = self.dbapi.get_nodes_in_cluster(self.context, db_cluster.id) # check if cluster size is one before accessing the node self.assertEqual(1, len(cluster_node)) self.assertEqual(db_cluster.id, cluster_node[0].cluster_id) self.assertEqual(db_cluster.flavor, cluster_node[0].flavor) self.assertEqual(db_cluster.status, cluster_node[0].status)
def test_cluster_api_to_object_to_api(self): """Tests Cluster api object conversion to Cluster object and back to api object. """ # create cluster api object api_cluster = func_utils.create_api_test_cluster_all().as_dict() # adjust network_id from list to single value api_cluster['network_id'] = api_cluster['network_id'][0] # create cue cluster object from api cluster object object_cluster = objects.Cluster(**api_cluster).as_dict() # verify fields match test_utils.validate_cluster_values(self, api_cluster, object_cluster) # adjust network_id from single value back to list object_cluster['network_id'] = [object_cluster['network_id']] # create cluster api object from cue cluster object api_cluster_2 = cluster.Cluster(**object_cluster).as_dict() # verify fields match to initial api cluster object test_utils.validate_cluster_values(self, api_cluster, api_cluster_2)
def test_cluster_db_to_object_to_db(self): """Tests Cluster db object conversion to Cluster object and back to db object. """ db_cluster_object = func_utils.create_db_test_cluster_model_object( self.context, deleted_at=timeutils.utcnow(), deleted=True) object_cluster = objects.Cluster._from_db_object( objects.Cluster(), db_cluster_object) test_utils.validate_cluster_values(self, db_cluster_object, object_cluster) self.validate_cluster_deleted_fields(db_cluster_object, object_cluster) cluster_changes = object_cluster.obj_get_changes() db_cluster_object_2 = models.Cluster() db_cluster_object_2.update(cluster_changes) test_utils.validate_cluster_values(self, db_cluster_object, db_cluster_object_2) self.validate_cluster_deleted_fields(db_cluster_object, db_cluster_object_2)
def test_cluster_object_to_dict(self): """test conversion of Cluster object to dict using as_dict.""" cluster = self.get_test_cluster() cluster_obj = objects.Cluster(**cluster) cluster_dict = cluster_obj.as_dict() test_utils.validate_cluster_values(self, cluster, cluster_dict)
def test_cluster_object_generation(self): """Test Cluster Object generation from a cluster dictionary object.""" cluster_dict = func_utils.get_test_cluster() cluster_object = objects.Cluster(**cluster_dict) test_utils.validate_cluster_values(self, cluster_dict, cluster_object)
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)