Fix cluster inheritence of docker_volume_size

Following [1], cluster objects have a docker_volume_size attribute.
If not explicitly set on creation, the value of this attribute should
default to the value of the same field on the cluster's template.

When not provided, the API Cluster object's docker_volume_size field
takes the value wsme.Unset, rather than None.

[1]
79039bb419

Change-Id: Iad5231643c01ec9698c932b59806781034390795
Depends-On: I510ff10d708a237be0cb88d3ff7094d7c81f5875
Closes-Bug: #1702314
This commit is contained in:
Mark Goddard 2017-07-04 15:27:03 +01:00
parent 2e7e5a7796
commit f055d1691d
4 changed files with 24 additions and 2 deletions

View File

@ -421,7 +421,7 @@ class BaysController(base.Controller):
bay.baymodel_id)
# If docker_volume_size is not present, use baymodel value
if bay.docker_volume_size is None:
if bay.docker_volume_size == wtypes.Unset:
bay.docker_volume_size = baymodel.docker_volume_size
bay_dict = bay.as_dict()

View File

@ -400,7 +400,7 @@ class ClustersController(base.Controller):
cluster.keypair = cluster_template.keypair_id
# If docker_volume_size is not present, use cluster_template value
if cluster.docker_volume_size is None:
if cluster.docker_volume_size == wtypes.Unset:
cluster.docker_volume_size = cluster_template.docker_volume_size
cluster_dict = cluster.as_dict()

View File

@ -788,6 +788,26 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
def test_create_bay_with_docker_volume_size(self):
bdict = apiutils.bay_post_data()
bdict['docker_volume_size'] = 3
response = self.post_json('/bays', bdict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
bay, timeout = self.mock_bay_create.call_args
self.assertEqual(3, bay[0].docker_volume_size)
def test_create_bay_without_docker_volume_size(self):
bdict = apiutils.bay_post_data()
# Remove the default docker_volume_size from the bay dict.
del bdict['docker_volume_size']
response = self.post_json('/bays', bdict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
bay, timeout = self.mock_bay_create.call_args
# Verify docker_volume_size from BayModel is used
self.assertEqual(20, bay[0].docker_volume_size)
class TestDelete(api_base.FunctionalTest):

View File

@ -792,6 +792,8 @@ class TestPost(api_base.FunctionalTest):
def test_create_cluster_without_docker_volume_size(self):
bdict = apiutils.cluster_post_data()
# Remove the default docker_volume_size from the cluster dict.
del bdict['docker_volume_size']
response = self.post_json('/clusters', bdict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(202, response.status_int)