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
diff --git a/checkbox_support/snap_utils/snapd.py b/checkbox_support/snap_utils/snapd.py
index 84ff9f5..8cb5c7c 100644
--- a/checkbox_support/snap_utils/snapd.py
+++ b/checkbox_support/snap_utils/snapd.py
@@ -12,8 +12,9 @@ import requests_unixsocket
1212
13class AsyncException(Exception):13class AsyncException(Exception):
1414
15 def __init__(self, message):15 def __init__(self, message, abort_message=''):
16 self.message = message16 self.message = message
17 self.abort_message = abort_message
1718
1819
19class Snapd():20class Snapd():
@@ -27,10 +28,15 @@ class Snapd():
27 _interfaces = '/v2/interfaces'28 _interfaces = '/v2/interfaces'
28 _assertions = '/v2/assertions'29 _assertions = '/v2/assertions'
2930
30 def __init__(self, task_timeout=30, poll_interval=1):31 def __init__(self, task_timeout=30, poll_interval=1, verbose=False):
31 self._session = requests_unixsocket.Session()32 self._session = requests_unixsocket.Session()
32 self._task_timeout = task_timeout33 self._task_timeout = task_timeout
33 self._poll_interval = poll_interval34 self._poll_interval = poll_interval
35 self._verbose = verbose
36
37 def _info(self, msg):
38 if self._verbose:
39 print('(info) {}'.format(msg), flush=True)
3440
35 def _get(self, path, params=None, decode=True):41 def _get(self, path, params=None, decode=True):
36 r = self._session.get(self._url + path, params=params)42 r = self._session.get(self._url + path, params=params)
@@ -60,9 +66,19 @@ class Snapd():
60 if status == 'Done':66 if status == 'Done':
61 return True67 return True
62 if time.time() > maxtime:68 if time.time() > maxtime:
63 raise AsyncException(status)69 abort_result = self._abort_change(change_id)
70 raise AsyncException(status, abort_result)
71 for task in self.tasks(change_id):
72 if task['status'] == 'Doing':
73 self._info(task['summary'])
64 time.sleep(self._poll_interval)74 time.sleep(self._poll_interval)
6575
76 def _abort_change(self, change_id):
77 path = self._changes + '/' + change_id
78 data = {'action': 'abort'}
79 r = self._post(path, json.dumps(data))
80 return r['result']['status']
81
66 def list(self, snap=None):82 def list(self, snap=None):
67 path = self._snaps83 path = self._snaps
68 if snap is not None:84 if snap is not None:
@@ -111,6 +127,11 @@ class Snapd():
111 r = self._get(path)127 r = self._get(path)
112 return r['result']['status']128 return r['result']['status']
113129
130 def tasks(self, change_id):
131 path = self._changes + '/' + change_id
132 r = self._get(path)
133 return r['result']['tasks']
134
114 def revert(self, snap, channel='stable', revision=None):135 def revert(self, snap, channel='stable', revision=None):
115 path = self._snaps + '/' + snap136 path = self._snaps + '/' + snap
116 data = {'action': 'revert', 'channel': channel}137 data = {'action': 'revert', 'channel': channel}

Subscribers

People subscribed via source and target branches