Remove unused arguments to images.fetch and images.fetch_to_raw

Functions were passing in user_id and project_id to these functions,
but they were not being used. This change allows a subsequent patch to
drop an instance object as a function argument which has no purpose
other than to provide these unused values.

Change-Id: I844b97523b28b327e76e01ef7f16b57a415418ec
This commit is contained in:
Matthew Booth 2016-05-12 13:56:19 +01:00
parent 69d538849d
commit 059021550a
9 changed files with 29 additions and 72 deletions

View File

@ -122,9 +122,7 @@ class ImageCacheTestCase(test_base.HyperVBaseTestCase):
self.assertEqual(expected_vhd_path, result)
mock_fetch.assert_called_once_with(self.context, self.FAKE_IMAGE_REF,
expected_path,
self.instance['user_id'],
self.instance['project_id'])
expected_path)
self.imagecache._vhdutils.get_vhd_format.assert_called_once_with(
expected_path)
self.imagecache._pathutils.rename.assert_called_once_with(

View File

@ -139,12 +139,11 @@ def get_fs_info(path):
'free': 84 * (1024 ** 3)}
def fetch_image(context, target, image_id, user_id, project_id, max_size=0):
def fetch_image(context, target, image_id, max_size=0):
pass
def fetch_raw_image(context, target, image_id, user_id, project_id,
max_size=0):
def fetch_raw_image(context, target, image_id, max_size=0):
pass

View File

@ -8330,17 +8330,11 @@ class LibvirtConnTestCase(test.NoDBTestCase):
mock.call(context=self.context,
target=backfile_path,
image_id=self.test_instance['image_ref'],
user_id=self.test_instance['user_id'],
project_id=self.test_instance['project_id'],
max_size=25165824),
mock.call(self.context, kernel_path,
self.test_instance['kernel_id'],
self.test_instance['user_id'],
self.test_instance['project_id']),
self.test_instance['kernel_id']),
mock.call(self.context, ramdisk_path,
self.test_instance['ramdisk_id'],
self.test_instance['user_id'],
self.test_instance['project_id']),
self.test_instance['ramdisk_id']),
])
@mock.patch.object(libvirt_driver.libvirt_utils, 'fetch_image')
@ -15224,16 +15218,13 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
imagebackend.Image.cache(context=mox.IgnoreArg(),
fetch_func=mox.IgnoreArg(),
filename=mox.IgnoreArg(),
image_id=mox.IgnoreArg(),
project_id=mox.IgnoreArg(),
user_id=mox.IgnoreArg()).MultipleTimes()
image_id=mox.IgnoreArg()).MultipleTimes()
imagebackend.Image.cache(context=mox.IgnoreArg(),
fetch_func=mox.IgnoreArg(),
filename=mox.IgnoreArg(),
image_id=mox.IgnoreArg(),
project_id=mox.IgnoreArg(),
size=None, user_id=mox.IgnoreArg())
size=None)
image_meta = objects.ImageMeta.from_dict(
{'id': 'fake', 'name': 'fake'})
@ -15346,16 +15337,13 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
imagebackend.Image.cache(context=mox.IgnoreArg(),
fetch_func=mox.IgnoreArg(),
filename=mox.IgnoreArg(),
image_id=mox.IgnoreArg(),
project_id=mox.IgnoreArg(),
user_id=mox.IgnoreArg()).MultipleTimes()
image_id=mox.IgnoreArg()).MultipleTimes()
imagebackend.Image.cache(context=mox.IgnoreArg(),
fetch_func=mox.IgnoreArg(),
filename=mox.IgnoreArg(),
image_id=mox.IgnoreArg(),
project_id=mox.IgnoreArg(),
size=None, user_id=mox.IgnoreArg())
size=None)
instance_metadata.InstanceMetadata.__init__(mox.IgnoreArg(),
content=mox.IgnoreArg(),

View File

@ -540,13 +540,9 @@ disk size: 4.4M
context = 'opaque context'
target = '/tmp/targetfile'
image_id = '4'
user_id = 'fake'
project_id = 'fake'
libvirt_utils.fetch_image(context, target, image_id,
user_id, project_id)
libvirt_utils.fetch_image(context, target, image_id)
mock_images.assert_called_once_with(
context, image_id, target, user_id, project_id,
max_size=0)
context, image_id, target, max_size=0)
@mock.patch('nova.virt.images.fetch')
def test_fetch_initrd_image(self, mock_images):
@ -556,13 +552,9 @@ disk size: 4.4M
user_name="pie")
target = '/tmp/targetfile'
image_id = '4'
user_id = 'fake'
project_id = 'fake'
libvirt_utils.fetch_raw_image(_context, target, image_id,
user_id, project_id)
libvirt_utils.fetch_raw_image(_context, target, image_id)
mock_images.assert_called_once_with(
_context, image_id, target, user_id, project_id,
max_size=0)
_context, image_id, target, max_size=0)
def test_fetch_raw_image(self):
@ -621,8 +613,6 @@ disk size: 4.4M
context = 'opaque context'
image_id = '4'
user_id = 'fake'
project_id = 'fake'
target = 't.qcow2'
self.executes = []
@ -631,22 +621,20 @@ disk size: 4.4M
'-f', 'qcow2'),
('rm', 't.qcow2.part'),
('mv', 't.qcow2.converted', 't.qcow2')]
images.fetch_to_raw(context, image_id, target, user_id, project_id,
max_size=1)
images.fetch_to_raw(context, image_id, target, max_size=1)
self.assertEqual(self.executes, expected_commands)
target = 't.raw'
self.executes = []
expected_commands = [('mv', 't.raw.part', 't.raw')]
images.fetch_to_raw(context, image_id, target, user_id, project_id)
images.fetch_to_raw(context, image_id, target)
self.assertEqual(self.executes, expected_commands)
target = 'backing.qcow2'
self.executes = []
expected_commands = [('rm', '-f', 'backing.qcow2.part')]
self.assertRaises(exception.ImageUnacceptable,
images.fetch_to_raw,
context, image_id, target, user_id, project_id)
images.fetch_to_raw, context, image_id, target)
self.assertEqual(self.executes, expected_commands)
target = 'big.qcow2'
@ -654,8 +642,7 @@ disk size: 4.4M
expected_commands = [('rm', '-f', 'big.qcow2.part')]
self.assertRaises(exception.FlavorDiskSmallerThanImage,
images.fetch_to_raw,
context, image_id, target, user_id, project_id,
max_size=1)
context, image_id, target, max_size=1)
self.assertEqual(self.executes, expected_commands)
del self.executes

View File

@ -65,4 +65,4 @@ class QemuTestCase(test.NoDBTestCase):
self.assertRaisesRegex(exception.ImageUnacceptable,
'Image href123 is unacceptable.*',
images.fetch_to_raw,
None, 'href123', '/no/path', None, None)
None, 'href123', '/no/path')

View File

@ -104,9 +104,7 @@ class ImageCache(object):
if not vhd_path:
try:
images.fetch(context, image_id, base_vhd_path,
instance.user_id,
instance.project_id)
images.fetch(context, image_id, base_vhd_path)
format_ext = self._vhdutils.get_vhd_format(base_vhd_path)
vhd_path = base_vhd_path + '.' + format_ext.lower()

View File

@ -96,7 +96,7 @@ def _convert_image(source, dest, in_format, out_format, run_as_root):
raise exception.ImageUnacceptable(image_id=source, reason=msg)
def fetch(context, image_href, path, _user_id, _project_id, max_size=0):
def fetch(context, image_href, path, max_size=0):
with fileutils.remove_path_on_error(path):
IMAGE_API.download(context, image_href, dest_path=path)
@ -105,10 +105,9 @@ def get_info(context, image_href):
return IMAGE_API.get(context, image_href)
def fetch_to_raw(context, image_href, path, user_id, project_id, max_size=0):
def fetch_to_raw(context, image_href, path, max_size=0):
path_tmp = "%s.part" % path
fetch(context, image_href, path_tmp, user_id, project_id,
max_size=max_size)
fetch(context, image_href, path_tmp, max_size=max_size)
with fileutils.remove_path_on_error(path_tmp):
data = qemu_img_info(path_tmp)

View File

@ -2944,17 +2944,13 @@ class LibvirtDriver(driver.ComputeDriver):
raw('kernel').cache(fetch_func=libvirt_utils.fetch_raw_image,
context=context,
filename=fname,
image_id=disk_images['kernel_id'],
user_id=instance.user_id,
project_id=instance.project_id)
image_id=disk_images['kernel_id'])
if disk_images['ramdisk_id']:
fname = imagecache.get_cache_fname(disk_images, 'ramdisk_id')
raw('ramdisk').cache(fetch_func=libvirt_utils.fetch_raw_image,
context=context,
filename=fname,
image_id=disk_images['ramdisk_id'],
user_id=instance.user_id,
project_id=instance.project_id)
image_id=disk_images['ramdisk_id'])
inst_type = instance.get_flavor()
@ -6260,10 +6256,7 @@ class LibvirtDriver(driver.ComputeDriver):
def _try_fetch_image(self, context, path, image_id, instance,
fallback_from_host=None):
try:
libvirt_utils.fetch_image(context, path,
image_id,
instance.user_id,
instance.project_id)
libvirt_utils.fetch_image(context, path, image_id)
except exception.ImageNotFound:
if not fallback_from_host:
raise
@ -6487,8 +6480,6 @@ class LibvirtDriver(driver.ComputeDriver):
context=context,
filename=filename,
image_id=image_id,
user_id=instance.user_id,
project_id=instance.project_id,
size=size)
except exception.ImageNotFound:
if not fallback_from_host:

View File

@ -414,21 +414,18 @@ def get_fs_info(path):
'used': used}
def fetch_image(context, target, image_id, user_id, project_id, max_size=0):
def fetch_image(context, target, image_id, max_size=0):
"""Grab image."""
images.fetch_to_raw(context, image_id, target, user_id, project_id,
max_size=max_size)
images.fetch_to_raw(context, image_id, target, max_size=max_size)
def fetch_raw_image(context, target, image_id, user_id, project_id,
max_size=0):
def fetch_raw_image(context, target, image_id, max_size=0):
"""Grab initrd or kernel image.
This function does not attempt raw conversion, as these images will
already be in raw format.
"""
images.fetch(context, image_id, target, user_id, project_id,
max_size=max_size)
images.fetch(context, image_id, target, max_size=max_size)
def get_instance_path(instance, forceold=False, relative=False):