Merge lp:~cjwatson/launchpad/snap-upload-deleted-builds into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18304
Proposed branch: lp:~cjwatson/launchpad/snap-upload-deleted-builds
Merge into: lp:launchpad
Diff against target: 62 lines (+30/-3)
2 files modified
lib/lp/archiveuploader/tests/test_uploadprocessor.py (+23/-1)
lib/lp/archiveuploader/uploadprocessor.py (+7/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-upload-deleted-builds
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+314433@code.launchpad.net

Commit message

Move upload to FAILED if its build was deleted (e.g. because of a deleted snap).

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/archiveuploader/tests/test_uploadprocessor.py'
2--- lib/lp/archiveuploader/tests/test_uploadprocessor.py 2016-07-02 07:55:26 +0000
3+++ lib/lp/archiveuploader/tests/test_uploadprocessor.py 2017-01-10 15:41:21 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Functional tests for uploadprocessor.py."""
10@@ -2258,6 +2258,28 @@
11 self.assertIsNot(None, build.duration)
12 self.assertIs(None, build.upload_log)
13
14+ def testSnapBuild_deleted_snap(self):
15+ # A snap build will fail if the snap is deleted.
16+ self.switchToAdmin()
17+ build = self.factory.makeSnapBuild()
18+ self.switchToUploader()
19+ Store.of(build).flush()
20+ behaviour = IBuildFarmJobBehaviour(build)
21+ leaf_name = behaviour.getUploadDirLeaf(build.build_cookie)
22+ os.mkdir(os.path.join(self.incoming_folder, leaf_name))
23+ self.options.context = 'buildd'
24+ self.options.builds = True
25+ build.updateStatus(BuildStatus.UPLOADING)
26+ self.switchToAdmin()
27+ build.snap.destroySelf()
28+ self.switchToUploader()
29+ BuildUploadHandler(
30+ self.uploadprocessor, self.incoming_folder, leaf_name).process()
31+ self.assertFalse(
32+ os.path.exists(os.path.join(self.incoming_folder, leaf_name)))
33+ self.assertTrue(
34+ os.path.exists(os.path.join(self.failed_folder, leaf_name)))
35+
36 def processUploadWithBuildStatus(self, status):
37 upload_dir = self.queueUpload("bar_1.0-1")
38 self.processUpload(self.uploadprocessor, upload_dir)
39
40=== modified file 'lib/lp/archiveuploader/uploadprocessor.py'
41--- lib/lp/archiveuploader/uploadprocessor.py 2015-08-03 15:07:29 +0000
42+++ lib/lp/archiveuploader/uploadprocessor.py 2017-01-10 15:41:21 +0000
43@@ -1,4 +1,4 @@
44-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
45+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
46 # GNU Affero General Public License version 3 (see the file LICENSE).
47
48 """Code for 'processing' 'uploads'. Also see nascentupload.py.
49@@ -645,7 +645,12 @@
50 Build uploads always contain a single package per leaf.
51 """
52 logger = BufferLogger()
53- if self.build.status == BuildStatus.BUILDING:
54+ if self.build is None:
55+ self.processor.log.info(
56+ "Build %s was deleted. Ignoring." % self.upload)
57+ self.moveUpload(UploadStatusEnum.FAILED, logger)
58+ return
59+ elif self.build.status == BuildStatus.BUILDING:
60 # Handoff from buildd-manager isn't complete until the
61 # status is UPLOADING.
62 self.processor.log.info("Build status is BUILDING. Ignoring.")