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
diff --git a/bin/snapd_resource b/bin/snapd_resource.py
0similarity index 72%0similarity index 72%
1rename from bin/snapd_resource1rename from bin/snapd_resource
2rename to bin/snapd_resource.py2rename to bin/snapd_resource.py
index 7f15906..5ce87c1 100755
--- a/bin/snapd_resource
+++ b/bin/snapd_resource.py
@@ -5,11 +5,12 @@
5# Written by:5# Written by:
6# Authors: Jonathan Cave <jonathan.cave@canonical.com>6# Authors: Jonathan Cave <jonathan.cave@canonical.com>
77
8import argparse
8import io9import io
9import os10import os
10import string11import string
12import sys
1113
12from guacamole import Command
13from checkbox_support.snap_utils.snapd import Snapd14from checkbox_support.snap_utils.snapd import Snapd
14from checkbox_support.snap_utils.system import get_kernel_snap15from checkbox_support.snap_utils.system import get_kernel_snap
1516
@@ -47,9 +48,9 @@ def http_to_resource(assertion_stream):
47 return count48 return count
4849
4950
50class ModelAssertion(Command):51class ModelAssertion():
5152
52 def invoked(self, ctx):53 def invoked(self):
53 count = http_to_resource(Snapd().get_assertions('model'))54 count = http_to_resource(Snapd().get_assertions('model'))
54 if count == 0:55 if count == 0:
55 # Print a dummy assertion - not nice but really trick to use56 # Print a dummy assertion - not nice but really trick to use
@@ -60,9 +61,9 @@ class ModelAssertion(Command):
60 print()61 print()
6162
6263
63class SerialAssertion(Command):64class SerialAssertion():
6465
65 def invoked(self, ctx):66 def invoked(self):
66 count = http_to_resource(Snapd().get_assertions('serial'))67 count = http_to_resource(Snapd().get_assertions('serial'))
67 if count == 0:68 if count == 0:
68 # Print a dummy assertion - not nice but really trick to use69 # Print a dummy assertion - not nice but really trick to use
@@ -73,17 +74,23 @@ class SerialAssertion(Command):
73 print()74 print()
7475
7576
76class Assertions(Command):77class Assertions():
7778
78 sub_commands = (79 def invoked(self):
79 ('model', ModelAssertion),80 actions = {
80 ('serial', SerialAssertion),81 'model': ModelAssertion,
81 )82 'serial': SerialAssertion,
83 }
84 parser = argparse.ArgumentParser()
85 parser.add_argument('action', type=str, help="The action to test",
86 choices=actions)
87 args = parser.parse_args(sys.argv[2:3])
88 actions[args.action]().invoked()
8289
8390
84class Snaps(Command):91class Snaps():
8592
86 def invoked(self, ctx):93 def invoked(self):
87 data = Snapd().list()94 data = Snapd().list()
88 for snap in data:95 for snap in data:
89 def print_field(key):96 def print_field(key):
@@ -102,9 +109,9 @@ class Snaps(Command):
102 print()109 print()
103110
104111
105class Endpoints(Command):112class Endpoints():
106113
107 def invoked(self, ctx):114 def invoked(self):
108 data = Snapd().interfaces()115 data = Snapd().interfaces()
109116
110 if 'plugs' in data:117 if 'plugs' in data:
@@ -158,26 +165,32 @@ def get_connections():
158 return connections165 return connections
159166
160167
161class Connections(Command):168class Connections():
162169
163 def invoked(self, ctx):170 def invoked(self):
164 for conn in get_connections():171 for conn in get_connections():
165 print('slot: {}:{}'.format(conn.target_snap, conn.target_slot))172 print('slot: {}:{}'.format(conn.target_snap, conn.target_slot))
166 print('plug: {}:{}'.format(conn.plug_snap, conn.plug_plug))173 print('plug: {}:{}'.format(conn.plug_snap, conn.plug_plug))
167 print()174 print()
168175
169176
170class Interfaces(Command):177class Interfaces():
171178
172 sub_commands = (179 def invoked(self):
173 ('endpoints', Endpoints),180 actions = {
174 ('connections', Connections),181 'endpoints': Endpoints,
175 )182 'connections': Connections
183 }
184 parser = argparse.ArgumentParser()
185 parser.add_argument('action', type=str, help="The action to test",
186 choices=actions)
187 args = parser.parse_args(sys.argv[2:3])
188 actions[args.action]().invoked()
176189
177190
178class Features(Command):191class Features():
179192
180 def invoked(self, ctx):193 def invoked(self):
181 self._detect_kernel_extraction()194 self._detect_kernel_extraction()
182 print()195 print()
183196
@@ -193,17 +206,24 @@ class Features(Command):
193 if snap is not None:206 if snap is not None:
194 feature_f = '/snap/{}/current/meta/force-kernel-extraction'.format(207 feature_f = '/snap/{}/current/meta/force-kernel-extraction'.format(
195 snap)208 snap)
196 print('force_kernel_extraction: {}'.format(os.path.exists(feature_f)))209 print('force_kernel_extraction: {}'.format(
197210 os.path.exists(feature_f)))
198211
199class SnapdResource(Command):212
200213class SnapdResource():
201 sub_commands = (214
202 ('assertions', Assertions),215 def main(self):
203 ('snaps', Snaps),216 actions = {
204 ('interfaces', Interfaces),217 'assertions': Assertions,
205 ('features', Features)218 'snaps': Snaps,
206 )219 'interfaces': Interfaces,
220 'features': Features
221 }
222 parser = argparse.ArgumentParser()
223 parser.add_argument('action', type=str, help="The action to test",
224 choices=actions)
225 args = parser.parse_args(sys.argv[1:2])
226 actions[args.action]().invoked()
207227
208228
209if __name__ == '__main__':229if __name__ == '__main__':
diff --git a/jobs/resource.pxu b/jobs/resource.pxu
index 5d59466..ffac737 100644
--- a/jobs/resource.pxu
+++ b/jobs/resource.pxu
@@ -53,7 +53,7 @@ unit: packaging meta-data
53os-id: debian53os-id: debian
54Depends: usbutils54Depends: usbutils
5555
56# This is for snapd_resource56# This is for snapd_resource.py
57unit: packaging meta-data57unit: packaging meta-data
58os-id: debian58os-id: debian
59Depends: python3-requests-unixsocket59Depends: python3-requests-unixsocket
@@ -374,7 +374,7 @@ estimated_duration: 1.1
374plugin: resource374plugin: resource
375command:375command:
376 unset PYTHONUSERBASE376 unset PYTHONUSERBASE
377 snapd_resource snaps377 snapd_resource.py snaps
378_description: Generates a list of snap packages378_description: Generates a list of snap packages
379_summary: Collect information about installed snap packages379_summary: Collect information about installed snap packages
380380
@@ -383,7 +383,7 @@ estimated_duration: 1.1
383plugin: resource383plugin: resource
384command:384command:
385 unset PYTHONUSERBASE385 unset PYTHONUSERBASE
386 snapd_resource interfaces endpoints386 snapd_resource.py interfaces endpoints
387_description: Generates a list of interface declarations on the device387_description: Generates a list of interface declarations on the device
388_summary: Collect information about interfaces388_summary: Collect information about interfaces
389389
@@ -392,7 +392,7 @@ estimated_duration: 1.1
392plugin: resource392plugin: resource
393command:393command:
394 unset PYTHONUSERBASE394 unset PYTHONUSERBASE
395 snapd_resource interfaces connections395 snapd_resource.py interfaces connections
396_description: Generates a list of plug and slot connections on the device396_description: Generates a list of plug and slot connections on the device
397_summary: Collect information about connections397_summary: Collect information about connections
398398
@@ -403,7 +403,7 @@ _description:
403plugin: resource403plugin: resource
404estimated_duration: 2.0404estimated_duration: 2.0
405command:405command:
406 snapd_resource assertions model406 snapd_resource.py assertions model
407407
408id: serial_assertion408id: serial_assertion
409_summary: Collect serial assertions on the device409_summary: Collect serial assertions on the device
@@ -412,7 +412,7 @@ _description:
412plugin: resource412plugin: resource
413estimated_duration: 2.0413estimated_duration: 2.0
414command:414command:
415 snapd_resource assertions serial415 snapd_resource.py assertions serial
416416
417id: serial_ports_static417id: serial_ports_static
418_summary: Generates a serial port resource based on user supplied configuration418_summary: Generates a serial port resource based on user supplied configuration
@@ -437,7 +437,7 @@ _description:
437plugin: resource437plugin: resource
438estimated_duration: 1.0438estimated_duration: 1.0
439command:439command:
440 snapd_resource features440 snapd_resource.py features
441441
442id: net_if_management442id: net_if_management
443_summary: Identify what service is managing each physical network interface443_summary: Identify what service is managing each physical network interface

Subscribers

People subscribed via source and target branches