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
diff --git a/bin/snapd_resource.py b/bin/snapd_resource.py
index 5ce87c1..fa3ef46 100755
--- a/bin/snapd_resource.py
+++ b/bin/snapd_resource.py
@@ -6,11 +6,13 @@
6# Authors: Jonathan Cave <jonathan.cave@canonical.com>6# Authors: Jonathan Cave <jonathan.cave@canonical.com>
77
8import argparse8import argparse
9import io
10import os9import os
11import string10import string
12import sys11import sys
1312
13from checkbox_support.snap_utils.asserts import decode
14from checkbox_support.snap_utils.asserts import model_to_resource
15from checkbox_support.snap_utils.asserts import serial_to_resource
14from checkbox_support.snap_utils.snapd import Snapd16from checkbox_support.snap_utils.snapd import Snapd
15from checkbox_support.snap_utils.system import get_kernel_snap17from checkbox_support.snap_utils.system import get_kernel_snap
1618
@@ -24,53 +26,25 @@ def slugify(_string):
24 return ''.join(c if c in valid_chars else '_' for c in _string)26 return ''.join(c if c in valid_chars else '_' for c in _string)
2527
2628
27def http_to_resource(assertion_stream):
28 """ Super naive Assertion parser
29
30 No attempt to handle assertions with a body. Discards signatures based
31 on lack of colon characters. Update: need to be less naive about
32 gadget and kernel names on UC18
33 """
34 count = int(assertion_stream.headers['X-Ubuntu-Assertions-Count'])
35 if count > 0:
36 for line in io.StringIO(assertion_stream.text):
37 if line.strip() == "":
38 print()
39 if line.count(':') == 1:
40 key, val = [x.strip() for x in line.split(':')]
41 if key in ('gadget', 'kernel'):
42 if '=' in val:
43 snap, track = [x.strip() for x in val.split('=')]
44 print('{}: {}'.format(key, snap))
45 print('{}_track: {}'.format(key, track))
46 continue
47 print(line.strip())
48 return count
49
50
51class ModelAssertion():29class ModelAssertion():
5230
53 def invoked(self):31 def invoked(self):
54 count = http_to_resource(Snapd().get_assertions('model'))32 models = decode(Snapd().get_assertions('model'))
55 if count == 0:33 for m in models:
56 # Print a dummy assertion - not nice but really trick to use34 r = model_to_resource(m)
57 # plainbox resources without some defualt value35 for key, val in r.items():
58 print('type: model')36 print('{}: {}'.format(key, val))
59 print('authority-id: None')
60 print('model: None')
61 print()37 print()
6238
6339
64class SerialAssertion():40class SerialAssertion():
6541
66 def invoked(self):42 def invoked(self):
67 count = http_to_resource(Snapd().get_assertions('serial'))43 serials = decode(Snapd().get_assertions('serial'))
68 if count == 0:44 for s in serials:
69 # Print a dummy assertion - not nice but really trick to use45 r = serial_to_resource(s)
70 # plainbox resources without some defualt value46 for key, val in r.items():
71 print('type: serial')47 print('{}: {}'.format(key, val))
72 print('authority-id: None')
73 print('serial: None')
74 print()48 print()
7549
7650

Subscribers

People subscribed via source and target branches