diff options
| author | Christoph Thiel <cthiel@suse.com> | 2012-07-26 00:07:24 +0200 |
|---|---|---|
| committer | Christoph Thiel <cthiel@suse.com> | 2012-07-26 11:03:00 +0200 |
| commit | 158d821204d2f79cc06c1443562b3ce9bbe7cb9f (patch) | |
| tree | 05bbdfa33d47d048ff5e5c23e82b9636108503e7 | |
| parent | e238e07692c747ddcb0c70452578a812836cea67 (diff) | |
libvirt driver: set os_type to support xen hvm/pv
Generate libvirt config for xen hvm and pv guests based on instance
vm_mode. The vm_mode can be set via the vm_mode image property.
Use hvmloader for vm_mode.HVM guests. libvirt_type xen still defaults to
vm_mode.XEN (pv), to not change any behavior.
Change-Id: I5f92bedf6588ab2674d784772a5ecdb895fabe40
| -rw-r--r-- | nova/tests/test_libvirt.py | 33 | ||||
| -rw-r--r-- | nova/tests/test_libvirt_config.py | 43 | ||||
| -rw-r--r-- | nova/virt/libvirt/config.py | 3 | ||||
| -rw-r--r-- | nova/virt/libvirt/driver.py | 18 |
4 files changed, 90 insertions, 7 deletions
diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 6020d820c..0e349c8a8 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -800,6 +800,19 @@ class LibvirtConnTestCase(test.TestCase): self._check_xml_and_uri(instance_data, expect_kernel=False, expect_ramdisk=False) + def test_xml_and_uri_no_ramdisk_no_kernel_xen_hvm(self): + instance_data = dict(self.test_instance) + instance_data.update({'vm_mode': vm_mode.HVM}) + self._check_xml_and_uri(instance_data, expect_kernel=False, + expect_ramdisk=False, expect_xen_hvm=True) + + def test_xml_and_uri_no_ramdisk_no_kernel_xen_pv(self): + instance_data = dict(self.test_instance) + instance_data.update({'vm_mode': vm_mode.XEN}) + self._check_xml_and_uri(instance_data, expect_kernel=False, + expect_ramdisk=False, expect_xen_hvm=False, + xen_only=True) + def test_xml_and_uri_no_ramdisk(self): instance_data = dict(self.test_instance) instance_data['kernel_id'] = 'aki-deadbeef' @@ -1356,7 +1369,7 @@ class LibvirtConnTestCase(test.TestCase): instance_ref['uuid']) def _check_xml_and_uri(self, instance, expect_ramdisk, expect_kernel, - rescue=None): + rescue=None, expect_xen_hvm=False, xen_only=False): user_context = context.RequestContext(self.user_id, self.project_id) instance_ref = db.instance_create(user_context, instance) network_ref = db.project_get_networks(context.get_admin_context(), @@ -1379,10 +1392,22 @@ class LibvirtConnTestCase(test.TestCase): 'xen': ('xen:///', [(lambda t: t.find('.').get('type'), 'xen'), (lambda t: t.find('./os/type').text, - vm_mode.XEN)]), - } + vm_mode.XEN)])} + + if expect_xen_hvm or xen_only: + hypervisors_to_check = ['xen'] + else: + hypervisors_to_check = ['qemu', 'kvm', 'xen'] + + if expect_xen_hvm: + type_uri_map = {} + type_uri_map['xen'] = ('xen:///', + [(lambda t: t.find('.').get('type'), + 'xen'), + (lambda t: t.find('./os/type').text, + vm_mode.HVM)]) - for hypervisor_type in ['qemu', 'kvm', 'xen']: + for hypervisor_type in hypervisors_to_check: check_list = type_uri_map[hypervisor_type][1] if rescue: diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index 55f5528c7..87c044115 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -556,7 +556,7 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest): </devices> </domain>""") - def test_config_xen(self): + def test_config_xen_pv(self): obj = config.LibvirtConfigGuest() obj.virt_type = "xen" obj.memory = 1024 * 1024 * 100 @@ -599,6 +599,47 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest): </devices> </domain>""") + def test_config_xen_hvm(self): + obj = config.LibvirtConfigGuest() + obj.virt_type = "xen" + obj.memory = 1024 * 1024 * 100 + obj.vcpus = 2 + obj.name = "demo" + obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147" + obj.os_type = "hvm" + obj.os_loader = '/usr/lib/xen/boot/hvmloader' + obj.os_root = "root=xvda" + obj.os_cmdline = "console=xvc0" + + disk = config.LibvirtConfigGuestDisk() + disk.source_type = "file" + disk.source_path = "/tmp/img" + disk.target_dev = "/dev/xvda" + disk.target_bus = "xen" + + obj.add_device(disk) + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + <domain type="xen"> + <uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid> + <name>demo</name> + <memory>104857600</memory> + <vcpu>2</vcpu> + <os> + <type>hvm</type> + <loader>/usr/lib/xen/boot/hvmloader</loader> + <cmdline>console=xvc0</cmdline> + <root>root=xvda</root> + </os> + <devices> + <disk type="file" device="disk"> + <source file="/tmp/img"/> + <target bus="xen" dev="/dev/xvda"/> + </disk> + </devices> + </domain>""") + def test_config_kvm(self): obj = config.LibvirtConfigGuest() obj.virt_type = "kvm" diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index da55dc234..a53ed640f 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -575,6 +575,7 @@ class LibvirtConfigGuest(LibvirtConfigObject): self.acpi = False self.clock = None self.os_type = None + self.os_loader = None self.os_kernel = None self.os_initrd = None self.os_cmdline = None @@ -594,6 +595,8 @@ class LibvirtConfigGuest(LibvirtConfigObject): os.append(self._text_node("type", self.os_type)) if self.os_kernel is not None: os.append(self._text_node("kernel", self.os_kernel)) + if self.os_loader is not None: + os.append(self._text_node("loader", self.os_loader)) if self.os_initrd is not None: os.append(self._text_node("initrd", self.os_initrd)) if self.os_cmdline is not None: diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index f0ffa895c..9fcb61c3e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1713,6 +1713,21 @@ class LibvirtDriver(driver.ComputeDriver): nova_context.get_admin_context(), instance['uuid'], {'root_device_name': '/dev/' + self.default_root_device}) + guest.os_type = vm_mode.get_from_instance(instance) + + if guest.os_type is None: + if FLAGS.libvirt_type == "lxc": + guest.os_type = vm_mode.EXE + elif FLAGS.libvirt_type == "uml": + guest.os_type = vm_mode.UML + elif FLAGS.libvirt_type == "xen": + guest.os_type = vm_mode.XEN + else: + guest.os_type = vm_mode.HVM + + if FLAGS.libvirt_type == "xen" and guest.os_type == vm_mode.HVM: + guest.os_loader = '/usr/lib/xen/boot/hvmloader' + if FLAGS.libvirt_type == "lxc": guest.os_type = vm_mode.EXE guest.os_init_path = "/sbin/init" @@ -1723,7 +1738,6 @@ class LibvirtDriver(driver.ComputeDriver): guest.os_root = root_device_name or "/dev/ubda" else: if FLAGS.libvirt_type == "xen": - guest.os_type = vm_mode.XEN guest.os_root = root_device_name or "/dev/xvda" else: guest.os_type = vm_mode.HVM @@ -1808,7 +1822,7 @@ class LibvirtDriver(driver.ComputeDriver): guest.add_device(consolepty) if FLAGS.vnc_enabled and FLAGS.libvirt_type not in ('lxc', 'uml'): - if FLAGS.use_usb_tablet: + if FLAGS.use_usb_tablet and guest.os_type == vm_mode.HVM: tablet = config.LibvirtConfigGuestInput() tablet.type = "tablet" tablet.bus = "usb" |
