From 725f0d1e75c27d30006cc1d4356321616d1f401b Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Wed, 15 Aug 2018 14:42:00 +0100 Subject: [PATCH] Py3 fix in fake image service In py3, a file opened with 'b' must be written with a bytes object, not a string (this restriction does not exist in py2): >>> f = open('/tmp/foo', 'wb+') >>> f.write('foo') Traceback (most recent call last): File "", line 1, in TypeError: a bytes-like object is required, not 'str' The fake image service's download method was writing '' by default when no image data was present, which would result in the above exception if we ever hit that code path. This fix changes it to b''. Change-Id: Id4644f611fd48936b9ef036c18174dba0013c84a --- nova/tests/unit/image/fake.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/image/fake.py b/nova/tests/unit/image/fake.py index 3771feab33d1..8e4cd24c2afa 100644 --- a/nova/tests/unit/image/fake.py +++ b/nova/tests/unit/image/fake.py @@ -167,10 +167,10 @@ class _FakeImageService(object): trusted_certs=None): self.show(context, image_id) if data: - data.write(self._imagedata.get(image_id, '')) + data.write(self._imagedata.get(image_id, b'')) elif dst_path: with open(dst_path, 'wb') as data: - data.write(self._imagedata.get(image_id, '')) + data.write(self._imagedata.get(image_id, b'')) def show(self, context, image_id, include_locations=False, show_deleted=True):