From 1bc640f3e095555e48eca7815aaa0aed131c7d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 19 Mar 2018 22:43:02 +0100 Subject: [PATCH] api/admin: add 'included_in' to admin.pool.Info call QubesOS/qubes-issues#3240 QubesOS/qubes-issues#3241 --- qubes/api/admin.py | 15 +++++++++++---- qubes/tests/api_admin.py | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/qubes/api/admin.py b/qubes/api/admin.py index c5bdb997..80408dff 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -606,19 +606,26 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI): self.fire_event_for_permission(pool=pool) - size_info = '' + other_info = '' try: - size_info += 'size={}\n'.format(pool.size) + other_info += 'size={}\n'.format(pool.size) except NotImplementedError: pass try: - size_info += 'usage={}\n'.format(pool.usage) + other_info += 'usage={}\n'.format(pool.usage) + except NotImplementedError: + pass + + try: + included_in = pool.included_in(self.app) + if included_in: + other_info += 'included_in={}\n'.format(str(included_in)) except NotImplementedError: pass return ''.join('{}={}\n'.format(prop, val) for prop, val in sorted(pool.config.items())) + \ - size_info + other_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 9df2df9c..998587ce 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -557,6 +557,7 @@ class TC_00_VMs(AdminAPITestCase): usage=102400, size=204800) } + self.app.pools['pool1'].included_in.return_value = None value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1') self.assertEqual(value, @@ -568,6 +569,7 @@ class TC_00_VMs(AdminAPITestCase): 'pool1': unittest.mock.Mock(config={ 'param1': 'value1', 'param2': 'value2'}) } + self.app.pools['pool1'].included_in.return_value = None type(self.app.pools['pool1']).size = unittest.mock.PropertyMock( side_effect=NotImplementedError) type(self.app.pools['pool1']).usage = unittest.mock.PropertyMock( @@ -578,6 +580,24 @@ class TC_00_VMs(AdminAPITestCase): 'param1=value1\nparam2=value2\n') self.assertFalse(self.app.save.called) + def test_152_pool_info_included_in(self): + self.app.pools = { + 'pool1': unittest.mock.MagicMock(config={ + 'param1': 'value1', + 'param2': 'value2'}, + usage=102400, + size=204800) + } + self.app.pools['pool1'].included_in.return_value = \ + self.app.pools['pool1'] + self.app.pools['pool1'].__str__.return_value = 'pool1' + value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1') + + self.assertEqual(value, + 'param1=value1\nparam2=value2\nsize=204800\nusage=102400' + '\nincluded_in=pool1\n') + self.assertFalse(self.app.save.called) + @unittest.mock.patch('qubes.storage.pool_drivers') @unittest.mock.patch('qubes.storage.driver_parameters') def test_160_pool_add(self, mock_parameters, mock_drivers):