Merge "Label temporary files created by image_utils" into stable/victoria

This commit is contained in:
Zuul 2021-03-24 04:49:09 +00:00 committed by Gerrit Code Review
commit 990cba70ee
2 changed files with 28 additions and 15 deletions

View File

@ -645,7 +645,7 @@ def fetch_to_volume_format(context, image_service,
# large and cause disk full errors which would confuse users. # large and cause disk full errors which would confuse users.
# Unfortunately it seems that you can't pipe to 'qemu-img convert' because # Unfortunately it seems that you can't pipe to 'qemu-img convert' because
# it seeks. Maybe we can think of something for a future version. # it seeks. Maybe we can think of something for a future version.
with temporary_file() as tmp: with temporary_file(prefix='image_download_%s_' % image_id) as tmp:
has_meta = False if not image_meta else True has_meta = False if not image_meta else True
try: try:
format_raw = True if image_meta['disk_format'] == 'raw' else False format_raw = True if image_meta['disk_format'] == 'raw' else False
@ -763,7 +763,7 @@ def upload_volume(context, image_service, image_meta, volume_path,
base_image_ref=base_image_ref) base_image_ref=base_image_ref)
return return
with temporary_file() as tmp: with temporary_file(prefix='vol_upload_') as tmp:
LOG.debug("%s was %s, converting to %s", LOG.debug("%s was %s, converting to %s",
image_id, volume_format, image_meta['disk_format']) image_id, volume_format, image_meta['disk_format'])
@ -997,7 +997,8 @@ class TemporaryImages(object):
@contextlib.contextmanager @contextlib.contextmanager
def fetch(cls, image_service, context, image_id, suffix=''): def fetch(cls, image_service, context, image_id, suffix=''):
tmp_images = cls.for_image_service(image_service).temporary_images tmp_images = cls.for_image_service(image_service).temporary_images
with temporary_file(suffix=suffix) as tmp: with temporary_file(prefix='image_fetch_%s_' % image_id,
suffix=suffix) as tmp:
fetch_verify_image(context, image_service, image_id, tmp) fetch_verify_image(context, image_service, image_id, tmp)
user = context.user_id user = context.user_id
if not tmp_images.get(user): if not tmp_images.get(user):

View File

@ -1142,7 +1142,8 @@ class TestFetchToVolumeFormat(test.TestCase):
volume_format, blocksize) volume_format, blocksize)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=True), mock.call(tmp, force_share=False, run_as_root=True),
mock.call(tmp, run_as_root=True)]) mock.call(tmp, run_as_root=True)])
@ -1194,7 +1195,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1250,7 +1252,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1302,7 +1305,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1406,7 +1410,8 @@ class TestFetchToVolumeFormat(test.TestCase):
self.assertIsNone(output) self.assertIsNone(output)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_called_once_with(tmp, mock_info.assert_called_once_with(tmp,
force_share=False, force_share=False,
run_as_root=run_as_root) run_as_root=run_as_root)
@ -1453,7 +1458,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_called_once_with(tmp, mock_info.assert_called_once_with(tmp,
force_share=False, force_share=False,
run_as_root=run_as_root) run_as_root=run_as_root)
@ -1498,7 +1504,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_called_once_with(tmp, mock_info.assert_called_once_with(tmp,
force_share=False, force_share=False,
run_as_root=run_as_root) run_as_root=run_as_root)
@ -1549,7 +1556,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1597,7 +1605,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1645,7 +1654,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
image_service.show.assert_called_once_with(ctxt, image_id) image_service.show.assert_called_once_with(ctxt, image_id)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1694,7 +1704,8 @@ class TestFetchToVolumeFormat(test.TestCase):
run_as_root=run_as_root) run_as_root=run_as_root)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=run_as_root), mock.call(tmp, force_share=False, run_as_root=run_as_root),
mock.call(tmp, run_as_root=run_as_root)]) mock.call(tmp, run_as_root=run_as_root)])
@ -1852,7 +1863,8 @@ class TestFetchToVolumeFormat(test.TestCase):
volume_format, blocksize) volume_format, blocksize)
self.assertIsNone(output) self.assertIsNone(output)
mock_temp.assert_called_once_with() mock_temp.assert_called_once_with(prefix='image_download_%s_' %
image_id)
mock_info.assert_has_calls([ mock_info.assert_has_calls([
mock.call(tmp, force_share=False, run_as_root=True), mock.call(tmp, force_share=False, run_as_root=True),
mock.call(tmp, run_as_root=True)]) mock.call(tmp, run_as_root=True)])