qubes/vm: fixes for features handling

Properly handle 'None' value, there is no difference between empty
string (<x></x>) and no content at all (<x/>).
This commit is contained in:
Marek Marczykowski-Górecki 2016-04-03 03:43:01 +02:00 committed by Wojtek Porczyk
parent 06c315c94b
commit 7f5feac98b
3 changed files with 4 additions and 6 deletions

View File

@ -61,7 +61,6 @@ class TC_10_BaseVM(qubes.tests.QubesTestCase):
</tags>
<features>
<feature name="testfeature_none"/>
<feature name="testfeature_empty"></feature>
<feature name="testfeature_aqq">aqq</feature>
</features>
@ -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',
})

View File

@ -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)

View File

@ -175,7 +175,7 @@ the parser will complain about missing combine= attribute on the second <start>.
</attribute>
<data type="string">
<param name="pattern">[a-z0-9_-]+</param>
<param name="pattern">[a-z0-9_-]*</param>
</data>
</element>
</oneOrMore>