From 5605942e709a9e6d4773c3f0fe6ef2e55d78753d Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 3 May 2024 17:23:53 +1200 Subject: [PATCH] Add a way to annotate the result of a asynchronous snapd operation --- subiquity/server/snapdapi.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/subiquity/server/snapdapi.py b/subiquity/server/snapdapi.py index 4173c5aa..8af125cc 100644 --- a/subiquity/server/snapdapi.py +++ b/subiquity/server/snapdapi.py @@ -313,14 +313,17 @@ def make_api_client(async_snapd): snapd_serializer = Serializer(ignore_unknown_fields=True, serialize_enums_by="value") -async def post_and_wait(client, meth, *args, **kw): +async def post_and_wait(client, meth, *args, ann=None, **kw): change_id = await meth(*args, **kw) log.debug("post_and_wait %s", change_id) while True: result = await client.v2.changes[change_id].GET() if result.status == TaskStatus.DONE: - return result.data + data = result.data + if ann is not None: + data = snapd_serializer.deserialize(ann, data) + return data elif result.status == TaskStatus.ERROR: raise aiohttp.ClientError(result.err) await asyncio.sleep(0.1)