Skip to content

Commit 725f0d1

Browse files
mdboothEric Fried
authored andcommitted
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 "<stdin>", line 1, in <module> 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
1 parent c049061 commit 725f0d1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

nova/tests/unit/image/fake.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ def download(self, context, image_id, data=None, dst_path=None,
167167
trusted_certs=None):
168168
self.show(context, image_id)
169169
if data:
170-
data.write(self._imagedata.get(image_id, ''))
170+
data.write(self._imagedata.get(image_id, b''))
171171
elif dst_path:
172172
with open(dst_path, 'wb') as data:
173-
data.write(self._imagedata.get(image_id, ''))
173+
data.write(self._imagedata.get(image_id, b''))
174174

175175
def show(self, context, image_id, include_locations=False,
176176
show_deleted=True):

0 commit comments

Comments
 (0)