From 521e7026de401bcd43dd928cd3296222bf7a095f Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 28 Sep 2022 15:59:44 +1300 Subject: [PATCH] tweak AsyncSnapd api slightly also remove dry-run delay for requests to /v2/change/{id} --- subiquity/server/controllers/refresh.py | 4 ++-- subiquitycore/snapd.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/subiquity/server/controllers/refresh.py b/subiquity/server/controllers/refresh.py index 5ef5693f..a4cbb001 100644 --- a/subiquity/server/controllers/refresh.py +++ b/subiquity/server/controllers/refresh.py @@ -213,9 +213,9 @@ class RefreshController(SubiquityController): @with_context() async def start_update(self, context): - change = await self.app.snapd.post( + change = (await self.app.snapd.post( 'v2/snaps/{}'.format(self.snap_name), - {'action': 'refresh', 'ignore-running': True}) + {'action': 'refresh', 'ignore-running': True}))['change'] context.description = "change id: {}".format(change) return change diff --git a/subiquitycore/snapd.py b/subiquitycore/snapd.py index 069a9ba9..70f29c45 100644 --- a/subiquitycore/snapd.py +++ b/subiquitycore/snapd.py @@ -152,7 +152,8 @@ class FakeSnapdConnection: "Don't know how to fake POST response to {}".format((path, args))) def get(self, path, **args): - time.sleep(1/self.scale_factor) + if 'change' not in path: + time.sleep(1/self.scale_factor) filename = path.replace('/', '-') if args: filename += '-' + urlencode(sorted(args.items())) @@ -184,10 +185,10 @@ class AsyncSnapd: response = await run_in_thread( partial(self.connection.post, path, body, **args)) response.raise_for_status() - return response.json()['change'] + return response.json() async def post_and_wait(self, path, body, **args): - change = await self.post(path, body, **args) + change = (await self.post(path, body, **args))['change'] change_path = 'v2/changes/{}'.format(change) while True: result = await self.get(change_path)