Merge lp:~doanac/charms/precise/ubuntu-ci-services-itself/lander into lp:~canonical-ci-engineering/charms/precise/ubuntu-ci-services-itself/lander

Proposed by Andy Doan
Status: Merged
Approved by: Francis Ginther
Approved revision: 27
Merged at revision: 23
Proposed branch: lp:~doanac/charms/precise/ubuntu-ci-services-itself/lander
Merge into: lp:~canonical-ci-engineering/charms/precise/ubuntu-ci-services-itself/lander
Diff against target: 283 lines (+86/-35)
4 files modified
config.yaml (+10/-0)
hooks/hooks.py (+38/-5)
metadata.yaml (+2/-0)
templates/jobs/lander_master.xml (+36/-30)
To merge this branch: bzr merge lp:~doanac/charms/precise/ubuntu-ci-services-itself/lander
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Andy Doan (community) Needs Resubmitting
Review via email: mp+200449@code.launchpad.net

Description of the change

This updates the master and ppa-assigner jobs to handle parameters properly. They now are able to determine things like the ppa-assigner's host ip via juju relation ships. It might be easiest to read this commit by commit.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

FYI - I have a private juju deployer file that can do a full deployment of the ppa-assigner and lander. Let me know if you want a copy (it includes oauth tokens so i can't share publically).

Revision history for this message
Francis Ginther (fginther) wrote :

The jenkins jobs are supposed to pass the params.json file from one job to the next, it's not intended to be created as is being done in templates/jobs/lander-ppa-assigner.xml. I confirmed that this is broken and am investigating.

Revision history for this message
Andy Doan (doanac) wrote :

On 01/06/2014 01:32 PM, Francis Ginther wrote:
> The jenkins jobs are supposed to pass the params.json file from one job to the next, it's not intended to be created as is being done in templates/jobs/lander-ppa-assigner.xml. I confirmed that this is broken and am investigating.

I think I've got this fixed in a branch based on this:

<http://bazaar.launchpad.net/~doanac/charms/precise/ubuntu-ci-services-itself/lander-bsb/revision/27>

if that looks sane, we can just fix it in that MP if that's okay?

22. By Francis Ginther

Fix jenkins jobs so that the accumulated json data is passed as a job parameter, update lander_archiver to work with updated script, add datastore config parameters.

23. By Andy Doan

store relationship information

the jenkins jobs will need to know the hostname of each service
connected to it like the ppa-assigner. This stores them under
a fix directory jobs can load dynamically

24. By Andy Doan

add ppa-assigner url to config

25. By Andy Doan

allow charm to interface with amqp

26. By Andy Doan

add bsbuilder config to master

27. By Andy Doan

clarify parameter passing and add progress trigger

parameter passing was being done via a file named child.json. However,
this is really a jenkins parameters file and not really json. This
renames that file and creates it with a few less lines of code.

Revision history for this message
Andy Doan (doanac) wrote :

I've rebased on your branch with a couple of minor updates. I changed your naming of "child.json" to "child.params" since it isn't really a json file. I then added the relationship handling logic to get the ppa-assigner and bsbuilder working.

review: Needs Resubmitting
Revision history for this message
Francis Ginther (fginther) wrote :

Thanks for cleaning up my child.json. I got the first one updated in lander_master, but failed to update the rest. The params file works just as well.

Revision history for this message
Francis Ginther (fginther) wrote :

I'm ok with the relation hooks, if we need to separate them later, we'll do it then.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2014-01-08 15:04:30 +0000
3+++ config.yaml 2014-01-08 21:09:33 +0000
4@@ -51,3 +51,13 @@
5 type: string
6 default: ""
7 description: Data store tenant name.
8+
9+# required for rabbitmq-server charm:
10+ amqp-user:
11+ type: string
12+ default: workerbee
13+ description: The user to log into the rabbitMQ server.
14+ amqp-vhost:
15+ type: string
16+ default: '/'
17+ description: The vhost in the rabbitMQ server.
18
19=== added symlink 'hooks/amqp-relation-broken'
20=== target is u'hooks.py'
21=== added symlink 'hooks/amqp-relation-changed'
22=== target is u'hooks.py'
23=== added symlink 'hooks/amqp-relation-joined'
24=== target is u'hooks.py'
25=== modified file 'hooks/hooks.py'
26--- hooks/hooks.py 2013-12-19 22:20:21 +0000
27+++ hooks/hooks.py 2014-01-08 21:09:33 +0000
28@@ -4,12 +4,10 @@
29 import json
30 import subprocess
31 import sys
32-import time
33
34
35 def juju_info(msg):
36 subprocess.check_call(['juju-log', '-l', 'INFO', msg])
37- pass
38
39
40 def _config():
41@@ -51,6 +49,11 @@
42 return os.path.join(config['install_root'], unit)
43
44
45+def _relation_file(config):
46+ relation = os.environ['JUJU_RELATION_ID']
47+ return os.path.join(_service_dir(config), 'juju-relations', relation)
48+
49+
50 def lander_jenkins_relation_joined(config):
51 juju_info("Config: %s" % config)
52 hostname = subprocess.check_output(['unit-get', 'private-address']).strip()
53@@ -61,13 +64,24 @@
54 'port': 8080, # the jenkins charm hardcodes 8080
55 })
56
57+ rfile = _relation_file(config)
58+ rdir = os.path.dirname(rfile)
59+ if not os.path.exists(rdir):
60+ os.mkdir(rdir)
61+ with open(rfile, 'w') as f:
62+ unit = os.environ['JUJU_REMOTE_UNIT'].split('/')[0]
63+ f.write('%s: %s' % (unit, _relation_get('private-address')))
64+
65
66 def lander_jenkins_relation_changed(config):
67- pass
68+ lander_jenkins_relation_joined(config)
69
70
71 def lander_jenkins_relation_broken(config):
72- pass
73+ rfile = _relation_file(config)
74+ juju_info('removing relation file: %s' % rfile)
75+ if os.path.exists(rfile):
76+ os.unlink(rfile)
77
78
79 def jenkins_extension_relation_joined(config):
80@@ -85,6 +99,26 @@
81 juju_info("Config: %s" % config)
82
83
84+def amqp_relation_joined(config):
85+ _relation_set({
86+ 'username': config['amqp-user'],
87+ 'vhost': config['amqp-vhost'],
88+ })
89+
90+
91+def amqp_relation_changed(config):
92+ with open(os.path.join(_service_dir(config), 'amqp_config.py'), 'w') as f:
93+ f.write('# DO NOT EDIT. Generated by lander-jenkins charm hook\n')
94+ f.write('AMQP_USER = "%s"\n' % config['amqp-user'])
95+ f.write('AMQP_VHOST = "%s"\n' % config['amqp-vhost'])
96+ f.write('AMQP_HOST = "%s"\n' % _relation_get('private-address'))
97+ f.write('AMQP_PASSWORD = "%s"\n' % _relation_get('password'))
98+
99+
100+def amqp_relation_broken(config):
101+ os.unlink(os.path.join(_service_dir(config), 'amqp_config.py'))
102+
103+
104 def main():
105 hook = os.path.basename(sys.argv[0])
106 juju_info("Running hook: %s" % hook)
107@@ -105,4 +139,3 @@
108
109 if __name__ == '__main__':
110 exit(main())
111-
112
113=== modified file 'metadata.yaml'
114--- metadata.yaml 2013-12-19 22:20:21 +0000
115+++ metadata.yaml 2014-01-08 21:09:33 +0000
116@@ -9,6 +9,8 @@
117 extension:
118 interface: jenkins-extension
119 scope: container
120+ amqp:
121+ interface: rabbitmq
122 provides:
123 lander-jenkins:
124 interface: lander-jenkins
125
126=== modified file 'templates/jobs/lander_master.xml'
127--- templates/jobs/lander_master.xml 2014-01-08 15:04:30 +0000
128+++ templates/jobs/lander_master.xml 2014-01-08 21:09:33 +0000
129@@ -31,23 +31,29 @@
130 <command><![CDATA[#!/bin/bash
131 set -ex
132
133+ppa_ip=$(grep ppa-django /srv/lander_jenkins/juju-relations/* | awk '{print $NF}' | head -n1)
134+bsb_ip=$(grep bsb-restish /srv/lander_jenkins/juju-relations/* | awk '{print $NF}' | head -n1)
135+
136 # Convert to input file
137 request_parameters=$(echo $request_parameters | sed -e 's/^"//' -e 's/"$//')
138 cat > params.json <<EOF
139 {
140 "request_id": "$request_id",
141+ "progress_trigger": "${JOB_NAME}-${BUILD_NUMBER}",
142+ "ppa_assigner_url": "http://${ppa_ip}:8080",
143+ "bsb_url": "http://${bsb_ip}:8080",
144 "request_parameters": $request_parameters
145 }
146 EOF
147 cat params.json
148
149 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service master --output-file all.json
150-request_parameters=$(echo $request_parameters | sed -e 's/^"//' -e 's/"$//')
151+
152 # Convert to a format that can be passed to the child jobs
153-all_params=`cat all.json`
154-cat > child.json <<EOF
155-"request_parameters": $all_params
156-EOF]]></command>
157+cat > child.params <<EOF
158+request_parameters=$(cat all.json)
159+EOF
160+ ]]></command>
161 </hudson.tasks.Shell>
162 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
163 <configs>
164@@ -59,7 +65,7 @@
165 </configs>
166 <configFactories>
167 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
168- <filePattern>child.json</filePattern>
169+ <filePattern>child.params</filePattern>
170 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
171 </configFactories>
172 <projects>lander_ppa_assigner</projects>
173@@ -97,10 +103,10 @@
174 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service ppa_assigner --output-file all.json --prior-file all.json
175
176 # Convert to a format that can be passed to the child jobs
177-all_params=`cat all.json`
178-cat > child.json <<EOF
179-request_parameters=$all_params
180-EOF]]></command>
181+cat > child.params <<EOF
182+request_parameters=$(cat all.json)
183+EOF
184+ ]]></command>
185 </hudson.tasks.Shell>
186 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
187 <configs>
188@@ -112,7 +118,7 @@
189 </configs>
190 <configFactories>
191 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
192- <filePattern>child.json</filePattern>
193+ <filePattern>child.params</filePattern>
194 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
195 </configFactories>
196 <projects>lander_branch_source_builder</projects>
197@@ -150,10 +156,10 @@
198 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service bsbuilder --output-file all.json --prior-file all.json
199
200 # Convert to a format that can be passed to the child jobs
201-all_params=`cat all.json`
202-cat > child.json <<EOF
203-request_parameters=$all_params
204-EOF]]></command>
205+cat > child.params <<EOF
206+request_parameters=$(cat all.json)
207+EOF
208+ ]]></command>
209 </hudson.tasks.Shell>
210 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
211 <configs>
212@@ -165,7 +171,7 @@
213 </configs>
214 <configFactories>
215 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
216- <filePattern>child.json</filePattern>
217+ <filePattern>child.params</filePattern>
218 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
219 </configFactories>
220 <projects>lander_image_builder</projects>
221@@ -203,10 +209,10 @@
222 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service image_builder --output-file all.json --prior-file all.json
223
224 # Convert to a format that can be passed to the child jobs
225-all_params=`cat all.json`
226-cat > child.json <<EOF
227-request_parameters=$all_params
228-EOF]]></command>
229+cat > child.params <<EOF
230+request_parameters=$(cat all.json)
231+EOF
232+ ]]></command>
233 </hudson.tasks.Shell>
234 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
235 <configs>
236@@ -218,7 +224,7 @@
237 </configs>
238 <configFactories>
239 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
240- <filePattern>child.json</filePattern>
241+ <filePattern>child.params</filePattern>
242 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
243 </configFactories>
244 <projects>lander_test_runner</projects>
245@@ -256,10 +262,10 @@
246 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service test_runner --output-file all.json --prior-file all.json
247
248 # Convert to a format that can be passed to the child jobs
249-all_params=`cat all.json`
250-cat > child.json <<EOF
251-request_parameters=$all_params
252-EOF]]></command>
253+cat > child.params <<EOF
254+request_parameters=$(cat all.json)
255+EOF
256+ ]]></command>
257 </hudson.tasks.Shell>
258 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
259 <configs>
260@@ -271,7 +277,7 @@
261 </configs>
262 <configFactories>
263 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
264- <filePattern>child.json</filePattern>
265+ <filePattern>child.params</filePattern>
266 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
267 </configFactories>
268 <projects>lander_publisher</projects>
269@@ -309,10 +315,10 @@
270 /srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service publisher --output-file all.json --prior-file all.json
271
272 # Convert to a format that can be passed to the child jobs
273-all_params=`cat all.json`
274-cat > child.json <<EOF
275-request_parameters=$all_params
276-EOF]]></command>
277+cat > child.params <<EOF
278+request_parameters=$(cat all.json)
279+EOF
280+ ]]></command>
281 </hudson.tasks.Shell>
282 </builders>
283 <publishers>

Subscribers

People subscribed via source and target branches