From ac402cd79db2570af4e0dad6c83b97fcf2396bca Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 14 Dec 2011 18:10:24 +0100 Subject: [PATCH] libvirt: implements boot from ISO images This allows to boot correctly ISO images. We just set the device type in the XML template to 'cdrom' if the image is in ISO format, and the bus type to IDE so it has maximum compatibility. This implements the blueprint support-kvm-boot-from-iso. Change-Id: I4d1ea52a17f6f24e944b10020d54aaec9e86c95c Signed-off-by: Julien Danjou --- nova/tests/test_libvirt.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 92a14ee2..15b7f725 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -347,12 +347,12 @@ class LibvirtConnTestCase(test.TestCase): result = conn._prepare_xml_info(instance_ref, _fake_network_info(self.stubs, 1), - False) + None, False) self.assertTrue(len(result['nics']) == 1) result = conn._prepare_xml_info(instance_ref, _fake_network_info(self.stubs, 2), - False) + None, False) self.assertTrue(len(result['nics']) == 2) def test_xml_and_uri_no_ramdisk_no_kernel(self): @@ -394,6 +394,14 @@ class LibvirtConnTestCase(test.TestCase): instance_data = dict(self.test_instance) self._check_xml_and_disk_prefix(instance_data) + def test_xml_disk_bus_virtio(self): + self._check_xml_and_disk_bus({"disk_format": "raw"}, + "disk", "virtio") + + def test_xml_disk_bus_ide(self): + self._check_xml_and_disk_bus({"disk_format": "iso"}, + "cdrom", "ide") + @test.skip_if(missing_libvirt(), "Test requires libvirt") def test_snapshot_in_ami_format(self): self.flags(image_service='nova.image.fake.FakeImageService') @@ -555,7 +563,7 @@ class LibvirtConnTestCase(test.TestCase): network_info = _fake_network_info(self.stubs, 2) conn = connection.LibvirtConnection(True) instance_ref = db.instance_create(self.context, instance_data) - xml = conn.to_xml(instance_ref, network_info, False) + xml = conn.to_xml(instance_ref, network_info, None, False) tree = xml_to_tree(xml) interfaces = tree.findall("./devices/interface") self.assertEquals(len(interfaces), 2) @@ -627,6 +635,19 @@ class LibvirtConnTestCase(test.TestCase): '%s != %s failed check %d' % (check(tree), expected_result, i)) + def _check_xml_and_disk_bus(self, image_meta, device_type, bus): + user_context = context.RequestContext(self.user_id, self.project_id) + instance_ref = db.instance_create(user_context, self.test_instance) + network_info = _fake_network_info(self.stubs, 1) + + xml = connection.LibvirtConnection(True).to_xml(instance_ref, + network_info, + image_meta) + tree = xml_to_tree(xml) + self.assertEqual(tree.find('./devices/disk').get('device'), + device_type) + self.assertEqual(tree.find('./devices/disk/target').get('bus'), bus) + def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, rescue=False): user_context = context.RequestContext(self.user_id, self.project_id) @@ -708,7 +729,7 @@ class LibvirtConnTestCase(test.TestCase): self.assertEquals(conn.uri, expected_uri) network_info = _fake_network_info(self.stubs, 1) - xml = conn.to_xml(instance_ref, network_info, rescue) + xml = conn.to_xml(instance_ref, network_info, None, rescue) tree = xml_to_tree(xml) for i, (check, expected_result) in enumerate(checks): self.assertEqual(check(tree),