Merge ~sylvain-pineau/plainbox-provider-resource:snapd_resources into plainbox-provider-resource:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 2bfd08f5ba444ceea654cf999a4aa6f45cfd9ede
Merged at revision: 136a0de01735babd46fb830b43e85c53a914c2e1
Proposed branch: ~sylvain-pineau/plainbox-provider-resource:snapd_resources
Merge into: plainbox-provider-resource:master
Diff against target: 247 lines (+226/-0)
2 files modified
bin/snapd_resource (+176/-0)
jobs/resource.pxu (+50/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Maciej Kisielewski Needs Information
Review via email: mp+322186@code.launchpad.net

Description of the change

Addition of the snapd resources jobs for desktop test plans and submissions.

The dependency on python3-requests-unixsocket [1] is ensured thanks to a dummy package for Trusty in the dev/stable ppas.

[1] http://packages.ubuntu.com/xenial/python3-requests-unixsocket

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> The dependency on python3-requests-unixsocket [1] is ensured thanks to a dummy package for Trusty in the dev/stable ppas.

I spooled up a fresh VM and installed everything from the dev ppa.
python3-requests-unixsocket didn't get installed.

After I installed it manually all jobs worked perfectly.

How this dependency is ensured? What am I doing wrong?

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

weird, I expected the packaging meta-data unit to do the right job for packaging.

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

I built the deb package for this provider locally and I can confirm the new dep is well written in the control file:

Package: plainbox-provider-resource-generic
Version: 0.31.0-1
Architecture: amd64
Maintainer: Checkbox Developers <email address hidden>
Installed-Size: 131
Depends: python3 (>= 3.2), python3-checkbox-support (>= 0.22), dmidecode, dpkg (>= 1.13), lsb-release, network-manager, udev, usbutils, python3-requests-unixsocket, libc6 (>= 2.4), libnl-3-200 (>= 3.2.7), libnl-genl-3-200 (>= 3.2.7)
Suggests: x11-server-utils, gconf2, xinput
Section: utils
Priority: optional
Homepage: http://launchpad.net/plainbox-provider-resource
Description: CheckBox generic resource jobs provider
 This package provides the generic resource jobs. It is used together
 alongside with PlainBox.
 .
 Jobs are smallest units of testing that can be performed by PlainBox.
 All jobs have an unique name. There are many types of jobs, some are fully
 automated others are fully manual.
 .
 Resources are collections of key-value data sets that are generated by
 special resource jobs. They are extensively used to indicate hardware or
 software dependencies. For example a bluetooth test may indicate it
 requires bluetooth hardware and appropriate software packages installed.

Once new builds will be available in the dev ppa, you'll see python3-requests-unixsocket installed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/snapd_resource b/bin/snapd_resource
0new file mode 1007550new file mode 100755
index 0000000..da0cac9
--- /dev/null
+++ b/bin/snapd_resource
@@ -0,0 +1,176 @@
1#!/usr/bin/env python3
2# Copyright 2017 Canonical Ltd.
3# All rights reserved.
4#
5# Written by:
6# Authors: Jonathan Cave <jonathan.cave@canonical.com>
7
8import io
9import logging
10import sys
11
12from guacamole import Command
13import requests
14import requests_unixsocket
15
16
17SNAPD_BASE_URL = 'http+unix://%2Frun%2Fsnapd.socket'
18
19
20class SnapdQuery(Command):
21
22 def __init__(self):
23 self._session = requests_unixsocket.Session()
24
25 def get(self, path):
26 r = self._session.get(SNAPD_BASE_URL + path)
27 if r.status_code != requests.codes.ok:
28 logging.error("Got error {} attempting to access {}".format(
29 r.status_code, path))
30 sys.exit(1)
31 return r
32
33
34class AssertionQuery(SnapdQuery):
35
36 prefix = '/v2/assertions/'
37
38 def convert(self, assertion):
39 """ Super naive Assertion parser
40
41 No attempt to handle assertions with a body. Discards signatures based
42 on lack of colon characters.
43 """
44 data = self.get(self.prefix + assertion)
45 count = int(data.headers['X-Ubuntu-Assertions-Count'])
46 if count > 0:
47 for line in io.StringIO(data.text):
48 if line.strip() == "":
49 print()
50 if ':' in line:
51 print(line.strip())
52 return count
53
54
55class ModelAssertion(AssertionQuery):
56
57 def invoked(self, ctx):
58 count = self.convert('model')
59 if count == 0:
60 # Print a dummy assertion - not nice but really trick to use
61 # plainbox resources without some defualt value
62 print('type: model')
63 print('authority-id: None')
64 print('model: None')
65 print()
66
67
68class SerialAssertion(AssertionQuery):
69
70 def invoked(self, ctx):
71 count = self.convert('serial')
72 if count == 0:
73 # Print a dummy assertion - not nice but really trick to use
74 # plainbox resources without some defualt value
75 print('type: serial')
76 print('authority-id: None')
77 print('serial: None')
78 print()
79
80
81class Assertions(Command):
82
83 sub_commands = (
84 ('model', ModelAssertion),
85 ('serial', SerialAssertion),
86 )
87
88
89class Snaps(SnapdQuery):
90
91 prefix = '/v2/snaps'
92
93 def invoked(self, ctx):
94 data = self.get(self.prefix).json()
95
96 for snap in data['result']:
97 def print_field(key):
98 val = snap[key]
99 if val != "":
100 print("{}: {}".format(key, val))
101 # Whitelist of information that is of interest
102 keys = ['name', 'type', 'channel', 'version', 'revision',
103 'developer', 'install-date', 'confinement', 'devmode']
104 for f in keys:
105 print_field(f)
106 print()
107
108
109class InterfacesQuery(SnapdQuery):
110
111 prefix = '/v2/interfaces'
112
113
114class Endpoints(InterfacesQuery):
115
116 def invoked(self, ctx):
117 data = self.get(self.prefix).json()
118
119 for plug in data['result']['plugs']:
120 def print_field(key):
121 val = plug[key]
122 if val != '':
123 print('{}: {}'.format(key, val))
124 keys = ['snap', 'interface']
125 for f in keys:
126 print_field(f)
127 print('type: plug')
128 print('name: {}'.format(plug['plug']))
129 print()
130
131 for slot in data['result']['slots']:
132 def print_field(key):
133 val = slot[key]
134 if val != '':
135 print('{}: {}'.format(key, val))
136 keys = ['snap', 'interface']
137 for f in keys:
138 print_field(f)
139 print('type: slot')
140 print('name: {}'.format(slot['slot']))
141 print()
142
143
144class Connections(InterfacesQuery):
145
146 def invoked(self, ctx):
147 data = self.get(self.prefix).json()
148
149 if data['result']['plugs'] is not None:
150 for plug in data['result']['plugs']:
151 if 'connections' in plug:
152 for con in plug['connections']:
153 print('slot: {}:{}'.format(con['snap'], con['slot']))
154 print('plug: {}:{}'.format(plug['snap'], plug['plug']))
155 print()
156
157
158class Interfaces(Command):
159
160 sub_commands = (
161 ('endpoints', Endpoints),
162 ('connections', Connections),
163 )
164
165
166class SnapdResource(Command):
167
168 sub_commands = (
169 ('assertions', Assertions),
170 ('snaps', Snaps),
171 ('interfaces', Interfaces),
172 )
173
174
175if __name__ == '__main__':
176 SnapdResource().main()
diff --git a/jobs/resource.pxu b/jobs/resource.pxu
index befc0dd..a7207d7 100644
--- a/jobs/resource.pxu
+++ b/jobs/resource.pxu
@@ -61,6 +61,11 @@ unit: packaging meta-data
61os-id: debian61os-id: debian
62Depends: usbutils62Depends: usbutils
6363
64# This is for snapd_resource
65unit: packaging meta-data
66os-id: debian
67Depends: python3-requests-unixsocket
68
64id: cpuinfo69id: cpuinfo
65estimated_duration: 0.3770estimated_duration: 0.37
66plugin: resource71plugin: resource
@@ -332,3 +337,48 @@ _description: Generate an entry for each MIR integration tests
332command:337command:
333 for test in `mir_integration_tests --gtest_list_tests | sed -n '/\.$/s/\.$//p'`; do echo "category: integration"; echo "name: $test"; echo ""; done338 for test in `mir_integration_tests --gtest_list_tests | sed -n '/\.$/s/\.$//p'`; do echo "category: integration"; echo "name: $test"; echo ""; done
334 for test in `mir_acceptance_tests --gtest_list_tests | sed -n '/\.$/s/\.$//p'`; do echo "category: acceptance"; echo "name: $test"; echo ""; done339 for test in `mir_acceptance_tests --gtest_list_tests | sed -n '/\.$/s/\.$//p'`; do echo "category: acceptance"; echo "name: $test"; echo ""; done
340
341id: snap
342estimated_duration: 1.1
343plugin: resource
344command:
345 unset PYTHONUSERBASE
346 snapd_resource snaps
347_description: Generates a list of snap packages
348_summary: Collect information about installed snap packages
349
350id: interface
351estimated_duration: 1.1
352plugin: resource
353command:
354 unset PYTHONUSERBASE
355 snapd_resource interfaces endpoints
356_description: Generates a list of interface declarations on the device
357_summary: Collect information about interfaces
358
359id: connections
360estimated_duration: 1.1
361plugin: resource
362command:
363 unset PYTHONUSERBASE
364 snapd_resource interfaces connections
365_description: Generates a list of plug and slot connections on the device
366_summary: Collect information about connections
367
368id: model_assertion
369_summary: Collect model assertions on the device
370_description:
371 Queries the snapd REST API for model assertions present on the device.
372plugin: resource
373estimated_duration: 2.0
374command:
375 snapd_resource assertions model
376
377id: serial_assertion
378_summary: Collect serial assertions on the device
379_description:
380 Queries the snapd REST API for serial assertions present on the device.
381plugin: resource
382estimated_duration: 2.0
383command:
384 snapd_resource assertions serial

Subscribers

People subscribed via source and target branches