From a91372a919e0c291a952651c5abd3deea6bb2287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 16 Jul 2017 01:10:03 +0200 Subject: [PATCH] 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). --- qubesadmin/devices.py | 2 +- qubesadmin/features.py | 2 +- qubesadmin/tests/devices.py | 4 ++-- qubesadmin/tests/tools/qvm_device.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qubesadmin/devices.py b/qubesadmin/devices.py index e0192ba..1d0bf5b 100644 --- a/qubesadmin/devices.py +++ b/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, diff --git a/qubesadmin/features.py b/qubesadmin/features.py index cd33d59..4ed8ef8 100644 --- a/qubesadmin/features.py +++ b/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: diff --git a/qubesadmin/tests/devices.py b/qubesadmin/tests/devices.py index f169e09..7c3f2ed 100644 --- a/qubesadmin/tests/devices.py +++ b/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 diff --git a/qubesadmin/tests/tools/qvm_device.py b/qubesadmin/tests/tools/qvm_device.py index 4d70ef3..d0cdace 100644 --- a/qubesadmin/tests/tools/qvm_device.py +++ b/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)