From 1481dc4fb867e5509c65d4a24ba76b66617f38e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 5 Sep 2017 03:59:01 +0200 Subject: [PATCH] devices: client stub for DeviceCollection.update_persistent QubesOS/qubes-issues#3055 --- qubesadmin/devices.py | 13 +++++++++++++ qubesadmin/tests/devices.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/qubesadmin/devices.py b/qubesadmin/devices.py index 1d0bf5b..a64cd14 100644 --- a/qubesadmin/devices.py +++ b/qubesadmin/devices.py @@ -229,6 +229,19 @@ class DeviceCollection(object): yield DeviceInfo(self._vm, ident, description=description, options=None, **info_dict) + def update_persistent(self, device, persistent): + '''Update `persistent` flag of already attached device. + + :param DeviceInfo device: device for which change persistent flag + :param bool persistent: new persistent flag + ''' + + self._vm.qubesd_call(None, + 'admin.vm.device.{}.Set.persistent'.format(self._class), + '{!s}+{!s}'.format(device.backend_domain, + device.ident), + str(persistent).encode('utf-8')) + __iter__ = available def clear_cache(self): diff --git a/qubesadmin/tests/devices.py b/qubesadmin/tests/devices.py index 7c3f2ed..88c3d36 100644 --- a/qubesadmin/tests/devices.py +++ b/qubesadmin/tests/devices.py @@ -293,3 +293,20 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase): self.assertEqual(devs[1].ident, 'dev2') self.assertAllCalled() + def test_070_update_persistent(self): + self.app.expected_calls[ + ('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1', + b'True')] = b'0\0' + dev = qubesadmin.devices.DeviceInfo( + self.app.domains['test-vm2'], 'dev1') + self.vm.devices['test'].update_persistent(dev, True) + self.assertAllCalled() + + def test_071_update_persistent_false(self): + self.app.expected_calls[ + ('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1', + b'False')] = b'0\0' + dev = qubesadmin.devices.DeviceInfo( + self.app.domains['test-vm2'], 'dev1') + self.vm.devices['test'].update_persistent(dev, False) + self.assertAllCalled()