Merge ~jocave/plainbox-provider-resource:new-assertions-output into plainbox-provider-resource:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 4f537bb60908cf1e9cc9b9a8c3990ffe188f8f47
Merged at revision: 190df7d4fec0707a9316a67a2873b4a93e80f213
Proposed branch: ~jocave/plainbox-provider-resource:new-assertions-output
Merge into: plainbox-provider-resource:master
Diff against target: 81 lines (+13/-39)
1 file modified
bin/snapd_resource.py (+13/-39)
Reviewer Review Type Date Requested Status
Devices Certification Bot Needs Fixing
Sylvain Pineau (community) Approve
Sheila Miguez (community) Approve
Review via email: mp+391271@code.launchpad.net

Description of the change

Depends on https://code.launchpad.net/~jocave/checkbox-support/+git/checkbox-support/+merge/391270

Use the new functions in checkbox-support to output assertion information in the corresponding resource jobs. Now produces valid output on UC20.

To post a comment you must log in.
Revision history for this message
Sheila Miguez (codersquid) wrote :

I have a question about the cases where there are zero assertions.

Revision history for this message
Jonathan Cave (jocave) wrote :

> I have a question about the cases where there are zero assertions.

I deleted it because I thought I initially put it there because checkbox used to have a bug with resources that did not produce any resource units (i.e. the job outputted nothing). That bug was fixed.

Now I think about it I wonder if I was actually trying to prevent warnings being outputted on systems that had yet to receive an assertion for some reason. Tbh I can't remember what the scenario was.

Revision history for this message
Sheila Miguez (codersquid) wrote :

If it's okay not to print anything when there are no assertions then this lgtm. Maybe check with the others to see if they know about that before marking this as really approved.

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

@Sheila. Good question. Actually it's not needed anymore. Checkbox can now process empty resources w/o crashing. Needless to output dummy stuff.

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

The merge was fine but running tests failed.

[bionic] [17:16:03] starting container
[xenial] [17:16:04] starting container
[focal] [17:16:05] starting container
Device project added to bionic-testing
Device project added to xenial-testing
Device project added to focal-testing
[xenial] [17:16:16] provisioning container
[bionic] [17:16:22] provisioning container
[focal] [17:16:23] provisioning container
[xenial] [17:16:34] Starting tests...
[xenial] Found a test script: ./requirements/container-tests-provider-resource-generic
[bionic] [17:16:45] Starting tests...
[bionic] Found a test script: ./requirements/container-tests-provider-resource-generic
[focal] [17:16:58] Starting tests...
[focal] Found a test script: ./requirements/container-tests-provider-resource-generic
[focal] [17:18:04] container-tests-provider-resource-generic: FAIL
[focal] output: https://paste.ubuntu.com/p/gGvFCnRBpD/
[focal] [17:18:08] Fixing file permissions in source directory
[focal] [17:18:08] Destroying container
[bionic] [17:18:17] container-tests-provider-resource-generic: FAIL
[bionic] output: https://paste.ubuntu.com/p/PSW3R6YTcr/
[bionic] [17:18:19] Fixing file permissions in source directory
[bionic] [17:18:19] Destroying container
[xenial] [17:18:20] container-tests-provider-resource-generic: FAIL
[xenial] output: https://paste.ubuntu.com/p/G9gmgbnRmW/
[xenial] [17:18:23] Fixing file permissions in source directory
[xenial] [17:18:23] Destroying container

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/snapd_resource.py b/bin/snapd_resource.py
2index 5ce87c1..fa3ef46 100755
3--- a/bin/snapd_resource.py
4+++ b/bin/snapd_resource.py
5@@ -6,11 +6,13 @@
6 # Authors: Jonathan Cave <jonathan.cave@canonical.com>
7
8 import argparse
9-import io
10 import os
11 import string
12 import sys
13
14+from checkbox_support.snap_utils.asserts import decode
15+from checkbox_support.snap_utils.asserts import model_to_resource
16+from checkbox_support.snap_utils.asserts import serial_to_resource
17 from checkbox_support.snap_utils.snapd import Snapd
18 from checkbox_support.snap_utils.system import get_kernel_snap
19
20@@ -24,53 +26,25 @@ def slugify(_string):
21 return ''.join(c if c in valid_chars else '_' for c in _string)
22
23
24-def http_to_resource(assertion_stream):
25- """ Super naive Assertion parser
26-
27- No attempt to handle assertions with a body. Discards signatures based
28- on lack of colon characters. Update: need to be less naive about
29- gadget and kernel names on UC18
30- """
31- count = int(assertion_stream.headers['X-Ubuntu-Assertions-Count'])
32- if count > 0:
33- for line in io.StringIO(assertion_stream.text):
34- if line.strip() == "":
35- print()
36- if line.count(':') == 1:
37- key, val = [x.strip() for x in line.split(':')]
38- if key in ('gadget', 'kernel'):
39- if '=' in val:
40- snap, track = [x.strip() for x in val.split('=')]
41- print('{}: {}'.format(key, snap))
42- print('{}_track: {}'.format(key, track))
43- continue
44- print(line.strip())
45- return count
46-
47-
48 class ModelAssertion():
49
50 def invoked(self):
51- count = http_to_resource(Snapd().get_assertions('model'))
52- if count == 0:
53- # Print a dummy assertion - not nice but really trick to use
54- # plainbox resources without some defualt value
55- print('type: model')
56- print('authority-id: None')
57- print('model: None')
58+ models = decode(Snapd().get_assertions('model'))
59+ for m in models:
60+ r = model_to_resource(m)
61+ for key, val in r.items():
62+ print('{}: {}'.format(key, val))
63 print()
64
65
66 class SerialAssertion():
67
68 def invoked(self):
69- count = http_to_resource(Snapd().get_assertions('serial'))
70- if count == 0:
71- # Print a dummy assertion - not nice but really trick to use
72- # plainbox resources without some defualt value
73- print('type: serial')
74- print('authority-id: None')
75- print('serial: None')
76+ serials = decode(Snapd().get_assertions('serial'))
77+ for s in serials:
78+ r = serial_to_resource(s)
79+ for key, val in r.items():
80+ print('{}: {}'.format(key, val))
81 print()
82
83

Subscribers

People subscribed via source and target branches