From ee81902979d44c3ccda17a85b917b3876e6e1de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 May 2017 09:48:18 +0200 Subject: [PATCH] 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. --- qubesadmin/features.py | 7 ++++++- qubesadmin/tests/tools/qvm_features.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qubesadmin/features.py b/qubesadmin/features.py index 8869df4..0eeef74 100644 --- a/qubesadmin/features.py +++ b/qubesadmin/features.py @@ -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( diff --git a/qubesadmin/tests/tools/qvm_features.py b/qubesadmin/tests/tools/qvm_features.py index c725842..ea85e51 100644 --- a/qubesadmin/tests/tools/qvm_features.py +++ b/qubesadmin/tests/tools/qvm_features.py @@ -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'],