Merge ~jocave/checkbox-support:snap-utils-system into checkbox-support:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 07ba6da2a78e665389b41f148bb81690c3f2634e
Merged at revision: b1d7e5e3a351aa2f5a6298e885be2663d264dd9d
Proposed branch: ~jocave/checkbox-support:snap-utils-system
Merge into: checkbox-support:master
Diff against target: 60 lines (+54/-0)
1 file modified
checkbox_support/snap_utils/system.py (+54/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+365909@code.launchpad.net

Description of the change

Add some functions that use snapd API to get information about the running system. Mostly assertion parsing code I think shouldn't be copied around our test code base.

Tested using the new resource job that will follow in a p-p-resource MR.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/snap_utils/system.py b/checkbox_support/snap_utils/system.py
2new file mode 100644
3index 0000000..8e3e80c
4--- /dev/null
5+++ b/checkbox_support/snap_utils/system.py
6@@ -0,0 +1,54 @@
7+# Copyright 2019 Canonical Ltd.
8+# All rights reserved.
9+#
10+# Written by:
11+# Jonathan Cave <jonathan.cave@canonical.com>
12+
13+import io
14+import yaml
15+
16+from checkbox_support.snap_utils.snapd import Snapd
17+
18+
19+def get_kernel_snap():
20+ snap = None
21+ assertion_stream = Snapd().get_assertions('model')
22+ count = int(assertion_stream.headers['X-Ubuntu-Assertions-Count'])
23+ if count > 0:
24+ for line in io.StringIO(assertion_stream.text):
25+ if line.count(':') == 1:
26+ key, val = [x.strip() for x in line.split(':')]
27+ if key == 'kernel':
28+ if '=' in val:
29+ snap, _ = [x.strip() for x in val.split('=')]
30+ else:
31+ snap = val
32+ break
33+ return snap
34+
35+
36+def get_gadget_snap():
37+ snap = None
38+ assertion_stream = Snapd().get_assertions('model')
39+ count = int(assertion_stream.headers['X-Ubuntu-Assertions-Count'])
40+ if count > 0:
41+ for line in io.StringIO(assertion_stream.text):
42+ if line.count(':') == 1:
43+ key, val = [x.strip() for x in line.split(':')]
44+ if key == 'gadget':
45+ if '=' in val:
46+ snap, _ = [x.strip() for x in val.split('=')]
47+ else:
48+ snap = val
49+ break
50+ return snap
51+
52+
53+def get_bootloader():
54+ bootloader = None
55+ gadget_yaml = '/snap/{}/current/meta/gadget.yaml'.format(get_gadget_snap())
56+ with open(gadget_yaml) as f:
57+ data = yaml.load(f)
58+ for k in data['volumes'].keys():
59+ bootloader = data['volumes'][k]['bootloader']
60+ return bootloader

Subscribers

People subscribed via source and target branches