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:
parent
05c80c4531
commit
03dc3e315e
@ -607,14 +607,13 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
|
||||
self.fire_event_for_permission(pool=pool)
|
||||
|
||||
other_info = ''
|
||||
try:
|
||||
other_info += 'size={}\n'.format(pool.size)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
try:
|
||||
other_info += 'usage={}\n'.format(pool.usage)
|
||||
except NotImplementedError:
|
||||
pass
|
||||
pool_size = pool.size
|
||||
if pool_size is not None:
|
||||
other_info += 'size={}\n'.format(pool_size)
|
||||
|
||||
pool_usage = pool.usage
|
||||
if pool_usage is not None:
|
||||
other_info += 'usage={}\n'.format(pool_usage)
|
||||
|
||||
try:
|
||||
included_in = pool.included_in(self.app)
|
||||
|
@ -828,13 +828,13 @@ class Pool(object):
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
''' Storage pool size in bytes '''
|
||||
raise self._not_implemented("size")
|
||||
''' Storage pool size in bytes, or None if unknown '''
|
||||
return None
|
||||
|
||||
@property
|
||||
def usage(self):
|
||||
''' Space used in the pool, in bytes '''
|
||||
raise self._not_implemented("usage")
|
||||
''' Space used in the pool in bytes, or None if unknown '''
|
||||
return None
|
||||
|
||||
def _not_implemented(self, method_name):
|
||||
''' Helper for emitting helpful `NotImplementedError` exceptions '''
|
||||
|
@ -567,13 +567,10 @@ class TC_00_VMs(AdminAPITestCase):
|
||||
def test_151_pool_info_unsupported_size(self):
|
||||
self.app.pools = {
|
||||
'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
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user