From 2a962c54dbbad7aa074dee8f171a81b5ef80e864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 18 Mar 2018 21:45:43 +0100 Subject: [PATCH] api/admin: include 'revisions_to_keep' and 'is_outdated' in volume info Since Volume.is_outdated() is a method, not a property, add a function for handling serialization. And at the same time, fix None serialization (applicable to 'source' property). QubesOS/qubes-issues#3256 --- qubes/api/admin.py | 13 ++++++++++--- qubes/tests/api_admin.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/qubes/api/admin.py b/qubes/api/admin.py index b42d6479..f03560f3 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -336,9 +336,16 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI): # properties defined in API volume_properties = [ 'pool', 'vid', 'size', 'usage', 'rw', 'source', - 'save_on_stop', 'snap_on_start'] - return ''.join('{}={}\n'.format(key, getattr(volume, key)) for key in - volume_properties) + 'save_on_stop', 'snap_on_start', 'revisions_to_keep', 'is_outdated'] + + def _serialize(value): + if callable(value): + value = value() + if value is None: + value = '' + return str(value) + return ''.join('{}={}\n'.format(key, _serialize(getattr(volume, key))) + for key in volume_properties) @qubes.api.method('admin.vm.volume.ListSnapshots', no_payload=True, scope='local', read=True) diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index dcbe5522..ec59fd49 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -40,7 +40,7 @@ import qubes.storage # properties defined in API volume_properties = [ 'pool', 'vid', 'size', 'usage', 'rw', 'source', - 'save_on_stop', 'snap_on_start'] + 'save_on_stop', 'snap_on_start', 'revisions_to_keep', 'is_outdated'] class AdminAPITestCase(qubes.tests.QubesTestCase):