Merge lp:~cjwatson/launchpad/snap-upload-check-filename into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18187
Proposed branch: lp:~cjwatson/launchpad/snap-upload-check-filename
Merge into: lp:launchpad
Diff against target: 86 lines (+31/-10)
2 files modified
lib/lp/archiveuploader/snapupload.py (+13/-9)
lib/lp/archiveuploader/tests/test_snapupload.py (+18/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-upload-check-filename
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+304369@code.launchpad.net

Commit message

If other files (e.g. manifests) are uploaded alongside snaps, make sure that there is still at least one snap.

Description of the change

If other files (e.g. manifests) are uploaded alongside snaps, make sure that there is still at least one snap.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Looks good. One question inline.

Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/snapupload.py'
2--- lib/lp/archiveuploader/snapupload.py 2015-08-03 15:07:29 +0000
3+++ lib/lp/archiveuploader/snapupload.py 2016-09-16 11:59:12 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Process a snap package upload."""
10@@ -38,23 +38,27 @@
11 self.logger.debug("Beginning processing.")
12
13 found_snap = False
14+ snap_paths = []
15 for dirpath, _, filenames in os.walk(self.upload_path):
16 if dirpath == self.upload_path:
17 # All relevant files will be in a subdirectory.
18 continue
19 for snap_file in sorted(filenames):
20- snap_path = os.path.join(dirpath, snap_file)
21- libraryfile = self.librarian.create(
22- snap_file, os.stat(snap_path).st_size,
23- open(snap_path, "rb"),
24- filenameToContentType(snap_path),
25- restricted=build.is_private)
26- found_snap = True
27- build.addFile(libraryfile)
28+ if snap_file.endswith(".snap"):
29+ found_snap = True
30+ snap_paths.append(os.path.join(dirpath, snap_file))
31
32 if not found_snap:
33 raise UploadError("Build did not produce any snap packages.")
34
35+ for snap_path in snap_paths:
36+ libraryfile = self.librarian.create(
37+ os.path.basename(snap_path), os.stat(snap_path).st_size,
38+ open(snap_path, "rb"),
39+ filenameToContentType(snap_path),
40+ restricted=build.is_private)
41+ build.addFile(libraryfile)
42+
43 # The master verifies the status to confirm successful upload.
44 self.logger.debug("Updating %s" % build.title)
45 build.updateStatus(BuildStatus.FULLYBUILT)
46
47=== modified file 'lib/lp/archiveuploader/tests/test_snapupload.py'
48--- lib/lp/archiveuploader/tests/test_snapupload.py 2016-06-28 21:10:18 +0000
49+++ lib/lp/archiveuploader/tests/test_snapupload.py 2016-09-16 11:59:12 +0000
50@@ -1,4 +1,4 @@
51-# Copyright 2015 Canonical Ltd. This software is licensed under the
52+# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
53 # GNU Affero General Public License version 3 (see the file LICENSE).
54
55 """Test uploads of SnapBuilds."""
56@@ -53,6 +53,7 @@
57 upload_dir = os.path.join(
58 self.incoming_folder, "test", str(self.build.id), "ubuntu")
59 write_file(os.path.join(upload_dir, "wget_0_all.snap"), "snap")
60+ write_file(os.path.join(upload_dir, "wget_0_all.manifest"), "manifest")
61 handler = UploadHandler.forProcessor(
62 self.uploadprocessor, self.incoming_folder, "test", self.build)
63 result = handler.processSnap(self.log)
64@@ -62,6 +63,22 @@
65 self.assertEqual(BuildStatus.FULLYBUILT, self.build.status)
66 self.assertTrue(self.build.verifySuccessfulUpload())
67
68+ def test_requires_snap(self):
69+ # The upload processor fails if the upload does not contain any
70+ # .snap files.
71+ self.assertFalse(self.build.verifySuccessfulUpload())
72+ upload_dir = os.path.join(
73+ self.incoming_folder, "test", str(self.build.id), "ubuntu")
74+ write_file(os.path.join(upload_dir, "wget_0_all.manifest"), "manifest")
75+ handler = UploadHandler.forProcessor(
76+ self.uploadprocessor, self.incoming_folder, "test", self.build)
77+ result = handler.processSnap(self.log)
78+ self.assertEqual(UploadStatusEnum.REJECTED, result)
79+ self.assertIn(
80+ "ERROR Build did not produce any snap packages.",
81+ self.log.getLogBuffer())
82+ self.assertFalse(self.build.verifySuccessfulUpload())
83+
84 def test_triggers_store_uploads(self):
85 # The upload processor triggers store uploads if appropriate.
86 self.pushConfig(