Merge "Cleanup if images.fetch fails"
This commit is contained in:
commit
99095ba2a3
@ -336,6 +336,9 @@ def _free_disk_space_for(path):
|
||||
def _fetch(context, image_href, path, force_raw=False):
|
||||
"""Fetch image and convert to raw format if needed."""
|
||||
path_tmp = "%s.part" % path
|
||||
if os.path.exists(path_tmp):
|
||||
LOG.warning("%s exist, assuming it's stale", path_tmp)
|
||||
os.remove(path_tmp)
|
||||
images.fetch(context, image_href, path_tmp, force_raw=False)
|
||||
# Notes(yjiang5): If glance can provide the virtual size information,
|
||||
# then we can firstly clean cache and then invoke images.fetch().
|
||||
|
@ -754,6 +754,7 @@ class CleanupImageCacheTestCase(base.TestCase):
|
||||
|
||||
class TestFetchCleanup(base.TestCase):
|
||||
|
||||
@mock.patch.object(os, 'remove', autospec=True)
|
||||
@mock.patch.object(images, 'converted_size', autospec=True)
|
||||
@mock.patch.object(images, 'fetch', autospec=True)
|
||||
@mock.patch.object(images, 'image_to_raw', autospec=True)
|
||||
@ -762,7 +763,7 @@ class TestFetchCleanup(base.TestCase):
|
||||
@mock.patch.object(image_cache, '_clean_up_caches', autospec=True)
|
||||
def test__fetch(
|
||||
self, mock_clean, mock_will_convert, mock_raw, mock_fetch,
|
||||
mock_size):
|
||||
mock_size, mock_remove):
|
||||
mock_size.return_value = 100
|
||||
image_cache._fetch('fake', 'fake-uuid', '/foo/bar', force_raw=True)
|
||||
mock_fetch.assert_called_once_with('fake', 'fake-uuid',
|
||||
@ -771,6 +772,30 @@ class TestFetchCleanup(base.TestCase):
|
||||
mock_raw.assert_called_once_with('fake-uuid', '/foo/bar',
|
||||
'/foo/bar.part')
|
||||
mock_will_convert.assert_called_once_with('fake-uuid', '/foo/bar.part')
|
||||
mock_remove.assert_not_called()
|
||||
|
||||
@mock.patch.object(os, 'remove', autospec=True)
|
||||
@mock.patch.object(os.path, 'exists', autospec=True)
|
||||
@mock.patch.object(images, 'converted_size', autospec=True)
|
||||
@mock.patch.object(images, 'fetch', autospec=True)
|
||||
@mock.patch.object(images, 'image_to_raw', autospec=True)
|
||||
@mock.patch.object(images, 'force_raw_will_convert', autospec=True,
|
||||
return_value=True)
|
||||
@mock.patch.object(image_cache, '_clean_up_caches', autospec=True)
|
||||
def test__fetch_part_already_exists(
|
||||
self, mock_clean, mock_will_convert, mock_raw, mock_fetch,
|
||||
mock_size, mock_exists, mock_remove):
|
||||
mock_exists.return_value = True
|
||||
mock_size.return_value = 100
|
||||
image_cache._fetch('fake', 'fake-uuid', '/foo/bar', force_raw=True)
|
||||
mock_fetch.assert_called_once_with('fake', 'fake-uuid',
|
||||
'/foo/bar.part', force_raw=False)
|
||||
mock_clean.assert_called_once_with('/foo', 100)
|
||||
mock_raw.assert_called_once_with('fake-uuid', '/foo/bar',
|
||||
'/foo/bar.part')
|
||||
mock_will_convert.assert_called_once_with('fake-uuid', '/foo/bar.part')
|
||||
self.assertEqual(1, mock_exists.call_count)
|
||||
self.assertEqual(1, mock_remove.call_count)
|
||||
|
||||
@mock.patch.object(images, 'converted_size', autospec=True)
|
||||
@mock.patch.object(images, 'fetch', autospec=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user