From 21940bef90fb21989b143cfb56a45b3d2467ed31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 17 Jul 2017 12:26:10 +0200 Subject: [PATCH] Change vm.hvm into vm.virt_mode Fixes QubesOS/qubes-issues#2912 --- qubes/backup.py | 2 +- qubes/core2migration.py | 2 +- qubes/tests/integ/backup.py | 4 ++-- qubes/tests/integ/basic.py | 4 ++-- qubes/tests/vm/qubesvm.py | 17 +++++++++++++---- qubes/vm/qubesvm.py | 26 ++++++++++++++++++-------- templates/libvirt/xen.xml | 12 +++++++----- 7 files changed, 44 insertions(+), 23 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index e432697e..d3637903 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -2123,7 +2123,7 @@ class BackupRestore(object): # allow kernel=None only for HVM, # otherwise require valid kernel if not (vm_info.vm.property_is_default('kernel') - or (not vm_info.vm.kernel and vm_info.vm.hvm) + or (not vm_info.vm.kernel and vm_info.vm.virt_mode == 'hvm') or vm_info.vm.kernel in installed_kernels): if self.options.use_default_kernel: vm_info.vm.kernel = qubes.property.DEFAULT diff --git a/qubes/core2migration.py b/qubes/core2migration.py index 2286ad1b..40c555a5 100644 --- a/qubes/core2migration.py +++ b/qubes/core2migration.py @@ -190,7 +190,7 @@ class Core2Qubes(qubes.Qubes): if value_is_default and value_is_default.lower() != \ "true": kwargs[attr] = value - kwargs['hvm'] = "HVm" in vm_class_name + kwargs['virt_mode'] = 'hvm' if "HVm" in vm_class_name else 'pv' kwargs['provides_network'] = \ vm_class_name in ('QubesNetVm', 'QubesProxyVm') if vm_class_name == 'QubesNetVm': diff --git a/qubes/tests/integ/backup.py b/qubes/tests/integ/backup.py index c5c71f59..73204d53 100644 --- a/qubes/tests/integ/backup.py +++ b/qubes/tests/integ/backup.py @@ -122,7 +122,7 @@ class BackupTestsMixin(qubes.tests.SystemTestsMixin): self.log.debug("Creating %s" % vmname) testvm2 = self.app.add_new_vm(qubes.vm.standalonevm.StandaloneVM, name=vmname, - hvm=True, + virt_mode='hvm', label='red') testvm2.create_on_disk(pool=pool) self.fill_image(testvm2.storage.export('root'), 1024 * 1024 * 1024, \ @@ -322,7 +322,7 @@ class TC_00_Backup(BackupTestsMixin, qubes.tests.QubesTestCase): self.log.debug("Creating %s" % vmname) hvmtemplate = self.app.add_new_vm( - qubes.vm.templatevm.TemplateVM, name=vmname, hvm=True, label='red') + qubes.vm.templatevm.TemplateVM, name=vmname, virt_mode='hvm', label='red') hvmtemplate.create_on_disk() self.fill_image( os.path.join(hvmtemplate.dir_path, '00file'), diff --git a/qubes/tests/integ/basic.py b/qubes/tests/integ/basic.py index 642f20d0..198cb4dd 100644 --- a/qubes/tests/integ/basic.py +++ b/qubes/tests/integ/basic.py @@ -212,7 +212,7 @@ class TC_02_QvmPrefs(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): qubes.vm.appvm.AppVM, name=self.make_vm_name("hvm"), label='red') - self.testvm.hvm = True + self.testvm.virt_mode = 'hvm' self.loop.run_until_complete(self.testvm.create_on_disk()) self.app.save() @@ -326,7 +326,7 @@ class TC_03_QvmRevertTemplateChanges(qubes.tests.SystemTestsMixin, qubes.vm.templatevm.TemplateVM, name=self.make_vm_name("hvm"), label='red', - hvm=True + virt_mode='hvm', ) self.loop.run_until_complete(self.test_template.create_on_disk()) self.app.save() diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index 60535d44..2ca799d9 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -97,6 +97,19 @@ class TC_00_setters(qubes.tests.QubesTestCase): # there is no check for self.app.get_label() + def test_040_setter_virt_mode(self): + self.assertEqual( + qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'hvm'), + 'hvm') + self.assertEqual( + qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'HVM'), + 'hvm') + self.assertEqual( + qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'PV'), + 'pv') + with self.assertRaises(ValueError): + qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'True') + class QubesVMTestsMixin(object): property_no_default = object() @@ -230,10 +243,6 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase): self.assertPropertyInvalidValue(vm, 'label', 'invalid') self.assertPropertyInvalidValue(vm, 'label', 123) - def test_150_hvm(self): - vm = self.get_vm() - self._test_generic_bool_property(vm, 'hvm', default=True) - def test_160_memory(self): vm = self.get_vm() self.assertPropertyDefaultValue(vm, 'memory', 400) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index e4eefa85..53795632 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -102,6 +102,15 @@ def _setter_default_user(self, prop, value): 'Username can contain only those characters: ' + allowed_chars) return value +def _setter_virt_mode(self, prop, value): + value = str(value) + value = value.lower() + if value not in ('hvm', 'pv'): + raise qubes.exc.QubesPropertyValueError(self, prop, value, + 'Invalid virtualization mode, supported values: hvm, pv') + return value + + class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): '''Base functionality of Qubes VM shared between all VMs. @@ -373,11 +382,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): clone=False, doc='UUID from libvirt.') - hvm = qubes.property('hvm', - type=bool, setter=qubes.property.bool, - default=True, - doc='''Use full virtualisation (HVM) for this qube, - instead of paravirtualisation (PV)''') + virt_mode = qubes.property('virt_mode', + type=str, setter=_setter_virt_mode, + default='hvm', + doc='''Virtualisation mode: full virtualisation ("hvm"), + or paravirtualisation ("pv")''') installed_by_rpm = qubes.property('installed_by_rpm', type=bool, setter=qubes.property.bool, @@ -388,7 +397,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): memory = qubes.property('memory', type=int, setter=_setter_positive_int, default=(lambda self: - qubes.config.defaults['hvm_memory' if self.hvm else 'memory']), + qubes.config.defaults[ + 'hvm_memory' if self.virt_mode == 'hvm' else 'memory']), doc='Memory currently available for this VM.') maxmem = qubes.property('maxmem', type=int, @@ -1117,7 +1127,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): return if mem_required is None: - if self.hvm: + if self.virt_mode == 'hvm': if self.stubdom_mem: stubdom_mem = self.stubdom_mem else: @@ -1186,7 +1196,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): qrexec_args.insert(0, "-q") qrexec_env = os.environ.copy() - if not self.features.check_with_template('qrexec', not self.hvm): + if not self.features.check_with_template('qrexec', False): self.log.debug( 'Starting the qrexec daemon in background, because of features') qrexec_env['QREXEC_STARTUP_NOWAIT'] = '1' diff --git a/templates/libvirt/xen.xml b/templates/libvirt/xen.xml index e3ff31ac..b2d71c94 100644 --- a/templates/libvirt/xen.xml +++ b/templates/libvirt/xen.xml @@ -2,7 +2,7 @@ {% block basic %} {{ vm.name }} {{ vm.uuid }} - {% if vm.hvm and vm.devices['pci'].persistent() | list %} + {% if vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list %} {{ vm.memory }} {% else %} {{ vm.maxmem }} @@ -11,6 +11,7 @@ {{ vm.vcpus }} {% endblock %} {% block cpu %} + {% if vm.virt_mode == 'hvm' %} @@ -18,10 +19,11 @@ + {% endif %} {% endblock %} {% block os %} - {% if vm.hvm %} + {% if vm.virt_mode == 'hvm' %} hvm hvmloader @@ -38,7 +40,7 @@ {% block features %} - {% if vm.hvm %} + {% if vm.virt_mode == 'hvm' %} @@ -55,7 +57,7 @@ {% block clock %} - {% if vm.hvm %} + {% if vm.virt_mode == 'hvm' %} {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %} {% if timezone == 'localtime' %} @@ -133,7 +135,7 @@ {% include 'libvirt/devices/pci.xml' %} {% endfor %} - {% if vm.hvm %} + {% if vm.virt_mode == 'hvm' %}