From 0fae70be53823222a54757ef4ca0b629ebaa47e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 28 Jul 2017 13:56:05 +0200 Subject: [PATCH] features: serialize True as '1' Do the same as core-admin code. --- qubesadmin/features.py | 5 +++-- qubesadmin/tests/backup/backupcompatibility.py | 2 ++ qubesadmin/tests/features.py | 2 +- qubesadmin/tests/tools/qvm_template_postprocess.py | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/qubesadmin/features.py b/qubesadmin/features.py index 4ed8ef8..e7a9cee 100644 --- a/qubesadmin/features.py +++ b/qubesadmin/features.py @@ -42,9 +42,10 @@ class Features(object): self.vm.qubesd_call(self.vm.name, 'admin.vm.feature.Remove', key) def __setitem__(self, key, value): - if value is False: + if isinstance(value, bool): # 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'1' if value else b'') else: self.vm.qubesd_call(self.vm.name, 'admin.vm.feature.Set', key, str(value).encode()) diff --git a/qubesadmin/tests/backup/backupcompatibility.py b/qubesadmin/tests/backup/backupcompatibility.py index b6e0d02..b70b9ea 100644 --- a/qubesadmin/tests/backup/backupcompatibility.py +++ b/qubesadmin/tests/backup/backupcompatibility.py @@ -1354,6 +1354,8 @@ class TC_10_BackupCompatibility(qubesadmin.tests.backup.BackupTestCase): for feature, value in vm['features'].items(): if value is False: value = '' + elif value is True: + value = '1' self.app.expected_calls[ (name, 'admin.vm.feature.Set', feature, str(value).encode())] = b'0\0' diff --git a/qubesadmin/tests/features.py b/qubesadmin/tests/features.py index 0a1d30c..d66cdce 100644 --- a/qubesadmin/tests/features.py +++ b/qubesadmin/tests/features.py @@ -78,7 +78,7 @@ class TC_00_Features(qubesadmin.tests.QubesTestCase): def test_021_set_bool(self): self.app.expected_calls[ - ('test-vm', 'admin.vm.feature.Set', 'feature1', b'True')] = \ + ('test-vm', 'admin.vm.feature.Set', 'feature1', b'1')] = \ b'0\0' self.vm.features['feature1'] = True self.assertAllCalled() diff --git a/qubesadmin/tests/tools/qvm_template_postprocess.py b/qubesadmin/tests/tools/qvm_template_postprocess.py index 78d8009..e2d74c9 100644 --- a/qubesadmin/tests/tools/qvm_template_postprocess.py +++ b/qubesadmin/tests/tools/qvm_template_postprocess.py @@ -243,7 +243,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'admin.vm.property.Reset', 'netvm', None)] = b'0\0' self.app.expected_calls[ - ('test-vm', 'admin.vm.feature.Set', 'qrexec', b'True')] = b'0\0' + ('test-vm', 'admin.vm.feature.Set', 'qrexec', b'1')] = b'0\0' self.app.expected_calls[ ('test-vm', 'admin.vm.Start', None, None)] = b'0\0' self.app.expected_calls[ @@ -293,7 +293,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase): self.app.expected_calls[ ('test-vm', 'admin.vm.property.Reset', 'netvm', None)] = b'0\0' self.app.expected_calls[ - ('test-vm', 'admin.vm.feature.Set', 'qrexec', b'True')] = b'0\0' + ('test-vm', 'admin.vm.feature.Set', 'qrexec', b'1')] = b'0\0' self.app.expected_calls[ ('test-vm', 'admin.vm.Start', None, None)] = b'0\0' self.app.expected_calls[