Merge ~jocave/plainbox-provider-resource:handle-no-plugs-on-system into plainbox-provider-resource:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: eee6cdfc03d37e1b9067f2f7740cf364783c5f8c
Merged at revision: 784e5574b8e7de8fe475ac48137c3c50414410ee
Proposed branch: ~jocave/plainbox-provider-resource:handle-no-plugs-on-system
Merge into: plainbox-provider-resource:master
Diff against target: 80 lines (+32/-30)
1 file modified
bin/snapd_resource (+32/-30)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+355451@code.launchpad.net

Description of the change

Modify the snapd_resource script so that it properly handles situations where there could be no plugs or slots at all on the system. Previously, the script would throw a KeyError.

Tested on plano classic systems.

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

+1

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
2index 5da6cc0..c65249c 100755
3--- a/bin/snapd_resource
4+++ b/bin/snapd_resource
5@@ -162,35 +162,37 @@ class Endpoints(InterfacesQuery):
6 def invoked(self, ctx):
7 data = self.get(self.prefix).json()
8
9- for plug in data['result']['plugs']:
10- def print_field(key):
11- val = plug[key]
12- if val != '':
13- print('{}: {}'.format(key, val))
14- keys = ['snap', 'interface']
15- for f in keys:
16- print_field(f)
17- print('type: plug')
18- print('name: {}'.format(plug['plug']))
19- if 'attrs' in plug:
20- for attr, val in plug['attrs'].items():
21- print('attr_{}: {}'.format(slugify(attr), val))
22- print()
23-
24- for slot in data['result']['slots']:
25- def print_field(key):
26- val = slot[key]
27- if val != '':
28- print('{}: {}'.format(key, val))
29- keys = ['snap', 'interface']
30- for f in keys:
31- print_field(f)
32- print('type: slot')
33- print('name: {}'.format(slot['slot']))
34- if 'attrs' in slot:
35- for attr, val in slot['attrs'].items():
36- print('attr_{}: {}'.format(slugify(attr), val))
37- print()
38+ if 'plugs' in data['result']:
39+ for plug in data['result']['plugs']:
40+ def print_field(key):
41+ val = plug[key]
42+ if val != '':
43+ print('{}: {}'.format(key, val))
44+ keys = ['snap', 'interface']
45+ for f in keys:
46+ print_field(f)
47+ print('type: plug')
48+ print('name: {}'.format(plug['plug']))
49+ if 'attrs' in plug:
50+ for attr, val in plug['attrs'].items():
51+ print('attr_{}: {}'.format(slugify(attr), val))
52+ print()
53+
54+ if 'slots' in data['result']:
55+ for slot in data['result']['slots']:
56+ def print_field(key):
57+ val = slot[key]
58+ if val != '':
59+ print('{}: {}'.format(key, val))
60+ keys = ['snap', 'interface']
61+ for f in keys:
62+ print_field(f)
63+ print('type: slot')
64+ print('name: {}'.format(slot['slot']))
65+ if 'attrs' in slot:
66+ for attr, val in slot['attrs'].items():
67+ print('attr_{}: {}'.format(slugify(attr), val))
68+ print()
69
70
71 Connection = namedtuple(
72@@ -209,7 +211,7 @@ class Connections(InterfacesQuery):
73 def get_connections(self):
74 data = self.get('/v2/interfaces').json()['result']
75 connections = []
76- if data['plugs'] is not None:
77+ if 'plugs' in data:
78 for plug in data['plugs']:
79 if 'connections' in plug:
80 for con in plug['connections']:

Subscribers

People subscribed via source and target branches