tweak AsyncSnapd api slightly

also remove dry-run delay for requests to /v2/change/{id}
This commit is contained in:
Michael Hudson-Doyle 2022-09-28 15:59:44 +13:00
parent 97c276faca
commit 521e7026de
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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)