diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index b8bd79d9..da518a99 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -801,10 +801,13 @@ class Pool: Contains data_usage for usage in bytes and data_size for pool size; other implementations may add more implementation-specific detail""" - return { - 'data_usage': self.usage, - 'data_size': self.size - } + result = {} + if self.usage is not None: + result['data_usage'] = self.usage + if self.size is not None: + result['data_size'] = self.size + + return result def _not_implemented(self, method_name): ''' Helper for emitting helpful `NotImplementedError` exceptions ''' diff --git a/qubes/tests/storage.py b/qubes/tests/storage.py index 6a49984b..fd58ae59 100644 --- a/qubes/tests/storage.py +++ b/qubes/tests/storage.py @@ -165,3 +165,32 @@ class TC_00_Pool(QubesTestCase): self.loop.run_until_complete(vm.create_on_disk(pool=pool)) with self.assertRaises(qubes.exc.QubesPoolInUseError): self.loop.run_until_complete(self.app.remove_pool(pool_name)) + + def test_006_pool_usage_qubespool(self): + qubes_pool = self.app.get_pool('varlibqubes') + + usage_details = qubes_pool.usage_details + + self.assertIsNotNone(usage_details['data_size'], + "Data size incorrectly reported as None") + self.assertIsNotNone(usage_details['data_usage'], + "Data usage incorrectly reported as None") + + def test_007_pool_kernels_usage(self): + pool_name = 'kernels_test_pools' + dir_path = '/tmp/{}'.format(pool_name) + pool = self.loop.run_until_complete( + self.app.add_pool(name=pool_name, + driver='linux-kernel', + dir_path=dir_path)) + self.assertTrue(self.assertPoolExists(pool_name)) + + qubes_pool = self.app.get_pool(pool_name) + + usage_details = qubes_pool.usage_details + + self.assertEqual(usage_details, + {}, + "Kernels pool should not report usage details.") + + self.loop.run_until_complete(self.app.remove_pool(pool_name))