Merge ~jocave/plainbox-provider-resource:remove-guacamole into plainbox-provider-resource:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 80a3abaada2d189bbdc8d84741fdbe1ac89f23ae
Merged at revision: a63c5747333eb4d2afe4b7fdd51137a6193193f4
Proposed branch: ~jocave/plainbox-provider-resource:remove-guacamole
Merge into: plainbox-provider-resource:master
Diff against target: 233 lines (+61/-41)
2 files modified
bin/snapd_resource.py (+54/-34)
jobs/resource.pxu (+7/-7)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+378005@code.launchpad.net

Description of the change

Switch from guacamole to argparse in the snapd_resource script. This is the only place where this modules is used in this provider.

Tested the resource jobs still work on a bionic server install.

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

+1 (and thx for the .py extension)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/snapd_resource b/bin/snapd_resource.py
2similarity index 72%
3rename from bin/snapd_resource
4rename to bin/snapd_resource.py
5index 7f15906..5ce87c1 100755
6--- a/bin/snapd_resource
7+++ b/bin/snapd_resource.py
8@@ -5,11 +5,12 @@
9 # Written by:
10 # Authors: Jonathan Cave <jonathan.cave@canonical.com>
11
12+import argparse
13 import io
14 import os
15 import string
16+import sys
17
18-from guacamole import Command
19 from checkbox_support.snap_utils.snapd import Snapd
20 from checkbox_support.snap_utils.system import get_kernel_snap
21
22@@ -47,9 +48,9 @@ def http_to_resource(assertion_stream):
23 return count
24
25
26-class ModelAssertion(Command):
27+class ModelAssertion():
28
29- def invoked(self, ctx):
30+ def invoked(self):
31 count = http_to_resource(Snapd().get_assertions('model'))
32 if count == 0:
33 # Print a dummy assertion - not nice but really trick to use
34@@ -60,9 +61,9 @@ class ModelAssertion(Command):
35 print()
36
37
38-class SerialAssertion(Command):
39+class SerialAssertion():
40
41- def invoked(self, ctx):
42+ def invoked(self):
43 count = http_to_resource(Snapd().get_assertions('serial'))
44 if count == 0:
45 # Print a dummy assertion - not nice but really trick to use
46@@ -73,17 +74,23 @@ class SerialAssertion(Command):
47 print()
48
49
50-class Assertions(Command):
51+class Assertions():
52
53- sub_commands = (
54- ('model', ModelAssertion),
55- ('serial', SerialAssertion),
56- )
57+ def invoked(self):
58+ actions = {
59+ 'model': ModelAssertion,
60+ 'serial': SerialAssertion,
61+ }
62+ parser = argparse.ArgumentParser()
63+ parser.add_argument('action', type=str, help="The action to test",
64+ choices=actions)
65+ args = parser.parse_args(sys.argv[2:3])
66+ actions[args.action]().invoked()
67
68
69-class Snaps(Command):
70+class Snaps():
71
72- def invoked(self, ctx):
73+ def invoked(self):
74 data = Snapd().list()
75 for snap in data:
76 def print_field(key):
77@@ -102,9 +109,9 @@ class Snaps(Command):
78 print()
79
80
81-class Endpoints(Command):
82+class Endpoints():
83
84- def invoked(self, ctx):
85+ def invoked(self):
86 data = Snapd().interfaces()
87
88 if 'plugs' in data:
89@@ -158,26 +165,32 @@ def get_connections():
90 return connections
91
92
93-class Connections(Command):
94+class Connections():
95
96- def invoked(self, ctx):
97+ def invoked(self):
98 for conn in get_connections():
99 print('slot: {}:{}'.format(conn.target_snap, conn.target_slot))
100 print('plug: {}:{}'.format(conn.plug_snap, conn.plug_plug))
101 print()
102
103
104-class Interfaces(Command):
105+class Interfaces():
106
107- sub_commands = (
108- ('endpoints', Endpoints),
109- ('connections', Connections),
110- )
111+ def invoked(self):
112+ actions = {
113+ 'endpoints': Endpoints,
114+ 'connections': Connections
115+ }
116+ parser = argparse.ArgumentParser()
117+ parser.add_argument('action', type=str, help="The action to test",
118+ choices=actions)
119+ args = parser.parse_args(sys.argv[2:3])
120+ actions[args.action]().invoked()
121
122
123-class Features(Command):
124+class Features():
125
126- def invoked(self, ctx):
127+ def invoked(self):
128 self._detect_kernel_extraction()
129 print()
130
131@@ -193,17 +206,24 @@ class Features(Command):
132 if snap is not None:
133 feature_f = '/snap/{}/current/meta/force-kernel-extraction'.format(
134 snap)
135- print('force_kernel_extraction: {}'.format(os.path.exists(feature_f)))
136-
137-
138-class SnapdResource(Command):
139-
140- sub_commands = (
141- ('assertions', Assertions),
142- ('snaps', Snaps),
143- ('interfaces', Interfaces),
144- ('features', Features)
145- )
146+ print('force_kernel_extraction: {}'.format(
147+ os.path.exists(feature_f)))
148+
149+
150+class SnapdResource():
151+
152+ def main(self):
153+ actions = {
154+ 'assertions': Assertions,
155+ 'snaps': Snaps,
156+ 'interfaces': Interfaces,
157+ 'features': Features
158+ }
159+ parser = argparse.ArgumentParser()
160+ parser.add_argument('action', type=str, help="The action to test",
161+ choices=actions)
162+ args = parser.parse_args(sys.argv[1:2])
163+ actions[args.action]().invoked()
164
165
166 if __name__ == '__main__':
167diff --git a/jobs/resource.pxu b/jobs/resource.pxu
168index 5d59466..ffac737 100644
169--- a/jobs/resource.pxu
170+++ b/jobs/resource.pxu
171@@ -53,7 +53,7 @@ unit: packaging meta-data
172 os-id: debian
173 Depends: usbutils
174
175-# This is for snapd_resource
176+# This is for snapd_resource.py
177 unit: packaging meta-data
178 os-id: debian
179 Depends: python3-requests-unixsocket
180@@ -374,7 +374,7 @@ estimated_duration: 1.1
181 plugin: resource
182 command:
183 unset PYTHONUSERBASE
184- snapd_resource snaps
185+ snapd_resource.py snaps
186 _description: Generates a list of snap packages
187 _summary: Collect information about installed snap packages
188
189@@ -383,7 +383,7 @@ estimated_duration: 1.1
190 plugin: resource
191 command:
192 unset PYTHONUSERBASE
193- snapd_resource interfaces endpoints
194+ snapd_resource.py interfaces endpoints
195 _description: Generates a list of interface declarations on the device
196 _summary: Collect information about interfaces
197
198@@ -392,7 +392,7 @@ estimated_duration: 1.1
199 plugin: resource
200 command:
201 unset PYTHONUSERBASE
202- snapd_resource interfaces connections
203+ snapd_resource.py interfaces connections
204 _description: Generates a list of plug and slot connections on the device
205 _summary: Collect information about connections
206
207@@ -403,7 +403,7 @@ _description:
208 plugin: resource
209 estimated_duration: 2.0
210 command:
211- snapd_resource assertions model
212+ snapd_resource.py assertions model
213
214 id: serial_assertion
215 _summary: Collect serial assertions on the device
216@@ -412,7 +412,7 @@ _description:
217 plugin: resource
218 estimated_duration: 2.0
219 command:
220- snapd_resource assertions serial
221+ snapd_resource.py assertions serial
222
223 id: serial_ports_static
224 _summary: Generates a serial port resource based on user supplied configuration
225@@ -437,7 +437,7 @@ _description:
226 plugin: resource
227 estimated_duration: 1.0
228 command:
229- snapd_resource features
230+ snapd_resource.py features
231
232 id: net_if_management
233 _summary: Identify what service is managing each physical network interface

Subscribers

People subscribed via source and target branches