Merge lp:~allenap/launchpad/pcj-more-often-bug-770721-pre into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 13893
Proposed branch: lp:~allenap/launchpad/pcj-more-often-bug-770721-pre
Merge into: lp:launchpad
Diff against target: 86 lines (+38/-2)
2 files modified
cronscripts/process-job-source-groups.py (+4/-2)
lib/lp/registry/tests/test_process_job_sources_cronjob.py (+34/-0)
To merge this branch: bzr merge lp:~allenap/launchpad/pcj-more-often-bug-770721-pre
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+74293@code.launchpad.net

Commit message

[r=stevenk][bug=770721] Make --exclude work with process-job-source-groups.py.

Description of the change

Make --exclude work with process-job-source-groups.py. This is needed
by a succession of future branches:

See the bug report, comment #3 for the big picture:
  https://bugs.launchpad.net/lp-production-crontabs/+bug/770721/comments/3

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cronscripts/process-job-source-groups.py'
2--- cronscripts/process-job-source-groups.py 2010-09-30 20:39:02 +0000
3+++ cronscripts/process-job-source-groups.py 2011-09-06 19:49:24 +0000
4@@ -16,6 +16,7 @@
5 import _pythonpath
6
7 from canonical.config import config
8+from canonical.launchpad.helpers import english_list
9 from lp.services.propertycache import cachedproperty
10 from lp.services.scripts.base import LaunchpadCronScript
11
12@@ -68,8 +69,9 @@
13 # Then, exclude job sources.
14 for source in self.options.excluded_job_sources:
15 if source not in selected_job_sources:
16- self.logger.info('%r is not in job source groups %s'
17- % (source, self.options.groups))
18+ self.logger.info(
19+ '%r is not in %s' % (
20+ source, english_list(selected_groups, "or")))
21 else:
22 selected_job_sources.remove(source)
23 # Process job sources.
24
25=== modified file 'lib/lp/registry/tests/test_process_job_sources_cronjob.py'
26--- lib/lp/registry/tests/test_process_job_sources_cronjob.py 2011-02-25 11:53:04 +0000
27+++ lib/lp/registry/tests/test_process_job_sources_cronjob.py 2011-09-06 19:49:24 +0000
28@@ -8,6 +8,7 @@
29 import transaction
30 from zope.component import getUtility
31
32+from canonical.config import config
33 from canonical.launchpad.scripts.tests import run_script
34 from canonical.testing import LaunchpadScriptLayer
35 from lp.registry.interfaces.teammembership import (
36@@ -18,6 +19,7 @@
37 login_person,
38 TestCaseWithFactory,
39 )
40+from lp.testing.matchers import DocTestMatches
41
42
43 class ProcessJobSourceTest(TestCaseWithFactory):
44@@ -72,6 +74,16 @@
45 layer = LaunchpadScriptLayer
46 script = 'cronscripts/process-job-source-groups.py'
47
48+ def getJobSources(self, *groups):
49+ sources = config['process-job-source-groups'].job_sources
50+ sources = (source.strip() for source in sources.split(','))
51+ sources = (source for source in sources if source in config)
52+ if len(groups) != 0:
53+ sources = (
54+ source for source in sources
55+ if config[source].crontab_group in groups)
56+ return sorted(set(sources))
57+
58 def tearDown(self):
59 super(ProcessJobSourceGroupsTest, self).tearDown()
60 self.layer.force_dirty_database()
61@@ -119,3 +131,25 @@
62 error)
63 self.assertIn('DEBUG MembershipNotificationJob sent email', error)
64 self.assertIn('Ran 1 MembershipNotificationJob jobs.', error)
65+
66+ def test_exclude(self):
67+ # Job sources can be excluded with a --exclude switch.
68+ args = ["MAIN"]
69+ for source in self.getJobSources("MAIN"):
70+ args.extend(("--exclude", source))
71+ returncode, output, error = run_script(self.script, args)
72+ expected = "INFO Creating lockfile: ...\n"
73+ self.assertThat(error, DocTestMatches(expected))
74+
75+ def test_exclude_non_existing_group(self):
76+ # If a job source specified by --exclude does not exist the script
77+ # continues, logging a short info message about it.
78+ args = ["MAIN"]
79+ for source in self.getJobSources("MAIN"):
80+ args.extend(("--exclude", source))
81+ args.extend(("--exclude", "BobbyDazzler"))
82+ returncode, output, error = run_script(self.script, args)
83+ expected = (
84+ "INFO Creating lockfile: ...\n"
85+ "INFO 'BobbyDazzler' is not in MAIN\n")
86+ self.assertThat(error, DocTestMatches(expected))