Merge lp:~vila/ubuntu-ci-services-itself/run-workers-fix into lp:ubuntu-ci-services-itself

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 319
Merged at revision: 320
Proposed branch: lp:~vila/ubuntu-ci-services-itself/run-workers-fix
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 202 lines (+57/-28)
9 files modified
branch-source-builder/bsbuilder/run_worker.py (+2/-6)
image-builder/imagebuilder/run_worker.py (+0/-4)
juju-deployer/branch-source-builder.yaml.tmpl (+1/-1)
juju-deployer/image-builder.yaml.tmpl (+1/-1)
juju-deployer/lander.yaml.tmpl (+1/-1)
juju-deployer/test-runner.yaml.tmpl (+1/-1)
lander/lander/run_worker.py (+1/-4)
run-python (+46/-0)
test_runner/tstrun/run_worker.py (+4/-10)
To merge this branch: bzr merge lp:~vila/ubuntu-ci-services-itself/run-workers-fix
Reviewer Review Type Date Requested Status
Evan (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+209623@code.launchpad.net

Commit message

fix broken run-worker change

revno(315) caused a regression because all the run-worker scripts
were dealing with sys.path in order to import things properly. This
patch adds a new "run-python" script that will launch the worker
scripts with the proper PYTHONPATH.

Description of the change

Fix pep8 issue blocking https://code.launchpad.net/~doanac/ubuntu-ci-services-itself/run-workers-fix/+merge/209583 landing.

I'm not using Andy's branch as a pre-requisite because doing so would block the landing. Full credit to Andy anyway.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:319
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~vila/ubuntu-ci-services-itself/run-workers-fix/+merge/209623/+edit-commit-message

http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/305/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/305/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Evan (ev) wrote :

I've done a full deploy to test this, checking that all the rabbit workers were operational.

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'branch-source-builder/bsbuilder/run_worker.py'
2--- branch-source-builder/bsbuilder/run_worker.py 2014-03-05 11:41:47 +0000
3+++ branch-source-builder/bsbuilder/run_worker.py 2014-03-06 09:35:24 +0000
4@@ -16,20 +16,16 @@
5
6 import json
7 import logging
8-import os
9-import sys
10 import time
11
12 import upload_package
13 import watch_ppa
14
15+from ci_utils import amqp_utils, dump_stack
16+
17 logging.basicConfig(level=logging.INFO)
18 log = logging.getLogger(__name__)
19
20-# the worker might not have installed this module, so determine the path
21-# and add it, so we can always safely import stuff
22-sys.path.append(os.path.join(os.path.dirname(__file__), '../ci-utils'))
23-from ci_utils import amqp_utils, dump_stack
24 TIME_BETWEEN_CHECKS = 60
25
26
27
28=== modified file 'image-builder/imagebuilder/run_worker.py'
29--- image-builder/imagebuilder/run_worker.py 2014-03-05 11:20:09 +0000
30+++ image-builder/imagebuilder/run_worker.py 2014-03-06 09:35:24 +0000
31@@ -16,7 +16,6 @@
32
33 import json
34 import logging
35-import os
36 import sys
37 from cStringIO import StringIO
38
39@@ -31,9 +30,6 @@
40 logstream.setLevel(logging.INFO)
41 log.addHandler(logstream)
42
43-# the worker might not have installed this module, so determine the path
44-# and add it, so we can always safely import stuff
45-sys.path.append(os.path.join(os.path.dirname(__file__), '../ci-utils'))
46 from ci_utils import amqp_utils
47 from ci_utils import dump_stack
48 from ci_utils import data_store
49
50=== modified file 'juju-deployer/branch-source-builder.yaml.tmpl'
51--- juju-deployer/branch-source-builder.yaml.tmpl 2014-03-05 11:41:47 +0000
52+++ juju-deployer/branch-source-builder.yaml.tmpl 2014-03-06 09:35:24 +0000
53@@ -19,7 +19,7 @@
54 bsb-worker:
55 charm: rabbitmq-worker
56 options:
57- main: ./branch-source-builder/bsbuilder/run_worker.py
58+ main: ./run-python ./branch-source-builder/bsbuilder/run_worker.py
59 vcs: ${CI_CODE_SOURCE}
60 branch: ${CI_BRANCH}
61 tarball: ${CI_PAYLOAD_URL}
62
63=== modified file 'juju-deployer/image-builder.yaml.tmpl'
64--- juju-deployer/image-builder.yaml.tmpl 2014-03-05 11:20:09 +0000
65+++ juju-deployer/image-builder.yaml.tmpl 2014-03-06 09:35:24 +0000
66@@ -20,7 +20,7 @@
67 charm: rabbitmq-worker
68 constraints: "root-disk=8192M"
69 options:
70- main: ./image-builder/imagebuilder/run_worker.py
71+ main: ./run-python ./image-builder/imagebuilder/run_worker.py
72 vcs: ${CI_CODE_SOURCE}
73 branch: ${CI_BRANCH}
74 tarball: ${CI_PAYLOAD_URL}
75
76=== modified file 'juju-deployer/lander.yaml.tmpl'
77--- juju-deployer/lander.yaml.tmpl 2014-03-05 11:20:09 +0000
78+++ juju-deployer/lander.yaml.tmpl 2014-03-06 09:35:24 +0000
79@@ -37,7 +37,7 @@
80 packages: "python-amqplib python-swiftclient lazr.enum"
81 plugins: "parameterized-trigger:2.14"
82 unit-config: include-base64://configs/unit_config.yaml
83- main: ./lander/lander/run_worker.py --service-name ts-django --service-port 8080 --delay 60
84+ main: ./run-python ./lander/lander/run_worker.py --service-name ts-django --service-port 8080 --delay 60
85 rabbit:
86 branch: lp:~canonical-ci-engineering/charms/precise/ubuntu-ci-services-itself/rabbitmq-server@46
87 charm: rabbitmq
88
89=== modified file 'juju-deployer/test-runner.yaml.tmpl'
90--- juju-deployer/test-runner.yaml.tmpl 2014-03-05 11:20:09 +0000
91+++ juju-deployer/test-runner.yaml.tmpl 2014-03-06 09:35:24 +0000
92@@ -27,7 +27,7 @@
93 charm: rabbitmq-worker
94 options:
95 # for tests branch: lp:~vila/ubuntu-ci-services-itself/testy
96- main: ./test_runner/tstrun/run_worker.py
97+ main: ./run-python ./test_runner/tstrun/run_worker.py
98 vcs: ${CI_CODE_SOURCE}
99 branch: ${CI_BRANCH}
100 tarball: ${CI_PAYLOAD_URL}
101
102=== modified file 'lander/lander/run_worker.py'
103--- lander/lander/run_worker.py 2014-03-05 11:20:09 +0000
104+++ lander/lander/run_worker.py 2014-03-06 09:35:24 +0000
105@@ -23,14 +23,11 @@
106 import time
107 import urllib2
108
109-# the worker might not have installed this module, so determine the path
110-# and add it, so we can always safely import stuff
111-sys.path.append(os.path.join(os.path.dirname(__file__), '../ci-utils'))
112 from ci_utils import jenkins_utils
113 from ci_utils import dump_stack
114
115 MAX_RETRIES = 15
116-SERVICE_PATH = os.path.join(os.path.dirname(__file__), '../juju-relations')
117+SERVICE_PATH = os.path.join(os.path.dirname(__file__), '../../juju-relations')
118
119 # set up a root logger for everything
120 stdout_handler = logging.StreamHandler(stream=sys.stdout)
121
122=== added file 'run-python'
123--- run-python 1970-01-01 00:00:00 +0000
124+++ run-python 2014-03-06 09:35:24 +0000
125@@ -0,0 +1,46 @@
126+#!/usr/bin/python
127+
128+import os
129+import sys
130+
131+
132+def _usage():
133+ print('Usage: %s script [arg [arg...]]' % sys.argv[0])
134+ print('Sets up a PYTHONPATH with our ci-utils so that python scripts '
135+ 'can be launched properly')
136+ exit(0)
137+
138+
139+def _parse_args(args):
140+ if not args or args[0] in ['-h', '--help', '-help']:
141+ _usage()
142+ return args[0], args
143+
144+
145+def _component_path(basedir, script):
146+ '''return the path to the component of the script'''
147+ script = os.path.abspath(script)
148+ if basedir not in script:
149+ exit('ERROR: scripts must reside in source tree')
150+ script = script[len(basedir) + 1:]
151+ return script.split('/')[0]
152+
153+
154+def main(args):
155+ script, args = _parse_args(args)
156+
157+ here = os.path.abspath(os.path.dirname(__file__))
158+ ci_utils = os.path.join(here, 'ci-utils')
159+ comp = _component_path(here, script)
160+
161+ python_path = os.environ.get('PYTHONPATH')
162+ if python_path:
163+ python_path = '{}:{}:{}'.format(ci_utils, comp, python_path)
164+ else:
165+ python_path = '{}:{}'.format(ci_utils, comp)
166+ os.environ['PYTHONPATH'] = python_path
167+
168+ os.execv(script, args)
169+
170+if __name__ == '__main__':
171+ exit(main(sys.argv[1:]))
172
173=== modified file 'test_runner/tstrun/run_worker.py'
174--- test_runner/tstrun/run_worker.py 2014-03-05 11:20:09 +0000
175+++ test_runner/tstrun/run_worker.py 2014-03-06 09:35:24 +0000
176@@ -16,22 +16,16 @@
177
178 import json
179 import logging
180-import os
181-import sys
182-
183-
184-logging.basicConfig(level=logging.INFO)
185-log = logging.getLogger(__name__)
186-
187-# the worker might not have installed this module, so determine the path
188-# and add it, so we can always safely import stuff
189-sys.path.append(os.path.join(os.path.dirname(__file__), '../ci-utils'))
190+
191 from ci_utils import amqp_utils
192 from ci_utils import dump_stack
193 from ci_utils import data_store
194 import tstrun
195 from tstrun import testbed
196
197+logging.basicConfig(level=logging.INFO)
198+log = logging.getLogger(__name__)
199+
200
201 def on_message(msg):
202 log.info('on_message: %s', msg.body)

Subscribers

People subscribed via source and target branches