Browse Source

api/admin: implement admin.pool.volume.List method

Similar to admin.vm.volume.List. There are still other
admin.pool.volume.* methods missing, but lets start with just this one.
Those with both pool name and volume id arguments may need some more
thoughts.
Marek Marczykowski-Górecki 4 years ago
parent
commit
263f218d40
2 changed files with 26 additions and 0 deletions
  1. 12 0
      qubes/api/admin.py
  2. 14 0
      qubes/tests/api_admin.py

+ 12 - 0
qubes/api/admin.py

@@ -713,6 +713,18 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
         yield from self.app.remove_pool(self.arg)
         self.app.save()
 
+    @qubes.api.method('admin.pool.volume.List', no_payload=True,
+        scope='global', read=True)
+    @asyncio.coroutine
+    def pool_volume_list(self):
+        self.enforce(self.dest.name == 'dom0')
+        self.enforce(self.arg in self.app.pools.keys())
+
+        pool = self.app.pools[self.arg]
+
+        volume_names = self.fire_event_for_filter(pool.volumes.keys())
+        return ''.join('{}\n'.format(name) for name in volume_names)
+
     @qubes.api.method('admin.pool.Set.revisions_to_keep',
         scope='global', write=True)
     @asyncio.coroutine

+ 14 - 0
qubes/tests/api_admin.py

@@ -2545,6 +2545,18 @@ class TC_00_VMs(AdminAPITestCase):
         with self.assertRaises(qubes.exc.QubesVMNotRunningError):
             self.call_mgmt_func(b'admin.vm.Console', b'test-vm1')
 
+    def test_700_pool_volume_list(self):
+        self.app.pools = {
+            'pool1': unittest.mock.Mock(config={
+                'param1': 'value1', 'param2': 'value2'},
+                usage=102400,
+                size=204800,
+                volumes={'vol1': unittest.mock.Mock(),
+                         'vol2': unittest.mock.Mock()})
+        }
+        value = self.call_mgmt_func(b'admin.pool.volume.List', b'dom0', b'pool1')
+        self.assertEqual(value, 'vol1\nvol2\n')
+
     def test_990_vm_unexpected_payload(self):
         methods_with_no_payload = [
             b'admin.vm.List',
@@ -2652,6 +2664,7 @@ class TC_00_VMs(AdminAPITestCase):
             b'admin.deviceclass.List',
             b'admin.vmclass.List',
             b'admin.vm.List',
+            b'admin.pool.volume.List',
             b'admin.label.List',
             b'admin.label.Get',
             b'admin.label.Remove',
@@ -2735,6 +2748,7 @@ class TC_00_VMs(AdminAPITestCase):
             b'admin.label.Create',
             b'admin.label.Get',
             b'admin.label.Remove',
+            b'admin.pool.volume.List',
             b'admin.property.List',
             b'admin.property.Get',
             b'admin.property.Set',