Skip to content

Commit

Permalink
fix side effects from seekability test on input file
Browse files Browse the repository at this point in the history
Fixes Bug #1007093

Mixing use of os.lseek(fileno, 0, os.SEEK_SET) with
file.seek seems to cause problems when reading data
with file.read

Change-Id: Ia96ce9bbdc93a1a8c6169d85b99187f8cd7b2fdc
  • Loading branch information
derekhiggins authored and Eoghan Glynn committed Jun 15, 2012
1 parent 49c49d9 commit 37c9a7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion glance/common/client.py
Expand Up @@ -566,7 +566,7 @@ def _seekable(self, body):
# cat /path/to/image | glance add ...
# or where add command is launched via popen
try:
os.lseek(body.fileno(), 0, os.SEEK_SET)
os.lseek(body.fileno(), 0, os.SEEK_CUR)
return True
except OSError as e:
return (e.errno != errno.ESPIPE)
Expand Down
25 changes: 25 additions & 0 deletions glance/tests/unit/test_clients.py
Expand Up @@ -1882,6 +1882,31 @@ def add_image_with_image_data_as_file(self, sendfile):
for k, v in fixture.items():
self.assertEquals(v, new_meta[k])

def test_added_image_notdoubled(self):
"""Tests contents of an added small seekable image, when using ssl"""
fixture = {'name': 'fake public image',
'disk_format': 'vhd',
'container_format': 'ovf'
}

tmp_fp = tempfile.TemporaryFile('w+')
image_data_fixture = _gen_uuid()
tmp_fp.write(image_data_fixture)
tmp_fp.seek(0)

self.client.use_ssl = True
new_image = self.client.add_image(fixture, tmp_fp)
new_image_id = new_image['id']

tmp_fp.close()

new_meta, new_image_chunks = self.client.get_image(new_image_id)
new_image_data = ""
for chunk in new_image_chunks:
new_image_data += chunk

self.assertEquals(image_data_fixture, new_image_data)

@test_utils.skip_if(not base_client.SENDFILE_SUPPORTED,
'sendfile not supported')
def test_add_image_with_image_data_as_file_with_sendfile(self):
Expand Down

0 comments on commit 37c9a7e

Please sign in to comment.