Merge "Make glance web uploads streamable"

This commit is contained in:
Jenkins 2016-04-05 19:13:26 +00:00 committed by Gerrit Code Review
commit b8bd93c029
2 changed files with 5 additions and 2 deletions

View File

@ -163,16 +163,19 @@ class GlanceV2Wrapper(GlanceWrapper):
timeout = time.time() - start
image_data = None
response = None
try:
if os.path.isfile(image_location):
image_data = open(image_location)
else:
response = requests.get(image_location)
response = requests.get(image_location, stream=True)
image_data = response.raw
self.client.images.upload(image.id, image_data)
finally:
if image_data is not None:
image_data.close()
if response is not None:
response.close()
return utils.wait_for_status(
image, ["active"],

View File

@ -180,7 +180,7 @@ class GlanceV2WrapperTestCase(test.ScenarioTestCase, GlanceWrapperTestBase):
mock_open.assert_called_once_with(location)
else:
data = mock_requests_get.return_value.raw
mock_requests_get.assert_called_once_with(location)
mock_requests_get.assert_called_once_with(location, stream=True)
data.close.assert_called_once_with()
self.client().images.upload.assert_called_once_with(created_image.id,
data)