Merge lp:~cjwatson/launchpad/code-import-data-send-dict into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18616
Proposed branch: lp:~cjwatson/launchpad/code-import-data-send-dict
Merge into: lp:launchpad
Diff against target: 63 lines (+19/-13)
2 files modified
lib/lp/code/xmlrpc/codeimportscheduler.py (+8/-4)
lib/lp/code/xmlrpc/tests/test_codeimportscheduler.py (+11/-9)
To merge this branch: bzr merge lp:~cjwatson/launchpad/code-import-data-send-dict
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+342220@code.launchpad.net

Commit message

Push blacklisted_hostnames to code import workers via the scheduler.

Description of the change

This will make it easier to split out the code import workers to a separate codebase without having to duplicate configuration.

In the process, I've started making use of the fact that code import workers now allow CodeImportSchedulerAPI.getImportDataForJobID to return a dict.

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/code/xmlrpc/codeimportscheduler.py'
2--- lib/lp/code/xmlrpc/codeimportscheduler.py 2018-03-15 20:44:04 +0000
3+++ lib/lp/code/xmlrpc/codeimportscheduler.py 2018-03-27 16:47:23 +0000
4@@ -13,6 +13,7 @@
5 from zope.security.proxy import removeSecurityProxy
6
7 from lp.code.enums import CodeImportResultStatus
8+from lp.code.interfaces.branch import get_blacklisted_hostnames
9 from lp.code.interfaces.codeimportjob import (
10 ICodeImportJobSet,
11 ICodeImportJobWorkflow,
12@@ -66,11 +67,14 @@
13 @return_fault
14 def _getImportDataForJobID(self, job_id):
15 job = self._getJob(job_id)
16- arguments = job.makeWorkerArguments()
17 target = job.code_import.target
18- target_url = canonical_url(target)
19- log_file_name = '%s.log' % target.unique_name[1:].replace('/', '-')
20- return (arguments, target_url, log_file_name)
21+ return {
22+ 'arguments': job.makeWorkerArguments(),
23+ 'target_url': canonical_url(target),
24+ 'log_file_name': '%s.log' % (
25+ target.unique_name[1:].replace('/', '-')),
26+ 'blacklisted_hostnames': get_blacklisted_hostnames(),
27+ }
28
29 @return_fault
30 def _updateHeartbeat(self, job_id, log_tail):
31
32=== modified file 'lib/lp/code/xmlrpc/tests/test_codeimportscheduler.py'
33--- lib/lp/code/xmlrpc/tests/test_codeimportscheduler.py 2018-03-15 20:44:04 +0000
34+++ lib/lp/code/xmlrpc/tests/test_codeimportscheduler.py 2018-03-27 16:47:23 +0000
35@@ -58,17 +58,19 @@
36 def test_getImportDataForJobID(self):
37 # getImportDataForJobID returns the worker arguments, target url and
38 # log file name for an import corresponding to a particular job.
39+ self.pushConfig(
40+ 'codehosting', blacklisted_hostnames='localhost,127.0.0.1')
41 code_import_job = self.makeCodeImportJob(running=True)
42 code_import = removeSecurityProxy(code_import_job).code_import
43- code_import_arguments, target_url, log_file_name = \
44- self.api.getImportDataForJobID(code_import_job.id)
45- import_as_arguments = code_import_job.makeWorkerArguments()
46- expected_log_file_name = '%s.log' % (
47- code_import.target.unique_name[1:].replace('/', '-'))
48- self.assertEqual(
49- (import_as_arguments, canonical_url(code_import.target),
50- expected_log_file_name),
51- (code_import_arguments, target_url, log_file_name))
52+ data = self.api.getImportDataForJobID(code_import_job.id)
53+ expected_data = {
54+ 'arguments': code_import_job.makeWorkerArguments(),
55+ 'target_url': canonical_url(code_import.target),
56+ 'log_file_name': '%s.log' % (
57+ code_import.target.unique_name[1:].replace('/', '-')),
58+ 'blacklisted_hostnames': ['localhost', '127.0.0.1'],
59+ }
60+ self.assertEqual(expected_data, data)
61
62 def test_getImportDataForJobID_not_found(self):
63 # getImportDataForJobID returns a NoSuchCodeImportJob fault when there