libvirt: Get driver type from base image type.

If we are using the raw backend (no cow), we should set the driver
type based on the type of the source image instead of always
using raw.

Calls to to_xml were moved after _create_image so that the image
type could be determined when creating the xml for libvirt.

Fixes bug 1163009

Change-Id: Ic8d5f0ab83d868a42f834d39c0afb64818d7e027
This commit is contained in:
Vishvananda Ishaya
2013-04-01 14:19:49 -07:00
parent 3af449d685
commit 95f4b0ec2d
2 changed files with 24 additions and 5 deletions

View File

@@ -156,6 +156,7 @@ class RawTestCase(_ImageTestCase, test.TestCase):
def setUp(self):
self.image_class = imagebackend.Raw
super(RawTestCase, self).setUp()
self.stubs.Set(imagebackend.Raw, 'correct_format', lambda _: None)
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
@@ -198,6 +199,24 @@ class RawTestCase(_ImageTestCase, test.TestCase):
self.mox.VerifyAll()
def test_correct_format(self):
info = self.mox.CreateMockAnything()
self.stubs.UnsetAll()
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.images, 'qemu_img_info')
os.path.exists(self.PATH).AndReturn(True)
info = self.mox.CreateMockAnything()
info.file_format = 'foo'
imagebackend.images.qemu_img_info(self.PATH).AndReturn(info)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME, path=self.PATH)
self.assertEqual(image.driver_format, 'foo')
self.mox.VerifyAll()
class Qcow2TestCase(_ImageTestCase, test.TestCase):
SIZE = 1024 * 1024 * 1024

View File

@@ -2722,10 +2722,10 @@ class LibvirtConnTestCase(test.TestCase):
instance,
None,
image_meta)
conn._create_image(context, instance,
disk_info['mapping'])
xml = conn.to_xml(instance, None,
disk_info, image_meta)
conn._create_image(context, instance, xml,
disk_info['mapping'])
wantFiles = [
{'filename': '356a192b7913b04c54574d18c28d46e6395428ab',
@@ -2783,10 +2783,10 @@ class LibvirtConnTestCase(test.TestCase):
instance,
None,
image_meta)
conn._create_image(context, instance,
disk_info['mapping'])
xml = conn.to_xml(instance, None,
disk_info, image_meta)
conn._create_image(context, instance, xml,
disk_info['mapping'])
wantFiles = [
{'filename': '356a192b7913b04c54574d18c28d46e6395428ab',
@@ -4879,7 +4879,7 @@ class LibvirtDriverTestCase(test.TestCase):
def fake_plug_vifs(instance, network_info):
pass
def fake_create_image(context, inst, libvirt_xml,
def fake_create_image(context, inst,
disk_mapping, suffix='',
disk_images=None, network_info=None,
block_device_info=None):