devices: adjust XML serialization of device options
Use '<option name="option_name">option_value</option>' instead of '<options option_name="option_value"/>'. It's more consistent with the rest of qubes.xml - have one thing per element. Also, add options deserialization test.
This commit is contained in:
parent
29f3c9b58f
commit
f93583e2be
@ -22,7 +22,9 @@
|
|||||||
</features>
|
</features>
|
||||||
|
|
||||||
<devices class="pci">
|
<devices class="pci">
|
||||||
<device backend-domain="dom0" id="01_23.45"/>
|
<device backend-domain="dom0" id="01_23.45">
|
||||||
|
<option name="no-strict-reset">True</option>
|
||||||
|
</device>
|
||||||
</devices>
|
</devices>
|
||||||
</domain>
|
</domain>
|
||||||
|
|
||||||
|
@ -76,7 +76,9 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
|
|||||||
</features>
|
</features>
|
||||||
|
|
||||||
<devices class="pci">
|
<devices class="pci">
|
||||||
<device backend-domain="domain1" id="00_11.22"/>
|
<device backend-domain="domain1" id="00_11.22">
|
||||||
|
<option name="no-strict-reset">True</option>
|
||||||
|
</device>
|
||||||
</devices>
|
</devices>
|
||||||
|
|
||||||
<devices class="usb" />
|
<devices class="usb" />
|
||||||
@ -111,6 +113,11 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
|
|||||||
self.assertCountEqual(list(vm.devices['pci'].persistent()),
|
self.assertCountEqual(list(vm.devices['pci'].persistent()),
|
||||||
[qubes.ext.pci.PCIDevice(vm, '00_11.22')])
|
[qubes.ext.pci.PCIDevice(vm, '00_11.22')])
|
||||||
|
|
||||||
|
assignments = list(vm.devices['pci'].assignments())
|
||||||
|
self.assertEqual(len(assignments), 1)
|
||||||
|
self.assertEqual(assignments[0].options, {'no-strict-reset': 'True'})
|
||||||
|
self.assertEqual(assignments[0].persistent, True)
|
||||||
|
|
||||||
self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
|
self.assertXMLIsValid(vm.__xml__(), 'domain.rng')
|
||||||
|
|
||||||
def test_001_nxproperty(self):
|
def test_001_nxproperty(self):
|
||||||
|
@ -289,8 +289,8 @@ class BaseVM(qubes.PropertyHolder):
|
|||||||
devclass = parent.get('class')
|
devclass = parent.get('class')
|
||||||
for node in parent.xpath('./device'):
|
for node in parent.xpath('./device'):
|
||||||
options = {}
|
options = {}
|
||||||
if node.get('options'):
|
for option in node.xpath('./option'):
|
||||||
options = node.get('options').attribs(),
|
options[option.get('name')] = option.text
|
||||||
|
|
||||||
device_assignment = qubes.devices.DeviceAssignment(
|
device_assignment = qubes.devices.DeviceAssignment(
|
||||||
self.app.domains[node.get('backend-domain')],
|
self.app.domains[node.get('backend-domain')],
|
||||||
@ -331,10 +331,11 @@ class BaseVM(qubes.PropertyHolder):
|
|||||||
node = lxml.etree.Element('device')
|
node = lxml.etree.Element('device')
|
||||||
node.set('backend-domain', device.backend_domain.name)
|
node.set('backend-domain', device.backend_domain.name)
|
||||||
node.set('id', device.ident)
|
node.set('id', device.ident)
|
||||||
options_node = lxml.etree.Element('options')
|
for key, val in device.options.items():
|
||||||
for key, val in device.options:
|
option_node = lxml.etree.Element('option')
|
||||||
options_node.set(key, val)
|
option_node.set('name', key)
|
||||||
node.append(options_node)
|
option_node.text = val
|
||||||
|
node.append(option_node)
|
||||||
devices.append(node)
|
devices.append(node)
|
||||||
element.append(devices)
|
element.append(devices)
|
||||||
|
|
||||||
|
@ -224,15 +224,23 @@ the parser will complain about missing combine= attribute on the second <start>.
|
|||||||
<param name="pattern">[0-9a-f]{2}_[0-9a-f]{2}.[0-9a-f]{2}</param>
|
<param name="pattern">[0-9a-f]{2}_[0-9a-f]{2}.[0-9a-f]{2}</param>
|
||||||
</data>
|
</data>
|
||||||
</attribute>
|
</attribute>
|
||||||
<optional>
|
<zeroOrMore>
|
||||||
<element name="options">
|
<element name="option">
|
||||||
<doc:description>
|
<doc:description>
|
||||||
Options
|
Options
|
||||||
|
</doc:description>
|
||||||
|
<attribute name="name">
|
||||||
|
<doc:description>
|
||||||
|
Option name.
|
||||||
</doc:description>
|
</doc:description>
|
||||||
|
<data type="string">
|
||||||
|
<param name="pattern">[a-z0-9_-]+</param>
|
||||||
|
</data>
|
||||||
|
</attribute>
|
||||||
<data type="string">
|
<data type="string">
|
||||||
</data>
|
</data>
|
||||||
</element>
|
</element>
|
||||||
</optional>
|
</zeroOrMore>
|
||||||
</element>
|
</element>
|
||||||
</oneOrMore>
|
</oneOrMore>
|
||||||
</element>
|
</element>
|
||||||
|
Loading…
Reference in New Issue
Block a user