Merge lp:~cjwatson/launchpad/publish-ftpmaster-cron-control into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18290
Proposed branch: lp:~cjwatson/launchpad/publish-ftpmaster-cron-control
Merge into: lp:launchpad
Diff against target: 98 lines (+30/-8)
3 files modified
lib/lp/archivepublisher/scripts/publish_ftpmaster.py (+3/-2)
lib/lp/archivepublisher/tests/test_publish_ftpmaster.py (+19/-0)
lib/lp/services/scripts/base.py (+8/-6)
To merge this branch: bzr merge lp:~cjwatson/launchpad/publish-ftpmaster-cron-control
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+312511@code.launchpad.net

Commit message

Don't allow cron-control to interrupt publish-ftpmaster part-way through.

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/archivepublisher/scripts/publish_ftpmaster.py'
2--- lib/lp/archivepublisher/scripts/publish_ftpmaster.py 2016-11-11 15:31:08 +0000
3+++ lib/lp/archivepublisher/scripts/publish_ftpmaster.py 2016-12-05 22:20:07 +0000
4@@ -334,7 +334,8 @@
5 self.logger.debug(
6 "Processing the accepted queue into the publishing records...")
7 script = ProcessAccepted(
8- test_args=["-d", distribution.name], logger=self.logger)
9+ test_args=["-d", distribution.name], logger=self.logger,
10+ ignore_cron_control=True)
11 script.txn = self.txn
12 script.main()
13
14@@ -428,7 +429,7 @@
15 sum([['-s', suite] for suite in suites], []))
16
17 publish_distro = PublishDistro(
18- test_args=arguments, logger=self.logger)
19+ test_args=arguments, logger=self.logger, ignore_cron_control=True)
20 publish_distro.logger = self.logger
21 publish_distro.txn = self.txn
22 publish_distro.main()
23
24=== modified file 'lib/lp/archivepublisher/tests/test_publish_ftpmaster.py'
25--- lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2016-11-07 16:42:23 +0000
26+++ lib/lp/archivepublisher/tests/test_publish_ftpmaster.py 2016-12-05 22:20:07 +0000
27@@ -11,10 +11,13 @@
28 import time
29
30 from apt_pkg import TagFile
31+from fixtures import MonkeyPatch
32 from testtools.matchers import (
33+ MatchesException,
34 MatchesStructure,
35 Not,
36 PathExists,
37+ Raises,
38 StartsWith,
39 )
40 from zope.component import getUtility
41@@ -1080,6 +1083,22 @@
42
43 self.assertEqual(1, script.recoverArchiveWorkingDir.call_count)
44
45+ def test_publish_is_not_interrupted_by_cron_control(self):
46+ # If cron-control switches to the disabled state in the middle of a
47+ # publisher run, all the subsidiary scripts are still run.
48+ script = self.makeScript()
49+ self.useFixture(MonkeyPatch(
50+ "lp.services.scripts.base.cronscript_enabled", FakeMethod(False)))
51+ process_accepted_fixture = self.useFixture(MonkeyPatch(
52+ "lp.archivepublisher.scripts.processaccepted.ProcessAccepted.main",
53+ FakeMethod()))
54+ publish_distro_fixture = self.useFixture(MonkeyPatch(
55+ "lp.archivepublisher.scripts.publishdistro.PublishDistro.main",
56+ FakeMethod()))
57+ self.assertThat(script.main, Not(Raises(MatchesException(SystemExit))))
58+ self.assertEqual(1, process_accepted_fixture.new_value.call_count)
59+ self.assertEqual(1, publish_distro_fixture.new_value.call_count)
60+
61
62 class TestCreateDistroSeriesIndexes(TestCaseWithFactory, HelpersMixin):
63 """Test initial creation of archive indexes for a `DistroSeries`."""
64
65=== modified file 'lib/lp/services/scripts/base.py'
66--- lib/lp/services/scripts/base.py 2014-08-29 01:34:04 +0000
67+++ lib/lp/services/scripts/base.py 2016-12-05 22:20:07 +0000
68@@ -1,4 +1,4 @@
69-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
70+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
71 # GNU Affero General Public License version 3 (see the file LICENSE).
72
73 __metaclass__ = type
74@@ -376,17 +376,19 @@
75 class LaunchpadCronScript(LaunchpadScript):
76 """Logs successful script runs in the database."""
77
78- def __init__(self, name=None, dbuser=None, test_args=None, logger=None):
79+ def __init__(self, name=None, dbuser=None, test_args=None, logger=None,
80+ ignore_cron_control=False):
81 super(LaunchpadCronScript, self).__init__(
82 name, dbuser, test_args=test_args, logger=logger)
83
84 # self.name is used instead of the name argument, since it may have
85 # have been overridden by command-line parameters or by
86 # overriding the name property.
87- enabled = cronscript_enabled(
88- config.canonical.cron_control_url, self.name, self.logger)
89- if not enabled:
90- sys.exit(0)
91+ if not ignore_cron_control:
92+ enabled = cronscript_enabled(
93+ config.canonical.cron_control_url, self.name, self.logger)
94+ if not enabled:
95+ sys.exit(0)
96
97 # Configure the IErrorReportingUtility we use with defaults.
98 # Scripts can override this if they want.