Get rid of pointless 'suffix' parameter in libvirt imagebackend
The libvirt 'imagebackend' module has various methods which take a 'name' and 'suffix' argument. They are never used in isolation, however, so passing them separately has no benefit. Indeed all but one caller passes a name which already has a suffix appended The suffix argument can thus trivially be removed completely. Change-Id: I2ee0f3d104a2eb5139fc85c2db68e36255b82dad Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
@@ -25,10 +25,10 @@ class Backend(object):
|
||||
def __init__(self, use_cow):
|
||||
pass
|
||||
|
||||
def image(self, instance, name, suffix='', image_type=''):
|
||||
def image(self, instance, name, image_type=''):
|
||||
class FakeImage(imagebackend.Image):
|
||||
def __init__(self, instance, name, suffix=''):
|
||||
self.path = os.path.join(instance, name + suffix)
|
||||
def __init__(self, instance, name):
|
||||
self.path = os.path.join(instance, name)
|
||||
|
||||
def create_image(self, prepare_template, base,
|
||||
size, *args, **kwargs):
|
||||
@@ -45,4 +45,4 @@ class Backend(object):
|
||||
info.source_path = self.path
|
||||
return info
|
||||
|
||||
return FakeImage(instance, name, suffix)
|
||||
return FakeImage(instance, name)
|
||||
|
||||
@@ -38,12 +38,11 @@ class _ImageTestCase(test.TestCase):
|
||||
super(_ImageTestCase, self).setUp()
|
||||
self.flags(instances_path=self.INSTANCES_PATH)
|
||||
self.INSTANCE = 'instance'
|
||||
self.NAME = 'fake'
|
||||
self.SUFFIX = 'vm'
|
||||
self.NAME = 'fake.vm'
|
||||
self.TEMPLATE = 'template'
|
||||
|
||||
self.PATH = os.path.join(FLAGS.instances_path, self.INSTANCE,
|
||||
self.NAME + self.SUFFIX)
|
||||
self.NAME)
|
||||
self.TEMPLATE_DIR = os.path.join(FLAGS.instances_path,
|
||||
'_base')
|
||||
self.TEMPLATE_PATH = os.path.join(self.TEMPLATE_DIR, 'template')
|
||||
@@ -61,7 +60,7 @@ class _ImageTestCase(test.TestCase):
|
||||
imagebackend.libvirt_utils.ensure_tree(self.TEMPLATE_DIR)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
self.mock_create_image(image)
|
||||
image.cache(fn, self.TEMPLATE)
|
||||
|
||||
@@ -72,7 +71,7 @@ class _ImageTestCase(test.TestCase):
|
||||
os.path.exists(self.PATH).AndReturn(True)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.cache(None, self.TEMPLATE)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -87,7 +86,7 @@ class _ImageTestCase(test.TestCase):
|
||||
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'ensure_tree')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
self.mock_create_image(image)
|
||||
image.cache(fn, self.TEMPLATE)
|
||||
|
||||
@@ -101,7 +100,7 @@ class _ImageTestCase(test.TestCase):
|
||||
fn = self.mox.CreateMockAnything()
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
self.mock_create_image(image)
|
||||
image.cache(fn, self.TEMPLATE)
|
||||
|
||||
@@ -129,7 +128,7 @@ class RawTestCase(_ImageTestCase):
|
||||
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH, self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, None, image_id=None)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -139,7 +138,7 @@ class RawTestCase(_ImageTestCase):
|
||||
fn(target=self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, None)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -151,7 +150,7 @@ class RawTestCase(_ImageTestCase):
|
||||
imagebackend.disk.extend(self.PATH, self.SIZE)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE, image_id=None)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -182,7 +181,7 @@ class Qcow2TestCase(_ImageTestCase):
|
||||
self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, None)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -199,7 +198,7 @@ class Qcow2TestCase(_ImageTestCase):
|
||||
self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -213,7 +212,7 @@ class Qcow2TestCase(_ImageTestCase):
|
||||
self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -228,7 +227,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
self.image_class = imagebackend.Lvm
|
||||
super(LvmTestCase, self).setUp()
|
||||
self.flags(libvirt_images_volume_group=self.VG)
|
||||
self.LV = '%s_%s' % (self.INSTANCE, self.NAME + self.SUFFIX)
|
||||
self.LV = '%s_%s' % (self.INSTANCE, self.NAME)
|
||||
self.PATH = os.path.join('/dev', self.VG, self.LV)
|
||||
|
||||
self.disk = imagebackend.disk
|
||||
@@ -257,7 +256,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
self.utils.execute(*cmd, run_as_root=True)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, None)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -269,7 +268,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
fn(target=self.PATH, ephemeral_size=None)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH,
|
||||
self.SIZE, ephemeral_size=None)
|
||||
|
||||
@@ -288,7 +287,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
self.disk.resize2fs(self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
@@ -328,7 +327,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
self.libvirt_utils.remove_logical_volumes(self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
|
||||
self.assertRaises(RuntimeError, image.create_image, fn,
|
||||
self.TEMPLATE_PATH, self.SIZE)
|
||||
@@ -346,7 +345,7 @@ class LvmTestCase(_ImageTestCase):
|
||||
self.libvirt_utils.remove_logical_volumes(self.PATH)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
image = self.image_class(self.INSTANCE, self.NAME, self.SUFFIX)
|
||||
image = self.image_class(self.INSTANCE, self.NAME)
|
||||
|
||||
self.assertRaises(RuntimeError, image.create_image, fn,
|
||||
self.TEMPLATE_PATH, self.SIZE,
|
||||
@@ -356,13 +355,11 @@ class LvmTestCase(_ImageTestCase):
|
||||
|
||||
class BackendTestCase(test.TestCase):
|
||||
INSTANCE = 'fake-instance'
|
||||
NAME = 'fake-name'
|
||||
SUFFIX = 'suffix'
|
||||
NAME = 'fake-name.suffix'
|
||||
|
||||
def get_image(self, use_cow, image_type):
|
||||
return imagebackend.Backend(use_cow).image(self.INSTANCE,
|
||||
self.NAME,
|
||||
self.SUFFIX,
|
||||
image_type)
|
||||
|
||||
def _test_image(self, image_type, image_not_cow, image_cow):
|
||||
|
||||
Reference in New Issue
Block a user