Merge lp:~cprov/click-reviewers-tools/interface-abbreviated-syntax into lp:click-reviewers-tools

Proposed by Celso Providelo
Status: Merged
Merged at revision: 684
Proposed branch: lp:~cprov/click-reviewers-tools/interface-abbreviated-syntax
Merge into: lp:click-reviewers-tools
Diff against target: 122 lines (+48/-11)
3 files modified
clickreviews/sr_lint.py (+29/-11)
clickreviews/tests/test_sr_lint.py (+18/-0)
debian/changelog (+1/-0)
To merge this branch: bzr merge lp:~cprov/click-reviewers-tools/interface-abbreviated-syntax
Reviewer Review Type Date Requested Status
Jamie Strandboge (community) Approve
Review via email: mp+298180@code.launchpad.net

Description of the change

Support for interface abbreviated syntax, e.g.:

{{{
name: 'network-manager',
...
apps:
    networkmanager:
        slots:
            - service
    nmcli:
        plugs:
            - nmcli'

plugs
    nmcli: network-manager

slots:
    service: network-manager
}}}

To post a comment you must log in.
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

This looks great. Thanks!

review: Approve
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Actually, one small pep8 whitespace issue. I'll fix and commit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clickreviews/sr_lint.py'
2--- clickreviews/sr_lint.py 2016-06-14 06:54:07 +0000
3+++ clickreviews/sr_lint.py 2016-06-22 23:47:51 +0000
4@@ -893,24 +893,37 @@
5 # 'interface' is optional since the interface name and the iface
6 # name are the same
7 interface = iface
8- if 'interface' in self.snap_yaml[iface_type][iface]:
9- interface = self.snap_yaml[iface_type][iface]['interface']
10-
11+
12+ spec = self.snap_yaml[iface_type][iface]
13+ if isinstance(spec, str):
14+ # Abbreviated syntax (no attributes)
15+ # <plugs|slots>:
16+ # <alias>: <interface>
17+ interface = spec
18+ elif 'interface' in spec:
19+ # Full specification.
20+ # <plugs|slots>:
21+ # <alias>:
22+ # interface: <interface>
23+ interface = spec['interface']
24+
25+ # Validate indirect (specified via alias) interfaces:
26+ if interface != iface:
27 key = 'interface'
28 t = 'info'
29- n = self._get_check_name(iface_type, app=key, extra=iface)
30+ n = self._get_check_name(iface_type, app=key, extra=interface)
31 s = 'OK'
32- if not isinstance(self.snap_yaml[iface_type][iface][key], str):
33+ if not isinstance(interface, str):
34 t = 'error'
35- s = "invalid %s: %s (not a str)" % \
36- (key, self.snap_yaml[iface_type][iface][key])
37- elif len(self.snap_yaml[iface_type][iface][key]) == 0:
38+ s = "invalid %s: %s (not a str)" % (key, interface)
39+ elif len(interface) == 0:
40 t = 'error'
41 s = "'%s' is empty" % key
42 self._add_result(t, n, s)
43 if t == 'error':
44 continue
45
46+ # Check interfaces whitelist.
47 t = 'info'
48 n = self._get_check_name(iface_type, app=interface, extra=iface)
49 s = 'OK'
50@@ -921,7 +934,12 @@
51 if t == 'error':
52 continue
53
54- for attrib in self.snap_yaml[iface_type][iface]:
55+ # Abbreviated interfaces don't have attributes, done checking.
56+ if isinstance(spec, str):
57+ continue
58+
59+ # Check interface attributes.
60+ for attrib in spec:
61 if attrib == 'interface':
62 continue
63 t = 'info'
64@@ -932,8 +950,8 @@
65 t = 'error'
66 s = "unknown attribute '%s' for interface '%s'" % (
67 attrib, interface)
68- elif not isinstance(self.snap_yaml[iface_type][iface][attrib],
69- type(self.interfaces[interface][attrib])):
70+ elif not isinstance(
71+ spec[attrib], type(self.interfaces[interface][attrib])):
72 t = 'error'
73 s = "'%s' is not '%s'" % \
74 (attrib,
75
76=== modified file 'clickreviews/tests/test_sr_lint.py'
77--- clickreviews/tests/test_sr_lint.py 2016-06-14 06:54:07 +0000
78+++ clickreviews/tests/test_sr_lint.py 2016-06-22 23:47:51 +0000
79@@ -2073,6 +2073,15 @@
80 expected_counts = {'info': None, 'warn': 0, 'error': 1}
81 self.check_results(r, expected_counts)
82
83+ def test_check_plugs_abbreviated(self):
84+ '''Test check_plugs() - abbreviated'''
85+ self.set_test_snap_yaml("plugs", {'nm': 'network-manager'})
86+ c = SnapReviewLint(self.test_name)
87+ c.check_plugs()
88+ r = c.click_report
89+ expected_counts = {'info': 2, 'warn': 0, 'error': 0}
90+ self.check_results(r, expected_counts)
91+
92 def test_check_apps_plugs(self):
93 '''Test check_apps_plugs()'''
94 plugs = self._create_top_plugs()
95@@ -2238,6 +2247,15 @@
96 expected_counts = {'info': None, 'warn': 0, 'error': 1}
97 self.check_results(r, expected_counts)
98
99+ def test_check_slots_abbreviated(self):
100+ '''Test check_slots() - abbreviated'''
101+ self.set_test_snap_yaml("slots", {'nm': 'network-manager'})
102+ c = SnapReviewLint(self.test_name)
103+ c.check_slots()
104+ r = c.click_report
105+ expected_counts = {'info': 2, 'warn': 0, 'error': 0}
106+ self.check_results(r, expected_counts)
107+
108 def test_check_apps_slots(self):
109 '''Test check_apps_slots()'''
110 slots = self._create_top_slots()
111
112=== modified file 'debian/changelog'
113--- debian/changelog 2016-06-22 20:41:28 +0000
114+++ debian/changelog 2016-06-22 23:47:51 +0000
115@@ -19,6 +19,7 @@
116 * sr_lint.py:
117 - support 'environment' key in yaml (LP: #1583259)
118 - support 'confinement' key in yaml
119+ - support for interface abbreviated syntax (LP: #1595184)
120 * sr_security.py: specifying mpris slot should not warn
121
122 -- Jamie Strandboge <jamie@ubuntu.com> Tue, 14 Jun 2016 09:48:15 +0300

Subscribers

People subscribed via source and target branches