fix side effects from seekability test on input file

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
This commit is contained in:
Derek Higgins 2012-05-31 22:13:40 +01:00
parent 41d285ab02
commit a25824e77a
2 changed files with 26 additions and 1 deletions

View File

@ -593,7 +593,7 @@ class BaseClient(object):
# 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)

View File

@ -1879,6 +1879,31 @@ class TestClient(base.IsolatedUnitTest):
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):