From f93583e2bea54a7206097284edbf83be6a64be69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 22 May 2017 15:27:14 +0200 Subject: [PATCH] devices: adjust XML serialization of device options Use '' instead of ''. It's more consistent with the rest of qubes.xml - have one thing per element. Also, add options deserialization test. --- doc/example.xml | 4 +++- qubes/tests/vm/init.py | 9 ++++++++- qubes/vm/__init__.py | 13 +++++++------ relaxng/qubes.rng | 18 +++++++++++++----- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/doc/example.xml b/doc/example.xml index 130dc154..c33c232c 100644 --- a/doc/example.xml +++ b/doc/example.xml @@ -22,7 +22,9 @@ - + + + diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 425b837d..c3fb2f99 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -76,7 +76,9 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): - + + + @@ -111,6 +113,11 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): self.assertCountEqual(list(vm.devices['pci'].persistent()), [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') def test_001_nxproperty(self): diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index c88a97c3..d9532f53 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -289,8 +289,8 @@ class BaseVM(qubes.PropertyHolder): devclass = parent.get('class') for node in parent.xpath('./device'): options = {} - if node.get('options'): - options = node.get('options').attribs(), + for option in node.xpath('./option'): + options[option.get('name')] = option.text device_assignment = qubes.devices.DeviceAssignment( self.app.domains[node.get('backend-domain')], @@ -331,10 +331,11 @@ class BaseVM(qubes.PropertyHolder): node = lxml.etree.Element('device') node.set('backend-domain', device.backend_domain.name) node.set('id', device.ident) - options_node = lxml.etree.Element('options') - for key, val in device.options: - options_node.set(key, val) - node.append(options_node) + for key, val in device.options.items(): + option_node = lxml.etree.Element('option') + option_node.set('name', key) + option_node.text = val + node.append(option_node) devices.append(node) element.append(devices) diff --git a/relaxng/qubes.rng b/relaxng/qubes.rng index b8f070c9..f3641562 100644 --- a/relaxng/qubes.rng +++ b/relaxng/qubes.rng @@ -224,15 +224,23 @@ the parser will complain about missing combine= attribute on the second . [0-9a-f]{2}_[0-9a-f]{2}.[0-9a-f]{2} - - - - Options + + + + Options + + + + Option name. + + [a-z0-9_-]+ + + - +