Prevent error in _parse_resp when nullable list
- Add if contiditon to check, that body object hasattr 'keys'
- Add unit test for this case
NOTE: The original patch is Ifd063ed2329ec14c123a128b9520babb54ece69c
and this patch moves it to Tempest from deprecated tempest-lib.
In addition, this patch moves the test path because the path was
not match to the corresponding module.
One more thing is that this issue happened on Murano side and
they needed to have some workaround on their side. It would be
nice to fix this root issue on Tempest side.
Co-Authored-By: Victor Ryzhenkin <vryzhenkin@mirantis.com>
Closes-Bug: #1539927
Change-Id: I46cee5f3910ec9dfe383c6466f711e4a9554bb60
This commit is contained in:
committed by
Ken'ichi Ohmichi
parent
d64c46b776
commit
69a8edc1ac
@@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
When receiving nullable list as a response body, tempest.lib
|
||||
rest_client module raised an exception without valid json
|
||||
deserialization. A new release fixes this bug.
|
||||
@@ -474,7 +474,7 @@ class RestClient(object):
|
||||
# Ensure there are not more than one top-level keys
|
||||
# NOTE(freerunner): Ensure, that JSON is not nullable to
|
||||
# to prevent StopIteration Exception
|
||||
if len(body.keys()) != 1:
|
||||
if not hasattr(body, "keys") or len(body.keys()) != 1:
|
||||
return body
|
||||
# Just return the "wrapped" element
|
||||
first_key, first_item = six.next(six.iteritems(body))
|
||||
|
||||
@@ -276,6 +276,11 @@ class TestRestClientParseRespJSON(BaseRestClientTestClass):
|
||||
body = self.rest_client._parse_resp(json.dumps(self.null_dict))
|
||||
self.assertEqual(self.null_dict, body)
|
||||
|
||||
def test_parse_empty_list(self):
|
||||
empty_list = []
|
||||
body = self.rest_client._parse_resp(json.dumps(empty_list))
|
||||
self.assertEqual(empty_list, body)
|
||||
|
||||
|
||||
class TestRestClientErrorCheckerJSON(base.TestCase):
|
||||
c_type = "application/json"
|
||||
Reference in New Issue
Block a user