A bay without name should be successfully created

Magnum Client can successfully create a bay without name. But when use
curl, it returned 500. This patch fix this.

Change-Id: Ic35c411914d81f1521f4b6051497efaf13772b37
Closes-Bug: #1532918
This commit is contained in:
houming-wang 2016-01-12 03:53:15 -05:00
parent fbb0151fd5
commit a88757326c
2 changed files with 11 additions and 0 deletions

View File

@ -284,6 +284,8 @@ class BaysController(rest.RestController):
# NOTE(suro-patz): Apply default node_count is 1, None -> 1
if bay_dict.get('node_count', None) is None:
bay_dict['node_count'] = 1
if bay_dict.get('name', None) is None:
bay_dict['name'] = None
new_bay = objects.Bay(context, **bay_dict)
res_bay = pecan.request.rpcapi.bay_create(new_bay,

View File

@ -535,6 +535,15 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['error_message'])
@mock.patch('magnum.api.attr_validator.validate_os_resources')
def test_create_bay_without_name(self, mock_valid_os_res):
bdict = apiutils.bay_post_data()
del bdict['name']
mock_valid_os_res.return_value = None
response = self.post_json('/bays', bdict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_os_resources')
def test_create_bay_with_timeout_none(self, mock_valid_os_res):
bdict = apiutils.bay_post_data()