Merge lp:~mvo/click-reviewers-tools/minimal-snap-yaml into lp:click-reviewers-tools

Proposed by Michael Vogt
Status: Merged
Merged at revision: 567
Proposed branch: lp:~mvo/click-reviewers-tools/minimal-snap-yaml
Merge into: lp:click-reviewers-tools
Diff against target: 201 lines (+89/-7)
4 files modified
clickreviews/cr_common.py (+27/-7)
clickreviews/cr_lint.py (+9/-0)
clickreviews/cr_tests.py (+29/-0)
clickreviews/tests/test_cr_lint.py (+24/-0)
To merge this branch: bzr merge lp:~mvo/click-reviewers-tools/minimal-snap-yaml
Reviewer Review Type Date Requested Status
Jamie Strandboge (community) Approve
Martin Albisetti (community) Approve
Review via email: mp+284562@code.launchpad.net

Description of the change

This branch adds minimal support for meta/snap.yaml by converting the snap.yaml to pkg.yaml internally. This is a stop-gap to unblock the store so that we can push unit tests to the store again with snap.yaml.

To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) wrote :

PEP8 has a small complaint:

./clickreviews/cr_common.py:186:49: W291 trailing whitespace

Other than that, +1

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

Yes, 'make check' also had another whitespace complaint. I fixed those.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clickreviews/cr_common.py'
2--- clickreviews/cr_common.py 2016-01-20 14:02:52 +0000
3+++ clickreviews/cr_common.py 2016-02-01 09:02:56 +0000
4@@ -161,8 +161,9 @@
5
6 # Parse and store the package.yaml, if it exists
7 pkg_yaml = self._extract_package_yaml()
8+ snap_yaml = self._extract_snap_yaml()
9 self.is_snap = False
10- if pkg_yaml is None:
11+ if pkg_yaml is None and snap_yaml is None:
12 self.pkgfmt["type"] = "click"
13 else:
14 self.pkgfmt["type"] = "snap"
15@@ -176,11 +177,23 @@
16 else:
17 self.pkgfmt["version"] = "15.04"
18
19- try:
20- self.pkg_yaml = yaml.safe_load(pkg_yaml)
21- except Exception:
22- error("Could not load package.yaml. Is it properly formatted?")
23- self._verify_package_yaml_structure()
24+ if snap_yaml:
25+ try:
26+ self.snap_yaml = yaml.safe_load(snap_yaml)
27+ except Exception:
28+ error("Could not load snap.yaml. Is it properly formatted?")
29+ # convert enough of snap_yaml too pkg.yaml to make
30+ # the basics of the review tools
31+ if self.snap_yaml:
32+ self.pkg_yaml = self.snap_yaml
33+ self.pkg_yaml["version"] = str(self.snap_yaml["version"])
34+
35+ if pkg_yaml:
36+ try:
37+ self.pkg_yaml = yaml.safe_load(pkg_yaml)
38+ except Exception:
39+ error("Could not load package.yaml. Is it properly formatted?")
40+ self._verify_package_yaml_structure()
41 self.is_snap = True
42
43 # default to 'app'
44@@ -272,12 +285,19 @@
45 return open_file_read(m)
46
47 def _extract_package_yaml(self):
48- '''Extract and read the snappy package.yaml'''
49+ '''Extract and read the snappy 15.04 package.yaml'''
50 y = os.path.join(self.unpack_dir, "meta/package.yaml")
51 if not os.path.isfile(y):
52 return None # snappy packaging is still optional
53 return open_file_read(y)
54
55+ def _extract_snap_yaml(self):
56+ '''Extract and read the snappy 16.04 snap.yaml'''
57+ y = os.path.join(self.unpack_dir, "meta/snap.yaml")
58+ if not os.path.isfile(y):
59+ return None # snappy packaging is still optional
60+ return open_file_read(y)
61+
62 def _extract_hashes_yaml(self):
63 '''Extract and read the snappy hashes.yaml'''
64 y = os.path.join(self.unpack_dir, "DEBIAN/hashes.yaml")
65
66=== modified file 'clickreviews/cr_lint.py'
67--- clickreviews/cr_lint.py 2016-01-20 14:02:52 +0000
68+++ clickreviews/cr_lint.py 2016-02-01 09:02:56 +0000
69@@ -1222,6 +1222,15 @@
70 manual_review = True
71 self._add_result(t, n, s, manual_review=manual_review)
72
73+ def check_squashfs_uses_snap_yaml(self):
74+ '''Ensure that squashfs uses 16.04'''
75+ if is_squashfs(self.pkg_filename) and not getattr(self, "snap_yaml"):
76+ t = 'error'
77+ n = self._get_check_name('check_squashfs_uses_snap_yaml')
78+ s = "squashfs snaps must have a meta/snap.yaml"
79+ manual_review = False
80+ self._add_result(t, n, s, manual_review=manual_review)
81+
82 def check_snappy_hashes(self):
83 '''Check snappy hashes.yaml'''
84 if self._pkgfmt_type() == "snap" and \
85
86=== modified file 'clickreviews/cr_tests.py'
87--- clickreviews/cr_tests.py 2015-11-20 21:03:02 +0000
88+++ clickreviews/cr_tests.py 2016-02-01 09:02:56 +0000
89@@ -31,6 +31,7 @@
90 TEST_CONTROL = ""
91 TEST_MANIFEST = ""
92 TEST_PKG_YAML = ""
93+TEST_SNAP_YAML = ""
94 TEST_HASHES_YAML = ""
95 TEST_README_MD = ""
96 TEST_SECURITY = dict()
97@@ -77,6 +78,11 @@
98 return io.StringIO(TEST_PKG_YAML)
99
100
101+def _extract_snap_yaml(self):
102+ '''Pretend we read the package.yaml file'''
103+ return io.StringIO(TEST_SNAP_YAML)
104+
105+
106 def _extract_hashes_yaml(self):
107 '''Pretend we read the hashes.yaml file'''
108 return io.StringIO(TEST_HASHES_YAML)
109@@ -281,6 +287,9 @@
110 'clickreviews.cr_common.ClickReview._extract_package_yaml',
111 _extract_package_yaml))
112 patches.append(patch(
113+ 'clickreviews.cr_common.ClickReview._extract_snap_yaml',
114+ _extract_snap_yaml))
115+ patches.append(patch(
116 'clickreviews.cr_common.ClickReview._extract_hashes_yaml',
117 _extract_hashes_yaml))
118 patches.append(patch(
119@@ -448,6 +457,8 @@
120 [self.test_control['Architecture']])
121 self._update_test_pkg_yaml()
122
123+ self.test_snap_yaml = dict()
124+
125 self.test_hashes_yaml = dict()
126 self._update_test_hashes_yaml()
127
128@@ -566,6 +577,12 @@
129 default_flow_style=False,
130 indent=4)
131
132+ def _update_test_snap_yaml(self):
133+ global TEST_SNAP_YAML
134+ TEST_SNAP_YAML = yaml.dump(self.test_snap_yaml,
135+ default_flow_style=False,
136+ indent=4)
137+
138 def _update_test_hashes_yaml(self):
139 global TEST_HASHES_YAML
140 TEST_HASHES_YAML = yaml.dump(self.test_hashes_yaml,
141@@ -794,6 +811,16 @@
142 self.test_pkg_yaml[key] = value
143 self._update_test_pkg_yaml()
144
145+ def set_test_snap_yaml(self, key, value):
146+ '''Set key in meta/snap.yaml to value. If value is None, remove
147+ key'''
148+ if value is None:
149+ if key in self.test_snap_yaml:
150+ self.test_snap_yaml.pop(key, None)
151+ else:
152+ self.test_snap_yaml[key] = value
153+ self._update_test_snap_yaml()
154+
155 def set_test_hashes_yaml(self, yaml):
156 '''Set hashes.yaml to yaml'''
157 self.test_hashes_yaml = yaml
158@@ -1137,6 +1164,8 @@
159 TEST_MANIFEST = ""
160 global TEST_PKG_YAML
161 TEST_PKG_YAML = ""
162+ global TEST_SNAP_YAML
163+ TEST_SNAP_YAML = ""
164 global TEST_HASHES_YAML
165 TEST_HASHES_YAML = ""
166 global TEST_README_MD
167
168=== modified file 'clickreviews/tests/test_cr_lint.py'
169--- clickreviews/tests/test_cr_lint.py 2016-01-20 17:27:51 +0000
170+++ clickreviews/tests/test_cr_lint.py 2016-02-01 09:02:56 +0000
171@@ -2190,6 +2190,30 @@
172 expected_counts = {'info': None, 'warn': 0, 'error': 1}
173 self.check_results(r, expected_counts)
174
175+ def test_squashfs_needs_snap_yaml(self):
176+ '''Test that squashfs snaps have a snap.yaml'''
177+ c = ClickReviewLint(self.test_name)
178+ c.unpack_dir = "/nonexistent.nonexec"
179+ with patch("clickreviews.cr_lint.is_squashfs") as mock_is_squashfs:
180+ mock_is_squashfs.return_value = True
181+ c.check_squashfs_uses_snap_yaml()
182+ r = c.click_report
183+ expected_counts = {'info': None, 'warn': 0, 'error': 1}
184+ self.assertEqual(r["error"]["lint:check_squashfs_uses_snap_yaml"]["text"], "squashfs snaps must have a meta/snap.yaml")
185+ self.check_results(r, expected_counts)
186+
187+ def test_squashfs_needs_snap_yaml_ok(self):
188+ '''Test that squashfs snaps have a snap.yaml'''
189+ c = ClickReviewLint(self.test_name)
190+ c.unpack_dir = "/nonexistent.nonexec"
191+ c.snap_yaml = {"name": "foo"}
192+ with patch("clickreviews.cr_lint.is_squashfs") as mock_is_squashfs:
193+ mock_is_squashfs.return_value = True
194+ c.check_squashfs_uses_snap_yaml()
195+ r = c.click_report
196+ expected_counts = {'info': None, 'warn': 0, 'error': 0}
197+ self.check_results(r, expected_counts)
198+
199
200 class ClickReviewLintTestCase(TestCase):
201 """Tests without mocks where they are not needed."""

Subscribers

People subscribed via source and target branches