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

Subscribers

People subscribed via source and target branches