From c91f9f2ccd7d61012673d5f3adb201e0767b939d Mon Sep 17 00:00:00 2001 From: Hirofumi Ichihara Date: Thu, 21 Jul 2016 16:27:36 +0900 Subject: [PATCH] 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 --- neutronclient/tests/unit/test_cli20.py | 5 +++++ neutronclient/v2_0/client.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py index 19bd29708..80362858e 100644 --- a/neutronclient/tests/unit/test_cli20.py +++ b/neutronclient/tests/unit/test_cli20.py @@ -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): diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index 5504fd1dd..9a01b38b1 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -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']