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).
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-16 01:10:03 +02:00
parent 2ab31e63dc
commit a91372a919
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 6 additions and 6 deletions

View File

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

View File

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

View File

@ -129,7 +129,7 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
def test_022_attach_persistent(self): def test_022_attach_persistent(self):
self.app.expected_calls[ self.app.expected_calls[
('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1', ('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( assign = qubesadmin.devices.DeviceAssignment(
self.app.domains['test-vm2'], 'dev1') self.app.domains['test-vm2'], 'dev1')
assign.persistent = True assign.persistent = True
@ -139,7 +139,7 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
def test_023_attach_persistent_options(self): def test_023_attach_persistent_options(self):
self.app.expected_calls[ self.app.expected_calls[
('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1', ('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( assign = qubesadmin.devices.DeviceAssignment(
self.app.domains['test-vm2'], 'dev1') self.app.domains['test-vm2'], 'dev1')
assign.persistent = True assign.persistent = True

View File

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