diff --git a/qubes/api/admin.py b/qubes/api/admin.py index 25a542fd..9d88ffa6 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -559,8 +559,19 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI): self.fire_event_for_permission(pool=pool) + size_info = '' + try: + size_info += 'size={}\n'.format(pool.size) + except NotImplementedError: + pass + try: + size_info += 'usage={}\n'.format(pool.usage) + except NotImplementedError: + pass + return ''.join('{}={}\n'.format(prop, val) - for prop, val in sorted(pool.config.items())) + for prop, val in sorted(pool.config.items())) + \ + size_info @qubes.api.method('admin.pool.Add', scope='global', write=True) diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index a3c4b037..ed737ed6 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -545,11 +545,29 @@ class TC_00_VMs(AdminAPITestCase): def test_150_pool_info(self): self.app.pools = { 'pool1': unittest.mock.Mock(config={ - 'param1': 'value1', 'param2': 'value2'}) + 'param1': 'value1', 'param2': 'value2'}, + usage=102400, + size=204800) } value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1') - self.assertEqual(value, 'param1=value1\nparam2=value2\n') + self.assertEqual(value, + 'param1=value1\nparam2=value2\nsize=204800\nusage=102400\n') + self.assertFalse(self.app.save.called) + + def test_151_pool_info_unsupported_size(self): + self.app.pools = { + 'pool1': unittest.mock.Mock(config={ + 'param1': 'value1', 'param2': 'value2'}) + } + type(self.app.pools['pool1']).size = unittest.mock.PropertyMock( + side_effect=NotImplementedError) + type(self.app.pools['pool1']).usage = unittest.mock.PropertyMock( + side_effect=NotImplementedError) + value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1') + + self.assertEqual(value, + 'param1=value1\nparam2=value2\n') self.assertFalse(self.app.save.called) @unittest.mock.patch('qubes.storage.pool_drivers')