image_utils: Simplify fetch_verify_image
Remove unused params and code. This is only ever called with user_id, project_id, and size set to None. Change-Id: Icf8a4829a02a3b3bba9375af7a27f86e24a850b7
This commit is contained in:
parent
ccb6025cd1
commit
e96f48d369
|
@ -566,9 +566,7 @@ def get_qemu_data(image_id, has_meta, disk_format_raw, dest, run_as_root,
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def fetch_verify_image(context, image_service, image_id, dest,
|
def fetch_verify_image(context, image_service, image_id, dest):
|
||||||
user_id=None, project_id=None, size=None,
|
|
||||||
run_as_root=True):
|
|
||||||
fetch(context, image_service, image_id, dest,
|
fetch(context, image_service, image_id, dest,
|
||||||
None, None)
|
None, None)
|
||||||
image_meta = image_service.show(context, image_id)
|
image_meta = image_service.show(context, image_id)
|
||||||
|
@ -580,7 +578,7 @@ def fetch_verify_image(context, image_service, image_id, dest,
|
||||||
except TypeError:
|
except TypeError:
|
||||||
format_raw = False
|
format_raw = False
|
||||||
data = get_qemu_data(image_id, has_meta, format_raw,
|
data = get_qemu_data(image_id, has_meta, format_raw,
|
||||||
dest, run_as_root)
|
dest, True)
|
||||||
# We can only really do verification of the image if we have
|
# We can only really do verification of the image if we have
|
||||||
# qemu data to use
|
# qemu data to use
|
||||||
if data is not None:
|
if data is not None:
|
||||||
|
@ -597,12 +595,6 @@ def fetch_verify_image(context, image_service, image_id, dest,
|
||||||
reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") %
|
reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") %
|
||||||
{'fmt': fmt, 'backing_file': backing_file}))
|
{'fmt': fmt, 'backing_file': backing_file}))
|
||||||
|
|
||||||
# NOTE(xqueralt): If the image virtual size doesn't fit in the
|
|
||||||
# requested volume there is no point on resizing it because it will
|
|
||||||
# generate an unusable image.
|
|
||||||
if size is not None:
|
|
||||||
check_virtual_size(data.virtual_size, size, image_id)
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_to_vhd(context, image_service,
|
def fetch_to_vhd(context, image_service,
|
||||||
image_id, dest, blocksize, volume_subformat=None,
|
image_id, dest, blocksize, volume_subformat=None,
|
||||||
|
|
|
@ -606,18 +606,13 @@ class TestVerifyImage(test.TestCase):
|
||||||
image_service = FakeImageService()
|
image_service = FakeImageService()
|
||||||
image_id = mock.sentinel.image_id
|
image_id = mock.sentinel.image_id
|
||||||
dest = mock.sentinel.dest
|
dest = mock.sentinel.dest
|
||||||
user_id = mock.sentinel.user_id
|
|
||||||
project_id = mock.sentinel.project_id
|
|
||||||
size = 2
|
|
||||||
run_as_root = mock.sentinel.run_as_root
|
|
||||||
mock_data = mock_info.return_value
|
mock_data = mock_info.return_value
|
||||||
mock_data.file_format = 'test_format'
|
mock_data.file_format = 'test_format'
|
||||||
mock_data.backing_file = None
|
mock_data.backing_file = None
|
||||||
mock_data.virtual_size = 1
|
mock_data.virtual_size = 1
|
||||||
|
|
||||||
output = image_utils.fetch_verify_image(
|
output = image_utils.fetch_verify_image(
|
||||||
ctxt, image_service, image_id, dest, user_id=user_id,
|
ctxt, image_service, image_id, dest)
|
||||||
project_id=project_id, size=size, run_as_root=run_as_root)
|
|
||||||
self.assertIsNone(output)
|
self.assertIsNone(output)
|
||||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||||
dest, None, None)
|
dest, None, None)
|
||||||
|
@ -626,8 +621,6 @@ class TestVerifyImage(test.TestCase):
|
||||||
.assert_called_once_with())
|
.assert_called_once_with())
|
||||||
(mock_fileutils.remove_path_on_error.return_value.__exit__
|
(mock_fileutils.remove_path_on_error.return_value.__exit__
|
||||||
.assert_called_once_with(None, None, None))
|
.assert_called_once_with(None, None, None))
|
||||||
mock_check_size.assert_called_once_with(mock_data.virtual_size,
|
|
||||||
size, image_id)
|
|
||||||
|
|
||||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
||||||
@mock.patch('cinder.image.image_utils.fileutils')
|
@mock.patch('cinder.image.image_utils.fileutils')
|
||||||
|
@ -661,29 +654,6 @@ class TestVerifyImage(test.TestCase):
|
||||||
image_utils.fetch_verify_image,
|
image_utils.fetch_verify_image,
|
||||||
ctxt, image_service, image_id, dest)
|
ctxt, image_service, image_id, dest)
|
||||||
|
|
||||||
@mock.patch('cinder.image.image_utils.check_virtual_size')
|
|
||||||
@mock.patch('cinder.image.image_utils.qemu_img_info')
|
|
||||||
@mock.patch('cinder.image.image_utils.fileutils')
|
|
||||||
@mock.patch('cinder.image.image_utils.fetch')
|
|
||||||
def test_size_error(self, mock_fetch, mock_fileutils, mock_info,
|
|
||||||
mock_check_size):
|
|
||||||
ctxt = mock.sentinel.context
|
|
||||||
image_service = mock.Mock()
|
|
||||||
image_id = mock.sentinel.image_id
|
|
||||||
dest = mock.sentinel.dest
|
|
||||||
size = 1
|
|
||||||
mock_data = mock_info.return_value
|
|
||||||
mock_data.file_format = 'test_format'
|
|
||||||
mock_data.backing_file = None
|
|
||||||
mock_data.virtual_size = 2 * units.Gi
|
|
||||||
|
|
||||||
mock_check_size.side_effect = exception.ImageUnacceptable(
|
|
||||||
image_id='fake_image_id', reason='test')
|
|
||||||
|
|
||||||
self.assertRaises(exception.ImageUnacceptable,
|
|
||||||
image_utils.fetch_verify_image,
|
|
||||||
ctxt, image_service, image_id, dest, size=size)
|
|
||||||
|
|
||||||
|
|
||||||
class TestTemporaryDir(test.TestCase):
|
class TestTemporaryDir(test.TestCase):
|
||||||
@mock.patch('cinder.image.image_utils.CONF')
|
@mock.patch('cinder.image.image_utils.CONF')
|
||||||
|
@ -1726,23 +1696,18 @@ class TestFetchToVolumeFormat(test.TestCase):
|
||||||
image_service = mock.Mock(temp_images=None)
|
image_service = mock.Mock(temp_images=None)
|
||||||
image_id = mock.sentinel.image_id
|
image_id = mock.sentinel.image_id
|
||||||
dest = mock.sentinel.dest
|
dest = mock.sentinel.dest
|
||||||
ctxt.user_id = user_id = mock.sentinel.user_id
|
ctxt.user_id = mock.sentinel.user_id
|
||||||
project_id = mock.sentinel.project_id
|
|
||||||
size = 4321
|
|
||||||
run_as_root = mock.sentinel.run_as_root
|
|
||||||
|
|
||||||
image_service.show.return_value = {'disk_format': 'raw',
|
image_service.show.return_value = {'disk_format': 'raw',
|
||||||
'size': 41126400}
|
'size': 41126400}
|
||||||
|
|
||||||
image_utils.fetch_verify_image(
|
image_utils.fetch_verify_image(
|
||||||
ctxt, image_service, image_id, dest,
|
ctxt, image_service, image_id, dest)
|
||||||
user_id=user_id, project_id=project_id, size=size,
|
|
||||||
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_info.assert_called_once_with(dest,
|
mock_info.assert_called_once_with(dest,
|
||||||
force_share=False,
|
force_share=False,
|
||||||
run_as_root=run_as_root)
|
run_as_root=True)
|
||||||
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
mock_fetch.assert_called_once_with(ctxt, image_service, image_id,
|
||||||
dest, None, None)
|
dest, None, None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue