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()
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,

View File

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

View File

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

View File

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