Fix ZTA API to prevent HTTP 500 upon empty body

2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware   File "/opt/stack/new/designate/designate/api/v2/controllers/zones/tasks/transfer_requests.py", line 92, in post_all
    2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware     body['zone_name'] = zone.name
    2016-08-25 13:20:34.576 28114 ERROR designate.api.middleware TypeError: 'NoneType' object does not support item assignment

Needed for the new ZTA tempest tests

Change-Id: I5fdefa64480f118dad898ed4651036f9b9b16fe9
Needed-By: I843701655f3fd07245b79e37fa286f05f20bf7a3
This commit is contained in:
Kiall Mac Innes 2016-08-25 15:48:06 +01:00
parent 86fcdd48e8
commit 6ac58041dd
2 changed files with 16 additions and 2 deletions

View File

@ -39,9 +39,13 @@ class Request(pecan.core.Request):
"""
if self.content_type in JSON_TYPES:
try:
return jsonutils.load(self.body_file)
json_dict = jsonutils.load(self.body_file)
if json_dict is None:
# NOTE(kiall): Somehow, json.load(fp) is returning None.
raise exceptions.EmptyRequestBody('Request Body is empty')
return json_dict
except ValueError as valueError:
if len(self.body) == 0:
if len(self.body) == 0 or self.body is None:
raise exceptions.EmptyRequestBody('Request Body is empty')
else:
raise exceptions.InvalidJson(six.text_type(valueError))

View File

@ -75,6 +75,16 @@ class ApiV2ZoneTransfersTest(ApiV2TestCase):
response.json['zone_id'])
self.assertIsNone(response.json['updated_at'])
def test_create_zone_transfer_request_empty_body(self):
# Send an empty ("None") body
response = self.client.post_json(
'/zones/%s/tasks/transfer_requests' % (self.zone.id),
None)
# Check the headers are what we expect
self.assertEqual(201, response.status_int)
self.assertEqual('application/json', response.content_type)
def test_get_zone_transfer_request(self):
initial = self.client.post_json(
'/zones/%s/tasks/transfer_requests' % (self.zone.id),