Merge ~jslarraz/review-tools:remove-error-function-from-checks into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Merged
Merged at revision: 7de878d5c0d486189dea0f8a239d827da5844e53
Proposed branch: ~jslarraz/review-tools:remove-error-function-from-checks
Merge into: review-tools:master
Diff against target: 169 lines (+43/-63)
2 files modified
reviewtools/sr_common.py (+15/-19)
tests/test.sh.expected (+28/-44)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466925@code.launchpad.net

Commit message

Remove calls to common.error in favor of using exceptions. Those exceptions, if not handled earlier, will be catch by snap-review and added as runtime errors to the report. It allows us to generate the output in a more consistent format

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM - thanks @jslarraz

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reviewtools/sr_common.py b/reviewtools/sr_common.py
2index d4f74e7..f63b62d 100644
3--- a/reviewtools/sr_common.py
4+++ b/reviewtools/sr_common.py
5@@ -21,13 +21,12 @@ import re
6 from reviewtools.common import (
7 ReviewBase,
8 ReviewException,
9- error,
10 read_snapd_base_declaration,
11 unsquashfs_lln,
12 unsquashfs_lln_parse,
13 verify_type,
14 )
15-from reviewtools.containers.snap_container import SnapContainer, ContainerException
16+from reviewtools.containers.snap_container import SnapContainer
17 from reviewtools.overrides import interfaces_attribs_addons
18
19
20@@ -394,23 +393,20 @@ class SnapReview(ReviewBase):
21 return
22 ReviewBase.__init__(self, review_type, overrides=overrides)
23
24- try:
25- self.snap = SnapContainer(fn)
26- except ContainerException as e:
27- error(str(e))
28-
29- try:
30- self.snap_yaml = self.snap.get_file_as_yaml(
31- "meta/snap.yaml", yaml_version="1.1"
32+ # Initialize the container class
33+ self.snap = SnapContainer(fn)
34+
35+ # Get required files
36+ self.snap_yaml = self.snap.get_file_as_yaml(
37+ "meta/snap.yaml", yaml_version="1.1"
38+ )
39+ self.snap_manifest_yaml = {}
40+ if "snap/manifest.yaml" in self.snap.files:
41+ self.snap_manifest_yaml = self.snap.get_file_as_yaml(
42+ "snap/manifest.yaml", yaml_version="1.1"
43 )
44- self.snap_manifest_yaml = {}
45- if "snap/manifest.yaml" in self.snap.files:
46- self.snap_manifest_yaml = self.snap.get_file_as_yaml(
47- "snap/manifest.yaml", yaml_version="1.1"
48- )
49- except ContainerException as e:
50- error(str(e))
51
52+ # Read base declarations
53 (
54 self.base_declaration_series,
55 self.base_declaration,
56@@ -489,7 +485,7 @@ class SnapReview(ReviewBase):
57 for iface in self.snap_yaml[k]:
58 if not isinstance(self.snap_yaml[k], dict):
59 # eg, top-level "plugs: [ content ]"
60- error(
61+ raise Exception(
62 "Invalid top-level '%s' " "(not a dict)" % k
63 ) # pragma: nocover
64 if self.snap_yaml[k][iface] is None:
65@@ -502,7 +498,7 @@ class SnapReview(ReviewBase):
66 """Run unsquashfs -lln on a snap package"""
67 (rc, out) = unsquashfs_lln(snap_pkg)
68 if rc != 0:
69- error("Could not unsquashfs -lln failed")
70+ raise Exception("Could not unsquashfs -lln failed")
71 hdr, entries = unsquashfs_lln_parse(out)
72 return hdr, entries
73
74diff --git a/tests/test.sh.expected b/tests/test.sh.expected
75index 36b209b..047537c 100644
76--- a/tests/test.sh.expected
77+++ b/tests/test.sh.expected
78@@ -3229,31 +3229,23 @@ glance_ocata_amd64.snap: pass
79 }
80
81 = hello-world_1.0.6_all.snap =
82-{
83- "runtime-errors": {
84- "error": {
85- "msg": {
86- "manual_review": true,
87- "text": "Unsupported package format (not squashfs)"
88- }
89- },
90- "info": {},
91- "warn": {}
92- }
93-}
94+Errors
95+------
96+ - msg
97+ Unsupported package format (not squashfs)
98+hello-world_1.0.6_all.snap: RUNTIME ERROR
99
100 = --sdk hello-world_1.0.6_all.snap =
101+= runtime-errors =
102 {
103- "runtime-errors": {
104- "error": {
105- "msg": {
106- "manual_review": true,
107- "text": "Unsupported package format (not squashfs)"
108- }
109- },
110- "info": {},
111- "warn": {}
112- }
113+ "error": {
114+ "msg": {
115+ "manual_review": true,
116+ "text": "Unsupported package format (not squashfs)"
117+ }
118+ },
119+ "info": {},
120+ "warn": {}
121 }
122
123 = --json hello-world_1.0.6_all.snap =
124@@ -18017,31 +18009,23 @@ test-bad-desktop-file_1_all.snap: FAIL
125 }
126
127 = test-bad-plugs_0_all.snap =
128-{
129- "runtime-errors": {
130- "error": {
131- "msg": {
132- "manual_review": true,
133- "text": "Invalid top-level 'plugs' (not a dict)"
134- }
135- },
136- "info": {},
137- "warn": {}
138- }
139-}
140+Errors
141+------
142+ - msg
143+ Invalid top-level 'plugs' (not a dict)
144+test-bad-plugs_0_all.snap: RUNTIME ERROR
145
146 = --sdk test-bad-plugs_0_all.snap =
147+= runtime-errors =
148 {
149- "runtime-errors": {
150- "error": {
151- "msg": {
152- "manual_review": true,
153- "text": "Invalid top-level 'plugs' (not a dict)"
154- }
155- },
156- "info": {},
157- "warn": {}
158- }
159+ "error": {
160+ "msg": {
161+ "manual_review": true,
162+ "text": "Invalid top-level 'plugs' (not a dict)"
163+ }
164+ },
165+ "info": {},
166+ "warn": {}
167 }
168
169 = --json test-bad-plugs_0_all.snap =

Subscribers

People subscribed via source and target branches