Don't decode empty response body

Some neutron POST and PUT APIs don't return response body,
for instance, dhcp-agent-network-add and l3-agent-router-add.
This patch add a check for response body.

Change-Id: Ia772927a28cb83c4c88680b5add925b12978dc5d
Related-Bug: #1555921
This commit is contained in:
Hirofumi Ichihara 2016-07-21 16:27:36 +09:00
parent 6bc4685f6b
commit c91f9f2ccd
2 changed files with 7 additions and 1 deletions

View File

@ -793,6 +793,11 @@ class ClientV2TestJson(CLITestV20Base):
self.mox.VerifyAll()
self.mox.UnsetStubs()
def test_deserialize_without_data(self):
data = u''
result = self.client.deserialize(data, 200)
self.assertEqual(data, result)
class CLITestV20ExceptionHandler(CLITestV20Base):

View File

@ -305,7 +305,8 @@ class ClientBase(object):
def deserialize(self, data, status_code):
"""Deserializes a JSON string into a dictionary."""
if status_code == 204:
# TODO(hichihara): Remove checking 204 in bug 1611167
if status_code == 204 or not data:
return data
return serializer.Serializer().deserialize(
data)['body']