storage: use None for size/usage properties if unknown

Raising NotImplementedError in a _property_ is weird behaviour, better
suited for actions (methods). Use None instead.

QubesOS/qubes-issues#3241
This commit is contained in:
Marek Marczykowski-Górecki 2018-03-20 17:19:50 +01:00
parent 05c80c4531
commit 03dc3e315e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 13 additions and 17 deletions

View File

@ -607,14 +607,13 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
self.fire_event_for_permission(pool=pool) self.fire_event_for_permission(pool=pool)
other_info = '' other_info = ''
try: pool_size = pool.size
other_info += 'size={}\n'.format(pool.size) if pool_size is not None:
except NotImplementedError: other_info += 'size={}\n'.format(pool_size)
pass
try: pool_usage = pool.usage
other_info += 'usage={}\n'.format(pool.usage) if pool_usage is not None:
except NotImplementedError: other_info += 'usage={}\n'.format(pool_usage)
pass
try: try:
included_in = pool.included_in(self.app) included_in = pool.included_in(self.app)

View File

@ -828,13 +828,13 @@ class Pool(object):
@property @property
def size(self): def size(self):
''' Storage pool size in bytes ''' ''' Storage pool size in bytes, or None if unknown '''
raise self._not_implemented("size") return None
@property @property
def usage(self): def usage(self):
''' Space used in the pool, in bytes ''' ''' Space used in the pool in bytes, or None if unknown '''
raise self._not_implemented("usage") return None
def _not_implemented(self, method_name): def _not_implemented(self, method_name):
''' Helper for emitting helpful `NotImplementedError` exceptions ''' ''' Helper for emitting helpful `NotImplementedError` exceptions '''

View File

@ -567,13 +567,10 @@ class TC_00_VMs(AdminAPITestCase):
def test_151_pool_info_unsupported_size(self): def test_151_pool_info_unsupported_size(self):
self.app.pools = { self.app.pools = {
'pool1': unittest.mock.Mock(config={ 'pool1': unittest.mock.Mock(config={
'param1': 'value1', 'param2': 'value2'}) 'param1': 'value1', 'param2': 'value2'},
size=None, usage=None),
} }
self.app.pools['pool1'].included_in.return_value = None 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(
side_effect=NotImplementedError)
value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1') value = self.call_mgmt_func(b'admin.pool.Info', b'dom0', b'pool1')
self.assertEqual(value, self.assertEqual(value,