features: fix serialization

qubesd_call expect "bytes" type. Additionally serialize false value as
empty string (which is treated by python as false value), because
otherwise would be serialized to (non-empty) string, which is true value
in python.
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-18 09:48:18 +02:00
parent 3217d8af6f
commit ee81902979
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 7 additions and 2 deletions

View File

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

View File

@ -51,7 +51,7 @@ class TC_00_qvm_features(qubesadmin.tests.QubesTestCase):
b'0\x00some-vm class=AppVM state=Running\n'
self.app.expected_calls[
('some-vm', 'admin.vm.feature.Set',
'feature3', 'value of feature')] = b'0\x00'
'feature3', b'value of feature')] = b'0\x00'
self.assertEqual(
qubesadmin.tools.qvm_features.main(['some-vm', 'feature3',
'value of feature'],