From 7f5feac98b7ff1332510b95e24043205323bda9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 3 Apr 2016 03:43:01 +0200 Subject: [PATCH] qubes/vm: fixes for features handling Properly handle 'None' value, there is no difference between empty string () and no content at all (). --- qubes/tests/vm/init.py | 2 -- qubes/vm/__init__.py | 6 +++--- relaxng/qubes.rng | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 83dd8d55..436279a4 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -61,7 +61,6 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): - aqq @@ -92,7 +91,6 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase): self.assertEqual(vm.defaultprop, 'defaultvalue') self.assertEqual(vm.tags, {'testtag': 'tagvalue'}) self.assertEqual(vm.features, { - 'testfeature_none': None, 'testfeature_empty': '', 'testfeature_aqq': 'aqq', }) diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index c72474cc..097d1c09 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -79,7 +79,7 @@ class Features(dict): self.vm.fire_event('domain-feature-delete', key) def __setitem__(self, key, value): - if isinstance(value, bool): + if value is None or isinstance(value, bool): value = '1' if value else '' else: value = str(value) @@ -185,7 +185,7 @@ class BaseVM(qubes.PropertyHolder): if self.xml is not None: # features - for node in xml.xpath('./features/service'): + for node in xml.xpath('./features/feature'): self.features[node.get('name')] = node.text # devices (pci, usb, ...) @@ -231,7 +231,7 @@ class BaseVM(qubes.PropertyHolder): features = lxml.etree.Element('features') for feature in self.features: - node = lxml.etree.Element('service', name=feature) + node = lxml.etree.Element('feature', name=feature) node.text = self.features[feature] features.append(node) element.append(features) diff --git a/relaxng/qubes.rng b/relaxng/qubes.rng index c40b4534..667e263b 100644 --- a/relaxng/qubes.rng +++ b/relaxng/qubes.rng @@ -175,7 +175,7 @@ the parser will complain about missing combine= attribute on the second . - [a-z0-9_-]+ + [a-z0-9_-]*