Merge "Change network_id argument to list type"
This commit is contained in:
commit
fdcef966e5
@ -79,7 +79,7 @@ class Cluster(base.APIBase):
|
||||
id = wtypes.text
|
||||
"UUID of cluster"
|
||||
|
||||
network_id = wtypes.wsattr(wtypes.text, mandatory=True)
|
||||
network_id = wtypes.wsattr([wtypes.text], mandatory=True)
|
||||
"NIC of Neutron network"
|
||||
|
||||
name = wsme.wsattr(wtypes.text, mandatory=True)
|
||||
@ -106,8 +106,13 @@ def get_complete_cluster(context, cluster_id):
|
||||
|
||||
cluster_obj = objects.Cluster.get_cluster_by_id(context, cluster_id)
|
||||
|
||||
cluster_as_dict = cluster_obj.as_dict()
|
||||
|
||||
# convert 'network_id' to list for ClusterDetails compatibility
|
||||
cluster_as_dict['network_id'] = [cluster_as_dict['network_id']]
|
||||
|
||||
# construct api cluster object
|
||||
cluster = Cluster(**cluster_obj.as_dict())
|
||||
cluster = Cluster(**cluster_as_dict)
|
||||
cluster.end_points = []
|
||||
|
||||
cluster_nodes = objects.Node.get_nodes_by_cluster_id(context, cluster_id)
|
||||
@ -202,8 +207,17 @@ class ClusterController(rest.RestController):
|
||||
_("Invalid cluster size, max size is: %d")
|
||||
% CONF.api.max_cluster_size)
|
||||
|
||||
if len(data.network_id) > 1:
|
||||
raise exception.Invalid(_("Invalid number of network_id's"))
|
||||
|
||||
data = data.as_dict()
|
||||
|
||||
# convert 'network_id' from list to string type for objects/cluster
|
||||
# compatibility
|
||||
data['network_id'] = data['network_id'][0]
|
||||
|
||||
# create new cluster object with required data from user
|
||||
new_cluster = objects.Cluster(**data.as_dict())
|
||||
new_cluster = objects.Cluster(**data)
|
||||
|
||||
# create new cluster with node related data from user
|
||||
new_cluster.create(context)
|
||||
@ -221,7 +235,7 @@ class ClusterController(rest.RestController):
|
||||
flow_kwargs = {
|
||||
'cluster_id': cluster.id,
|
||||
'node_ids': node_ids,
|
||||
'user_network_id': cluster.network_id,
|
||||
'user_network_id': cluster.network_id[0],
|
||||
'management_network_id': CONF.management_network_id,
|
||||
}
|
||||
|
||||
|
@ -25,17 +25,10 @@ class ClusterValidationMixin(object):
|
||||
|
||||
def validate_cluster_values(self, cluster_ref, cluster_cmp):
|
||||
self.assertEqual(cluster_ref.id if hasattr(cluster_ref, "id") else
|
||||
cluster_ref["id"],
|
||||
cluster_cmp.id if hasattr(cluster_cmp, "id") else
|
||||
cluster_cmp["id"],
|
||||
"Invalid cluster id value")
|
||||
self.assertEqual(cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"],
|
||||
cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"],
|
||||
"Invalid cluster network_id value")
|
||||
cluster_ref["id"],
|
||||
cluster_cmp.id if hasattr(cluster_cmp, "id") else
|
||||
cluster_cmp["id"],
|
||||
"Invalid cluster id value")
|
||||
self.assertEqual(cluster_ref.name if hasattr(cluster_ref, "name")
|
||||
else cluster_ref["name"],
|
||||
cluster_cmp.name if hasattr(cluster_cmp, "name")
|
||||
@ -63,15 +56,39 @@ class ClusterValidationMixin(object):
|
||||
"volume_size")
|
||||
else cluster_cmp["volume_size"],
|
||||
"Invalid cluster volume_size value")
|
||||
|
||||
self.assertEqual(unicode(cluster_ref.created_at.isoformat()),
|
||||
self.assertEqual(unicode(cluster_ref["created_at"].isoformat()),
|
||||
cluster_cmp["created_at"],
|
||||
"Invalid cluster created_at value")
|
||||
if cluster_ref.updated_at:
|
||||
self.assertEqual(unicode(cluster_ref.updated_at.isoformat()),
|
||||
|
||||
if cluster_ref["updated_at"] is not None:
|
||||
self.assertEqual(unicode(cluster_ref["updated_at"].isoformat()),
|
||||
cluster_cmp["updated_at"],
|
||||
"Invalid cluster updated_at value")
|
||||
|
||||
if isinstance((cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"]), (str, unicode)):
|
||||
cluster_ref['network_id'] = [cluster_ref['network_id']]
|
||||
|
||||
if isinstance((cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"]), (str, unicode)):
|
||||
cluster_cmp['network_id'] = [cluster_cmp['network_id']]
|
||||
|
||||
self.assertEqual(len(cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"]),
|
||||
len(cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"]),
|
||||
"Unequal number of cluster network_id")
|
||||
|
||||
for i, network_id in enumerate(cluster_ref.network_id if hasattr(
|
||||
cluster_ref, "network_id") else cluster_ref["network_id"]):
|
||||
self.assertEqual(network_id, cluster_cmp.network_id[i] if hasattr(
|
||||
cluster_cmp, "network_id") else cluster_cmp["network_id"][i],
|
||||
"Invalid cluster network_id value")
|
||||
|
||||
def validate_endpoint_values(self, endpoints_ref, endpoints_cmp):
|
||||
self.assertEqual(len(endpoints_ref), len(endpoints_cmp),
|
||||
"Invalid number of endpoints")
|
||||
|
@ -21,15 +21,20 @@ Tests for the API /cluster/ controller methods.
|
||||
|
||||
import uuid
|
||||
|
||||
from cue.db.sqlalchemy import api as db_api
|
||||
from cue.db.sqlalchemy import models
|
||||
from cue import objects
|
||||
from cue.tests.functional import api
|
||||
from cue.tests.functional.api import api_utils
|
||||
from cue.tests.functional import utils as test_utils
|
||||
|
||||
from oslo.config import cfg
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestGetCluster(api.APITest,
|
||||
api_utils.ClusterValidationMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(TestGetCluster, self).setUp()
|
||||
|
||||
@ -76,18 +81,18 @@ class TestGetCluster(api.APITest,
|
||||
|
||||
def test_get_cluster(self):
|
||||
"""test get cluster on valid existing cluster."""
|
||||
# create record for a new cluster in db
|
||||
cluster = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context, name=self.cluster_name, size=3)
|
||||
data = self.get_json('/clusters/' + cluster.id,
|
||||
self.context, name=self.cluster_name, size=3).as_dict()
|
||||
data = self.get_json('/clusters/' + cluster['id'],
|
||||
headers=self.auth_headers)
|
||||
|
||||
self.validate_cluster_values(cluster, data)
|
||||
|
||||
# verify all endpoints in cluster
|
||||
all_endpoints = test_utils.get_endpoints_in_cluster(self.context,
|
||||
cluster.id)
|
||||
self.validate_endpoint_values(all_endpoints,
|
||||
data["end_points"])
|
||||
cluster['id'])
|
||||
self.validate_endpoint_values(all_endpoints, data["end_points"])
|
||||
|
||||
|
||||
class TestDeleteCluster(api.APITest,
|
||||
@ -137,21 +142,23 @@ class TestDeleteCluster(api.APITest,
|
||||
cluster.id)
|
||||
self.assertEqual(models.Status.BUILDING, cluster_in_db.status,
|
||||
"Invalid cluster status value")
|
||||
self.delete('/clusters/' + cluster.id, headers=self.auth_headers)
|
||||
|
||||
self.delete('/clusters/' + cluster.id, headers=self.auth_headers)
|
||||
cluster_in_db = objects.Cluster.get_cluster_by_id(self.context,
|
||||
cluster.id)
|
||||
cluster.status = models.Status.DELETING
|
||||
cluster.updated_at = cluster_in_db.created_at
|
||||
cluster.created_at = cluster_in_db.created_at
|
||||
cluster.updated_at = cluster_in_db.updated_at
|
||||
|
||||
data = self.get_json('/clusters/' + cluster.id,
|
||||
data = self.get_json('/clusters/' + cluster['id'],
|
||||
headers=self.auth_headers)
|
||||
cluster = cluster.as_dict()
|
||||
self.validate_cluster_values(cluster, data)
|
||||
|
||||
|
||||
class TestListClusters(api.APITest,
|
||||
api_utils.ClusterValidationMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(TestListClusters, self).setUp()
|
||||
|
||||
@ -161,46 +168,42 @@ class TestListClusters(api.APITest,
|
||||
|
||||
def test_one(self):
|
||||
cluster = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name)
|
||||
self.context, name=self.cluster_name)
|
||||
data = self.get_json('/clusters', headers=self.auth_headers)
|
||||
|
||||
# verify number of clusters received
|
||||
self.assertEqual(len(data), 1, "Invalid number of clusters returned")
|
||||
|
||||
self.validate_cluster_values(cluster, data[0])
|
||||
# verify cluster
|
||||
self.validate_cluster_values(cluster.as_dict(), data[0])
|
||||
# verify endpoints in cluster
|
||||
all_endpoints = test_utils.get_endpoints_in_cluster(self.context,
|
||||
cluster.id)
|
||||
self.validate_endpoint_values(all_endpoints,
|
||||
data[0]["end_points"])
|
||||
|
||||
def test_multiple(self):
|
||||
cluster_0 = test_utils.create_db_test_cluster_from_objects_api(
|
||||
num_of_clusters = 5
|
||||
clusters = [test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_0')
|
||||
cluster_1 = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_1')
|
||||
cluster_2 = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_2')
|
||||
cluster_3 = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_3')
|
||||
cluster_4 = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_4')
|
||||
name=self.cluster_name + '_' + str(i), size=i + 1) for i in
|
||||
range(num_of_clusters)]
|
||||
|
||||
data = self.get_json('/clusters', headers=self.auth_headers)
|
||||
|
||||
self.assertEqual(len(data), 5,
|
||||
# verify number of clusters received
|
||||
self.assertEqual(len(data), num_of_clusters,
|
||||
"Invalid number of clusters returned")
|
||||
|
||||
self.validate_cluster_values(cluster_0, data[0])
|
||||
self.validate_cluster_values(cluster_1, data[1])
|
||||
self.validate_cluster_values(cluster_2, data[2])
|
||||
self.validate_cluster_values(cluster_3, data[3])
|
||||
self.validate_cluster_values(cluster_4, data[4])
|
||||
for i in range(num_of_clusters):
|
||||
# verify cluster
|
||||
self.validate_cluster_values(clusters[i].as_dict(), data[i])
|
||||
# verify endpoints in cluster
|
||||
all_endpoints = test_utils.get_endpoints_in_cluster(self.context,
|
||||
clusters[i].id)
|
||||
self.validate_endpoint_values(all_endpoints,
|
||||
data[i]["end_points"])
|
||||
|
||||
|
||||
class TestCreateCluster(api.APITest,
|
||||
api_utils.ClusterValidationMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCreateCluster, self).setUp()
|
||||
|
||||
@ -251,6 +254,21 @@ class TestCreateCluster(api.APITest,
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_too_large(self):
|
||||
"""test create cluster with size larger than limit."""
|
||||
api_cluster = test_utils.create_api_test_cluster(
|
||||
size=(CONF.api.max_cluster_size + 1))
|
||||
|
||||
data = self.post_json('/clusters', headers=self.auth_headers,
|
||||
params=api_cluster.as_dict(),
|
||||
expect_errors=True)
|
||||
self.assertEqual(413, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertIn('Invalid cluster size, max size is: ' +
|
||||
str(CONF.api.max_cluster_size),
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_size_one(self):
|
||||
"""test create a cluster with one node.
|
||||
|
||||
@ -260,13 +278,13 @@ class TestCreateCluster(api.APITest,
|
||||
api_cluster = test_utils.create_api_test_cluster(size=1)
|
||||
data = self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"])
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING,
|
||||
data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster.id,
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"]).as_dict()
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING, data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster['id'],
|
||||
headers=self.auth_headers)
|
||||
self.validate_cluster_values(cluster, data_api)
|
||||
self.assertEqual(models.Status.BUILDING, data_api['status'])
|
||||
@ -280,13 +298,13 @@ class TestCreateCluster(api.APITest,
|
||||
api_cluster = test_utils.create_api_test_cluster(size=3)
|
||||
data = self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"])
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING,
|
||||
data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster.id,
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"]).as_dict()
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING, data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster['id'],
|
||||
headers=self.auth_headers)
|
||||
self.validate_cluster_values(cluster, data_api)
|
||||
self.assertEqual(models.Status.BUILDING, data_api['status'])
|
||||
@ -305,6 +323,75 @@ class TestCreateCluster(api.APITest,
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_network_id_size_not_one(self):
|
||||
"""test create a cluster with size of network_id more than one."""
|
||||
api_cluster = test_utils.create_api_test_cluster(network_id=(
|
||||
[str(uuid.uuid4()), str(uuid.uuid4())]))
|
||||
|
||||
data = self.post_json('/clusters', headers=self.auth_headers,
|
||||
params=api_cluster.as_dict(),
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertIn("Invalid number of network_id's",
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_two_clusters_verify_time_stamps(self):
|
||||
"""test time stamps times at creation and delete."""
|
||||
api_cluster_1 = test_utils.create_api_test_cluster()
|
||||
api_cluster_2 = test_utils.create_api_test_cluster()
|
||||
|
||||
# Create two clusters
|
||||
data_1 = self.post_json('/clusters', params=api_cluster_1.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
data_2 = self.post_json('/clusters', params=api_cluster_2.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
|
||||
# retrieve cluster objects
|
||||
cluster_1 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_1.json["id"])
|
||||
cluster_2 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_2.json["id"])
|
||||
|
||||
# verify second cluster was created after first by created_at time
|
||||
self.assertEqual(True, cluster_2.created_at > cluster_1.created_at,
|
||||
"Second cluster was not created after first")
|
||||
|
||||
cluster_1_created_at = cluster_1.created_at
|
||||
|
||||
# issue delete request cluster for cluster_1
|
||||
self.delete('/clusters/' + data_1.json["id"],
|
||||
headers=self.auth_headers)
|
||||
|
||||
# retrieve cluster_1
|
||||
cluster_1 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_1.json["id"])
|
||||
|
||||
# verify updated_at time is after created_at
|
||||
self.assertEqual(True, cluster_1.updated_at > cluster_1.created_at,
|
||||
"Cluster updated at time is invalid")
|
||||
# verify created_at time did not change
|
||||
self.assertEqual(cluster_1_created_at, cluster_1.created_at,
|
||||
"Cluster created_at time has changed")
|
||||
|
||||
# delete cluster_1
|
||||
cluster = objects.Cluster(deleted=True, status=models.Status.DELETED)
|
||||
cluster.update(self.context, data_1.json["id"])
|
||||
|
||||
# retrieve deleted (soft) cluster
|
||||
cluster_query = db_api.model_query(self.context, models.Cluster,
|
||||
read_deleted=True).filter_by(
|
||||
id=data_1.json["id"])
|
||||
cluster_1 = cluster_query.one()
|
||||
|
||||
# verify deleted_at time is after created_at
|
||||
self.assertEqual(True, cluster_1.deleted_at > cluster_1.created_at,
|
||||
"Cluster deleted_at time is invalid")
|
||||
# verify updated_at time is after deleted_at
|
||||
self.assertEqual(True, cluster_1.updated_at > cluster_1.deleted_at,
|
||||
"Cluster deleted_at time is invalid")
|
||||
|
||||
def test_create_invalid_volume_size(self):
|
||||
"""test with invalid volume_size parameter."""
|
||||
|
||||
|
@ -1,269 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
Tests for the API /clusters/ controller methods.
|
||||
"""
|
||||
|
||||
from cue.db.sqlalchemy import api as db_api
|
||||
from cue.db.sqlalchemy import models
|
||||
from cue import objects
|
||||
from cue.tests.functional import api
|
||||
from cue.tests.functional.api import api_utils
|
||||
from cue.tests.functional import utils as test_utils
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestListClusters(api.APITest,
|
||||
api_utils.ClusterValidationMixin):
|
||||
def setUp(self):
|
||||
super(TestListClusters, self).setUp()
|
||||
|
||||
def test_empty(self):
|
||||
data = self.get_json('/clusters')
|
||||
self.assertEqual([], data)
|
||||
|
||||
def test_one(self):
|
||||
cluster = test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name)
|
||||
data = self.get_json('/clusters', headers=self.auth_headers)
|
||||
# verify number of clusters received
|
||||
self.assertEqual(len(data), 1, "Invalid number of clusters returned")
|
||||
# verify cluster
|
||||
self.validate_cluster_values(cluster, data[0])
|
||||
# verify endpoints in cluster
|
||||
all_endpoints = test_utils.get_endpoints_in_cluster(self.context,
|
||||
cluster.id)
|
||||
self.validate_endpoint_values(all_endpoints,
|
||||
data[0]["end_points"])
|
||||
|
||||
def test_multiple(self):
|
||||
num_of_clusters = 5
|
||||
clusters = [test_utils.create_db_test_cluster_from_objects_api(
|
||||
self.context,
|
||||
name=self.cluster_name + '_' + str(i), size=i + 1) for i in
|
||||
range(num_of_clusters)]
|
||||
|
||||
data = self.get_json('/clusters', headers=self.auth_headers)
|
||||
# verify number of clusters received
|
||||
self.assertEqual(len(data), num_of_clusters,
|
||||
"Invalid number of clusters returned")
|
||||
|
||||
for i in range(num_of_clusters):
|
||||
# verify cluster
|
||||
self.validate_cluster_values(clusters[i], data[i])
|
||||
# verify endpoints in cluster
|
||||
all_endpoints = test_utils.get_endpoints_in_cluster(self.context,
|
||||
clusters[i].id)
|
||||
self.validate_endpoint_values(all_endpoints,
|
||||
data[i]["end_points"])
|
||||
|
||||
|
||||
class TestCreateCluster(api.APITest,
|
||||
api_utils.ClusterValidationMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCreateCluster, self).setUp()
|
||||
|
||||
def test_create_empty_body(self):
|
||||
cluster_params = {}
|
||||
#header = {'Content-Type': 'application/json'}
|
||||
data = self.post_json('/clusters', params=cluster_params,
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertEqual('400 Bad Request', data.status,
|
||||
'Invalid status value received.')
|
||||
self.assertIn('Invalid input for field/attribute',
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_size_missing(self):
|
||||
"""test create an empty cluster."""
|
||||
api_cluster = test_utils.create_api_test_cluster(size=0)
|
||||
request_body = api_cluster.as_dict()
|
||||
|
||||
# remove size field
|
||||
del request_body['size']
|
||||
|
||||
data = self.post_json('/clusters', headers=self.auth_headers,
|
||||
params=request_body,
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertEqual('400 Bad Request', data.status,
|
||||
'Invalid status value received.')
|
||||
self.assertIn('Mandatory field missing',
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_size_zero(self):
|
||||
"""test create an empty cluster."""
|
||||
api_cluster = test_utils.create_api_test_cluster(size=0)
|
||||
|
||||
data = self.post_json('/clusters', headers=self.auth_headers,
|
||||
params=api_cluster.as_dict(),
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertEqual('400 Bad Request', data.status,
|
||||
'Invalid status value received.')
|
||||
self.assertIn('Invalid cluster size provided',
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_too_large(self):
|
||||
"""test create cluster with size larger than limit."""
|
||||
api_cluster = test_utils.create_api_test_cluster(
|
||||
size=(CONF.api.max_cluster_size + 1))
|
||||
|
||||
data = self.post_json('/clusters', headers=self.auth_headers,
|
||||
params=api_cluster.as_dict(),
|
||||
expect_errors=True)
|
||||
self.assertEqual(413, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertIn('Invalid cluster size, max size is: ' +
|
||||
str(CONF.api.max_cluster_size),
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_size_one(self):
|
||||
"""test create a cluster with one node.
|
||||
|
||||
Will verify cluster create from DB record then verifies cluster get
|
||||
returns the same cluster from the API.
|
||||
"""
|
||||
api_cluster = test_utils.create_api_test_cluster(size=1)
|
||||
data = self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"])
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING,
|
||||
data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster.id,
|
||||
headers=self.auth_headers)
|
||||
self.validate_cluster_values(cluster, data_api)
|
||||
self.assertEqual(models.Status.BUILDING, data_api['status'])
|
||||
|
||||
def test_create_size_three(self):
|
||||
"""test create a cluster with three nodes.
|
||||
|
||||
Will verify cluster create from DB record then verifies cluster get
|
||||
returns the same cluster from the API.
|
||||
"""
|
||||
api_cluster = test_utils.create_api_test_cluster(size=3)
|
||||
data = self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
cluster = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data.json["id"])
|
||||
self.validate_cluster_values(cluster, data.json)
|
||||
self.assertEqual(models.Status.BUILDING,
|
||||
data.json['status'])
|
||||
|
||||
data_api = self.get_json('/clusters/' + cluster.id,
|
||||
headers=self.auth_headers)
|
||||
self.validate_cluster_values(cluster, data_api)
|
||||
self.assertEqual(models.Status.BUILDING, data_api['status'])
|
||||
|
||||
def test_create_invalid_size_format(self):
|
||||
"""test with invalid formatted size parameter."""
|
||||
api_cluster = test_utils.create_api_test_cluster(size="a")
|
||||
|
||||
data = self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, expect_errors=True)
|
||||
self.assertEqual(500, data.status_code,
|
||||
'Invalid status code value received.')
|
||||
self.assertEqual('500 Internal Server Error', data.status,
|
||||
'Invalid status value received.')
|
||||
self.assertIn('invalid literal for int() with base 10:',
|
||||
data.namespace["faultstring"],
|
||||
'Invalid faultstring received.')
|
||||
|
||||
def test_create_two_clusters_verify_time_stamps(self):
|
||||
"""test time stamps times at creation and delete."""
|
||||
api_cluster_1 = test_utils.create_api_test_cluster()
|
||||
api_cluster_2 = test_utils.create_api_test_cluster()
|
||||
|
||||
# Create two clusters
|
||||
data_1 = self.post_json('/clusters', params=api_cluster_1.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
data_2 = self.post_json('/clusters', params=api_cluster_2.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
|
||||
# retrieve cluster objects
|
||||
cluster_1 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_1.json["id"])
|
||||
cluster_2 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_2.json["id"])
|
||||
|
||||
# verify second cluster was created after first by created_at time
|
||||
self.assertEqual(True, cluster_2.created_at > cluster_1.created_at,
|
||||
"Second cluster was not created after first")
|
||||
|
||||
cluster_1_created_at = cluster_1.created_at
|
||||
|
||||
# issue delete request cluster for cluster_1
|
||||
self.delete('/clusters/' + data_1.json["id"],
|
||||
headers=self.auth_headers)
|
||||
|
||||
# retrieve cluster_1
|
||||
cluster_1 = objects.Cluster.get_cluster_by_id(self.context,
|
||||
data_1.json["id"])
|
||||
|
||||
# verify updated_at time is after created_at
|
||||
self.assertEqual(True, cluster_1.updated_at > cluster_1.created_at,
|
||||
"Cluster updated at time is invalid")
|
||||
# verify created_at time did not change
|
||||
self.assertEqual(cluster_1_created_at, cluster_1.created_at,
|
||||
"Cluster created_at time has changed")
|
||||
|
||||
# delete cluster_1
|
||||
cluster = objects.Cluster(deleted=True, status=models.Status.DELETED)
|
||||
cluster.update(self.context, data_1.json["id"])
|
||||
|
||||
# retrieve deleted (soft) cluster
|
||||
cluster_query = db_api.model_query(self.context, models.Cluster,
|
||||
read_deleted=True).filter_by(
|
||||
id=data_1.json["id"])
|
||||
cluster_1 = cluster_query.one()
|
||||
|
||||
# verify deleted_at time is after created_at
|
||||
self.assertEqual(True, cluster_1.deleted_at > cluster_1.created_at,
|
||||
"Cluster deleted_at time is invalid")
|
||||
# verify updated_at time is after deleted_at
|
||||
self.assertEqual(True, cluster_1.updated_at > cluster_1.deleted_at,
|
||||
"Cluster deleted_at time is invalid")
|
||||
|
||||
def test_create_invalid_volume_size(self):
|
||||
"""test with invalid volume_size parameter."""
|
||||
|
||||
def test_create_invalid_parameter_set_id(self):
|
||||
"""test with invalid parameter set: id."""
|
||||
|
||||
def test_create_invalid_parameter_set_status(self):
|
||||
"""test with invalid parameter set: status."""
|
||||
|
||||
def test_create_invalid_parameter_set_created_at(self):
|
||||
"""test with invalid parameter set: created_at."""
|
||||
|
||||
def test_create_invalid_parameter_set_updated_at(self):
|
||||
"""test with invalid parameter set: updated_at."""
|
||||
|
||||
def test_create_invalid_parameter_set_deleted_at(self):
|
||||
"""test with invalid parameter set: deleted_at."""
|
@ -23,6 +23,7 @@ import mock
|
||||
from oslo.utils import timeutils
|
||||
import testtools
|
||||
|
||||
|
||||
from cue.api.controllers.v1 import cluster
|
||||
from cue.common import exception
|
||||
from cue.db import api as db_api
|
||||
@ -49,13 +50,6 @@ class ClusterObjectsTests(base.FunctionalTestCase):
|
||||
cluster_cmp.id if hasattr(cluster_cmp, "id") else
|
||||
cluster_cmp["id"],
|
||||
"Invalid cluster id value")
|
||||
self.assertEqual(cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"],
|
||||
cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"],
|
||||
"Invalid cluster network_id value")
|
||||
self.assertEqual(cluster_ref.name if hasattr(cluster_ref, "name")
|
||||
else cluster_ref["name"],
|
||||
cluster_cmp.name if hasattr(cluster_cmp, "name")
|
||||
@ -98,6 +92,24 @@ class ClusterObjectsTests(base.FunctionalTestCase):
|
||||
"updated_at")
|
||||
else cluster_cmp["updated_at"])
|
||||
|
||||
if not isinstance((cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"]), (str, unicode)):
|
||||
cluster_ref['network_id'] = cluster_ref['network_id'][0]
|
||||
|
||||
if not isinstance((cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"]), (str, unicode)):
|
||||
cluster_cmp['network_id'] = cluster_cmp['network_id'][0]
|
||||
|
||||
self.assertEqual(cluster_ref.network_id if hasattr(cluster_ref,
|
||||
"network_id")
|
||||
else cluster_ref["network_id"],
|
||||
cluster_cmp.network_id if hasattr(cluster_cmp,
|
||||
"network_id")
|
||||
else cluster_cmp["network_id"],
|
||||
"Invalid cluster network_id value")
|
||||
|
||||
def test_cluster_object_generation(self):
|
||||
"""Test Cluster Object generation from a cluster dictionary object."""
|
||||
cluster_dict = test_utils.get_test_cluster()
|
||||
@ -115,10 +127,20 @@ class ClusterObjectsTests(base.FunctionalTestCase):
|
||||
|
||||
to api object.
|
||||
"""
|
||||
api_cluster = test_utils.create_api_test_cluster_all()
|
||||
object_cluster = objects.Cluster(**api_cluster.as_dict())
|
||||
# create cluster api object
|
||||
api_cluster = test_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
|
||||
self.validate_cluster_values(api_cluster, object_cluster)
|
||||
api_cluster_2 = cluster.Cluster(**object_cluster.as_dict())
|
||||
|
||||
# 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
|
||||
self.validate_cluster_values(api_cluster, api_cluster_2)
|
||||
|
||||
def test_cluster_db_to_object_to_db(self):
|
||||
|
@ -12,11 +12,13 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import uuid
|
||||
|
||||
from oslo.utils import uuidutils
|
||||
import taskflow.patterns.linear_flow as linear_flow
|
||||
import taskflow.task
|
||||
|
||||
|
||||
import cue.taskflow.client as tf_client
|
||||
from cue.tests.functional import api
|
||||
from cue.tests.functional import base
|
||||
@ -88,7 +90,8 @@ class ApiTaskFlowClientTest(api.APITest):
|
||||
|
||||
def test_create_cluster_api(self):
|
||||
"""This test verifies create cluster job is posted from REST API."""
|
||||
api_cluster = test_utils.create_api_test_cluster(size=1)
|
||||
api_cluster = test_utils.create_api_test_cluster(size=1,
|
||||
network_id=[str(uuid.uuid4())])
|
||||
pre_count = self.tf_client.jobboard.job_count
|
||||
self.post_json('/clusters', params=api_cluster.as_dict(),
|
||||
headers=self.auth_headers, status=202)
|
||||
|
@ -51,6 +51,9 @@ def create_api_test_cluster(**kw):
|
||||
|
||||
test_cluster = get_test_cluster(**kw)
|
||||
|
||||
if isinstance(test_cluster['network_id'], (str, unicode)):
|
||||
test_cluster['network_id'] = [test_cluster['network_id']]
|
||||
|
||||
cluster_parameters = {
|
||||
'name': test_cluster['name'],
|
||||
'network_id': test_cluster['network_id'],
|
||||
@ -75,6 +78,9 @@ def create_api_test_cluster_all(**kw):
|
||||
|
||||
test_cluster = get_test_cluster(**kw)
|
||||
|
||||
if isinstance(test_cluster['network_id'], (str, unicode)):
|
||||
test_cluster['network_id'] = [test_cluster['network_id']]
|
||||
|
||||
cluster_parameters = {
|
||||
'name': test_cluster['name'],
|
||||
'network_id': test_cluster['network_id'],
|
||||
|
Loading…
Reference in New Issue
Block a user