Просмотр исходного кода

devices,features: fix bool values handling

API define False value serialized as '' and True as 'True'. Do not
serialize 0 as '' (features) or True as 'yes' (devices).
Marek Marczykowski-Górecki 6 лет назад
Родитель
Сommit
a91372a919

+ 1 - 1
qubesadmin/devices.py

@@ -144,7 +144,7 @@ class DeviceCollection(object):
 
         options = device_assignment.options.copy()
         if device_assignment.persistent:
-            options['persistent'] = 'yes'
+            options['persistent'] = 'True'
         options_str = ' '.join('{}={}'.format(opt,
             val) for opt, val in sorted(options.items()))
         self._vm.qubesd_call(None,

+ 1 - 1
qubesadmin/features.py

@@ -42,7 +42,7 @@ class Features(object):
         self.vm.qubesd_call(self.vm.name, 'admin.vm.feature.Remove', key)
 
     def __setitem__(self, key, value):
-        if not value:
+        if value is False:
             # False value needs to be serialized as empty string
             self.vm.qubesd_call(self.vm.name, 'admin.vm.feature.Set', key, b'')
         else:

+ 2 - 2
qubesadmin/tests/devices.py

@@ -129,7 +129,7 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
     def test_022_attach_persistent(self):
         self.app.expected_calls[
             ('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1',
-            b'persistent=yes')] = b'0\0'
+            b'persistent=True')] = b'0\0'
         assign = qubesadmin.devices.DeviceAssignment(
             self.app.domains['test-vm2'], 'dev1')
         assign.persistent = True
@@ -139,7 +139,7 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
     def test_023_attach_persistent_options(self):
         self.app.expected_calls[
             ('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1',
-            b'persistent=yes ro=True')] = b'0\0'
+            b'persistent=True ro=True')] = b'0\0'
         assign = qubesadmin.devices.DeviceAssignment(
             self.app.domains['test-vm2'], 'dev1')
         assign.persistent = True

+ 2 - 2
qubesadmin/tests/tools/qvm_device.py

@@ -87,7 +87,7 @@ class TC_00_qvm_device(qubesadmin.tests.QubesTestCase):
             None, None)] = b'0\0'
         self.app.expected_calls[('test-vm3', 'admin.vm.device.test.List',
             None, None)] = \
-            b'0\0test-vm1+dev1 persistent=yes\n'
+            b'0\0test-vm1+dev1 persistent=True\n'
 
         with qubesadmin.tests.tools.StdoutBuffer() as buf:
             qubesadmin.tools.qvm_device.main(
@@ -144,7 +144,7 @@ class TC_00_qvm_device(qubesadmin.tests.QubesTestCase):
     def test_011_attach_persistent(self):
         ''' Test attach action '''
         self.app.expected_calls[('test-vm2', 'admin.vm.device.test.Attach',
-            'test-vm1+dev1', b'persistent=yes')] = b'0\0'
+            'test-vm1+dev1', b'persistent=True')] = b'0\0'
         qubesadmin.tools.qvm_device.main(
             ['test', 'attach', '-p', 'test-vm2', 'test-vm1:dev1'],
             app=self.app)