Browse Source

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/>).
Marek Marczykowski-Górecki 8 years ago
parent
commit
7f5feac98b
3 changed files with 4 additions and 6 deletions
  1. 0 2
      qubes/tests/vm/init.py
  2. 3 3
      qubes/vm/__init__.py
  3. 1 1
      relaxng/qubes.rng

+ 0 - 2
qubes/tests/vm/init.py

@@ -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',
         })

+ 3 - 3
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)

+ 1 - 1
relaxng/qubes.rng

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