From 95f4b0ec2d64fff0a9c5afea54b90c3a8eba23c7 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 1 Apr 2013 14:19:49 -0700 Subject: [PATCH] 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 --- nova/tests/test_imagebackend.py | 19 +++++++++++++++++++ nova/tests/test_libvirt.py | 10 +++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/nova/tests/test_imagebackend.py b/nova/tests/test_imagebackend.py index 871e25dc..d571bbf9 100644 --- a/nova/tests/test_imagebackend.py +++ b/nova/tests/test_imagebackend.py @@ -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 diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 8c9d6e5f..1413eb98 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -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):