api/admin: add pool size and usage to admin.pool.Info response
QubesOS/qubes-issues#3240
This commit is contained in:
parent
e76372b934
commit
f18f4c9bff
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user