diff --git a/rally/plugins/openstack/wrappers/glance.py b/rally/plugins/openstack/wrappers/glance.py index c1f27bb0..d497cbc1 100644 --- a/rally/plugins/openstack/wrappers/glance.py +++ b/rally/plugins/openstack/wrappers/glance.py @@ -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"], diff --git a/tests/unit/plugins/openstack/wrappers/test_glance.py b/tests/unit/plugins/openstack/wrappers/test_glance.py index 10951577..fe4acf0e 100644 --- a/tests/unit/plugins/openstack/wrappers/test_glance.py +++ b/tests/unit/plugins/openstack/wrappers/test_glance.py @@ -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)