Add code and test for migrating vm.hvm into vm.virt_mode
This will allow to load old qubes.xml - otherwise previous change render the system unusable (until manual qubes.xml edit). QubesOS/qubes-issues#2912
This commit is contained in:
parent
21940bef90
commit
9ba84ecdad
@ -26,6 +26,7 @@ import os
|
||||
import unittest
|
||||
import uuid
|
||||
import datetime
|
||||
import lxml.etree
|
||||
|
||||
import qubes
|
||||
import qubes.exc
|
||||
@ -476,3 +477,26 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase):
|
||||
vm = self.get_vm()
|
||||
self.assertPropertyInvalidValue(vm, 'backup_timestamp', 'xxx')
|
||||
self.assertPropertyInvalidValue(vm, 'backup_timestamp', None)
|
||||
|
||||
def test_500_property_migrate_virt_mode(self):
|
||||
xml_template = '''
|
||||
<domain class="QubesVM" id="domain-1">
|
||||
<properties>
|
||||
<property name="qid">1</property>
|
||||
<property name="name">testvm</property>
|
||||
<property name="label" ref="label-1" />
|
||||
<property name="hvm">{hvm_value}</property>
|
||||
</properties>
|
||||
</domain>
|
||||
'''
|
||||
xml = lxml.etree.XML(xml_template.format(hvm_value='True'))
|
||||
vm = qubes.vm.qubesvm.QubesVM(self.app, xml)
|
||||
self.assertEqual(vm.virt_mode, 'hvm')
|
||||
with self.assertRaises(AttributeError):
|
||||
vm.hvm
|
||||
|
||||
xml = lxml.etree.XML(xml_template.format(hvm_value='False'))
|
||||
vm = qubes.vm.qubesvm.QubesVM(self.app, xml)
|
||||
self.assertEqual(vm.virt_mode, 'pv')
|
||||
with self.assertRaises(AttributeError):
|
||||
vm.hvm
|
||||
|
@ -621,6 +621,16 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
||||
#
|
||||
|
||||
def __init__(self, app, xml, volume_config=None, **kwargs):
|
||||
# migrate renamed properties
|
||||
if xml is not None:
|
||||
node_hvm = xml.find('./properties/property[@name=\'hvm\']')
|
||||
if node_hvm is not None:
|
||||
if qubes.property.bool(None, None, node_hvm.text):
|
||||
kwargs['virt_mode'] = 'hvm'
|
||||
else:
|
||||
kwargs['virt_mode'] = 'pv'
|
||||
node_hvm.getparent().remove(node_hvm)
|
||||
|
||||
super(QubesVM, self).__init__(app, xml, **kwargs)
|
||||
|
||||
if volume_config is None:
|
||||
|
Loading…
Reference in New Issue
Block a user