Allocation API: fix a small inconsistency
Currently the POST API returns "null" values for unspecified traits or candidate_nodes fields, while the subsequent GET API will return empty lists. This patch fixes it to always return empty lists. Change-Id: Ia3de56e97f63ef06a1115ae6328a626e327a64af Story: #2004341
This commit is contained in:
parent
506cb12160
commit
9741aed7be
|
@ -117,6 +117,12 @@ class Allocation(base.APIBase):
|
|||
if fields is not None:
|
||||
api_utils.check_for_invalid_fields(fields, allocation.fields)
|
||||
|
||||
# Make the default values consistent between POST and GET API
|
||||
if allocation.candidate_nodes is None:
|
||||
allocation.candidate_nodes = []
|
||||
if allocation.traits is None:
|
||||
allocation.traits = []
|
||||
|
||||
allocation = cls._convert_with_links(allocation,
|
||||
pecan.request.host_url)
|
||||
|
||||
|
|
|
@ -403,11 +403,15 @@ class TestPost(test_api_base.BaseApiTest):
|
|||
self.assertEqual(adict['uuid'], response.json['uuid'])
|
||||
self.assertEqual('allocating', response.json['state'])
|
||||
self.assertIsNone(response.json['node_uuid'])
|
||||
self.assertEqual([], response.json['candidate_nodes'])
|
||||
self.assertEqual([], response.json['traits'])
|
||||
result = self.get_json('/allocations/%s' % adict['uuid'],
|
||||
headers=self.headers)
|
||||
self.assertEqual(adict['uuid'], result['uuid'])
|
||||
self.assertFalse(result['updated_at'])
|
||||
self.assertIsNone(result['node_uuid'])
|
||||
self.assertEqual([], result['candidate_nodes'])
|
||||
self.assertEqual([], result['traits'])
|
||||
return_created_at = timeutils.parse_isotime(
|
||||
result['created_at']).replace(tzinfo=None)
|
||||
self.assertEqual(test_time, return_created_at)
|
||||
|
|
Loading…
Reference in New Issue