Merge ~jocave/checkbox-support:snapd-install-improvements into checkbox-support:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: a5f45712e77012a881e419a79c1669a524f6f07e
Merged at revision: 51bd2a261a902bd63287f1788f983f0f47136cdd
Proposed branch: ~jocave/checkbox-support:snapd-install-improvements
Merge into: checkbox-support:master
Diff against target: 65 lines (+24/-3)
1 file modified
checkbox_support/snap_utils/snapd.py (+24/-3)
Reviewer Review Type Date Requested Status
Devices Certification Bot Needs Fixing
Sylvain Pineau (community) Approve
Review via email: mp+378972@code.launchpad.net

Description of the change

Some improvements to the snapd class used by the snappy tests in particular. First commit adds a call to abort the change if the timeout is reached. Second commit just provides information about the tasks in progress to help diagnose problems like slow installs.

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

Modified second commit to make verbose output to be off by default

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

LGTM

review: Approve
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

[xenial] [13:45:56] starting container
[bionic] [13:45:56] starting container
Device project added to xenial-testing
Device project added to bionic-testing
[xenial] [13:46:06] provisioning container
[bionic] [13:46:11] provisioning container
[xenial] [13:46:37] Unable to provision requirements in container!
[xenial] output: https://paste.ubuntu.com/p/4bCRvWpk5m/
[xenial] [13:46:39] Fixing file permissions in source directory
[xenial] Destroying failed container to reclaim resources
[bionic] [13:47:05] Unable to provision requirements in container!
[bionic] output: https://paste.ubuntu.com/p/JcgFcQj3R9/
[bionic] [13:47:07] Fixing file permissions in source directory
[bionic] Destroying failed container to reclaim resources

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/snap_utils/snapd.py b/checkbox_support/snap_utils/snapd.py
2index 84ff9f5..8cb5c7c 100644
3--- a/checkbox_support/snap_utils/snapd.py
4+++ b/checkbox_support/snap_utils/snapd.py
5@@ -12,8 +12,9 @@ import requests_unixsocket
6
7 class AsyncException(Exception):
8
9- def __init__(self, message):
10+ def __init__(self, message, abort_message=''):
11 self.message = message
12+ self.abort_message = abort_message
13
14
15 class Snapd():
16@@ -27,10 +28,15 @@ class Snapd():
17 _interfaces = '/v2/interfaces'
18 _assertions = '/v2/assertions'
19
20- def __init__(self, task_timeout=30, poll_interval=1):
21+ def __init__(self, task_timeout=30, poll_interval=1, verbose=False):
22 self._session = requests_unixsocket.Session()
23 self._task_timeout = task_timeout
24 self._poll_interval = poll_interval
25+ self._verbose = verbose
26+
27+ def _info(self, msg):
28+ if self._verbose:
29+ print('(info) {}'.format(msg), flush=True)
30
31 def _get(self, path, params=None, decode=True):
32 r = self._session.get(self._url + path, params=params)
33@@ -60,9 +66,19 @@ class Snapd():
34 if status == 'Done':
35 return True
36 if time.time() > maxtime:
37- raise AsyncException(status)
38+ abort_result = self._abort_change(change_id)
39+ raise AsyncException(status, abort_result)
40+ for task in self.tasks(change_id):
41+ if task['status'] == 'Doing':
42+ self._info(task['summary'])
43 time.sleep(self._poll_interval)
44
45+ def _abort_change(self, change_id):
46+ path = self._changes + '/' + change_id
47+ data = {'action': 'abort'}
48+ r = self._post(path, json.dumps(data))
49+ return r['result']['status']
50+
51 def list(self, snap=None):
52 path = self._snaps
53 if snap is not None:
54@@ -111,6 +127,11 @@ class Snapd():
55 r = self._get(path)
56 return r['result']['status']
57
58+ def tasks(self, change_id):
59+ path = self._changes + '/' + change_id
60+ r = self._get(path)
61+ return r['result']['tasks']
62+
63 def revert(self, snap, channel='stable', revision=None):
64 path = self._snaps + '/' + snap
65 data = {'action': 'revert', 'channel': channel}

Subscribers

People subscribed via source and target branches