ソースを参照

devices: client stub for DeviceCollection.update_persistent

QubesOS/qubes-issues#3055
Marek Marczykowski-Górecki 7 年 前
コミット
1481dc4fb8
2 ファイル変更30 行追加0 行削除
  1. 13 0
      qubesadmin/devices.py
  2. 17 0
      qubesadmin/tests/devices.py

+ 13 - 0
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):

+ 17 - 0
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()