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
=== modified file 'config.yaml'
--- config.yaml 2014-01-08 15:04:30 +0000
+++ config.yaml 2014-01-08 21:09:33 +0000
@@ -51,3 +51,13 @@
51 type: string51 type: string
52 default: ""52 default: ""
53 description: Data store tenant name.53 description: Data store tenant name.
54
55# required for rabbitmq-server charm:
56 amqp-user:
57 type: string
58 default: workerbee
59 description: The user to log into the rabbitMQ server.
60 amqp-vhost:
61 type: string
62 default: '/'
63 description: The vhost in the rabbitMQ server.
5464
=== added symlink 'hooks/amqp-relation-broken'
=== target is u'hooks.py'
=== added symlink 'hooks/amqp-relation-changed'
=== target is u'hooks.py'
=== added symlink 'hooks/amqp-relation-joined'
=== target is u'hooks.py'
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2013-12-19 22:20:21 +0000
+++ hooks/hooks.py 2014-01-08 21:09:33 +0000
@@ -4,12 +4,10 @@
4import json4import json
5import subprocess5import subprocess
6import sys6import sys
7import time
87
98
10def juju_info(msg):9def juju_info(msg):
11 subprocess.check_call(['juju-log', '-l', 'INFO', msg])10 subprocess.check_call(['juju-log', '-l', 'INFO', msg])
12 pass
1311
1412
15def _config():13def _config():
@@ -51,6 +49,11 @@
51 return os.path.join(config['install_root'], unit)49 return os.path.join(config['install_root'], unit)
5250
5351
52def _relation_file(config):
53 relation = os.environ['JUJU_RELATION_ID']
54 return os.path.join(_service_dir(config), 'juju-relations', relation)
55
56
54def lander_jenkins_relation_joined(config):57def lander_jenkins_relation_joined(config):
55 juju_info("Config: %s" % config)58 juju_info("Config: %s" % config)
56 hostname = subprocess.check_output(['unit-get', 'private-address']).strip()59 hostname = subprocess.check_output(['unit-get', 'private-address']).strip()
@@ -61,13 +64,24 @@
61 'port': 8080, # the jenkins charm hardcodes 808064 'port': 8080, # the jenkins charm hardcodes 8080
62 })65 })
6366
67 rfile = _relation_file(config)
68 rdir = os.path.dirname(rfile)
69 if not os.path.exists(rdir):
70 os.mkdir(rdir)
71 with open(rfile, 'w') as f:
72 unit = os.environ['JUJU_REMOTE_UNIT'].split('/')[0]
73 f.write('%s: %s' % (unit, _relation_get('private-address')))
74
6475
65def lander_jenkins_relation_changed(config):76def lander_jenkins_relation_changed(config):
66 pass77 lander_jenkins_relation_joined(config)
6778
6879
69def lander_jenkins_relation_broken(config):80def lander_jenkins_relation_broken(config):
70 pass81 rfile = _relation_file(config)
82 juju_info('removing relation file: %s' % rfile)
83 if os.path.exists(rfile):
84 os.unlink(rfile)
7185
7286
73def jenkins_extension_relation_joined(config):87def jenkins_extension_relation_joined(config):
@@ -85,6 +99,26 @@
85 juju_info("Config: %s" % config)99 juju_info("Config: %s" % config)
86100
87101
102def amqp_relation_joined(config):
103 _relation_set({
104 'username': config['amqp-user'],
105 'vhost': config['amqp-vhost'],
106 })
107
108
109def amqp_relation_changed(config):
110 with open(os.path.join(_service_dir(config), 'amqp_config.py'), 'w') as f:
111 f.write('# DO NOT EDIT. Generated by lander-jenkins charm hook\n')
112 f.write('AMQP_USER = "%s"\n' % config['amqp-user'])
113 f.write('AMQP_VHOST = "%s"\n' % config['amqp-vhost'])
114 f.write('AMQP_HOST = "%s"\n' % _relation_get('private-address'))
115 f.write('AMQP_PASSWORD = "%s"\n' % _relation_get('password'))
116
117
118def amqp_relation_broken(config):
119 os.unlink(os.path.join(_service_dir(config), 'amqp_config.py'))
120
121
88def main():122def main():
89 hook = os.path.basename(sys.argv[0])123 hook = os.path.basename(sys.argv[0])
90 juju_info("Running hook: %s" % hook)124 juju_info("Running hook: %s" % hook)
@@ -105,4 +139,3 @@
105139
106if __name__ == '__main__':140if __name__ == '__main__':
107 exit(main())141 exit(main())
108
109142
=== modified file 'metadata.yaml'
--- metadata.yaml 2013-12-19 22:20:21 +0000
+++ metadata.yaml 2014-01-08 21:09:33 +0000
@@ -9,6 +9,8 @@
9 extension:9 extension:
10 interface: jenkins-extension10 interface: jenkins-extension
11 scope: container11 scope: container
12 amqp:
13 interface: rabbitmq
12provides:14provides:
13 lander-jenkins:15 lander-jenkins:
14 interface: lander-jenkins16 interface: lander-jenkins
1517
=== modified file 'templates/jobs/lander_master.xml'
--- templates/jobs/lander_master.xml 2014-01-08 15:04:30 +0000
+++ templates/jobs/lander_master.xml 2014-01-08 21:09:33 +0000
@@ -31,23 +31,29 @@
31 <command><![CDATA[#!/bin/bash31 <command><![CDATA[#!/bin/bash
32set -ex32set -ex
3333
34ppa_ip=$(grep ppa-django /srv/lander_jenkins/juju-relations/* | awk '{print $NF}' | head -n1)
35bsb_ip=$(grep bsb-restish /srv/lander_jenkins/juju-relations/* | awk '{print $NF}' | head -n1)
36
34# Convert to input file37# Convert to input file
35request_parameters=$(echo $request_parameters | sed -e 's/^"//' -e 's/"$//')38request_parameters=$(echo $request_parameters | sed -e 's/^"//' -e 's/"$//')
36cat > params.json <<EOF39cat > params.json <<EOF
37{40{
38 "request_id": "$request_id",41 "request_id": "$request_id",
42 "progress_trigger": "${JOB_NAME}-${BUILD_NUMBER}",
43 "ppa_assigner_url": "http://${ppa_ip}:8080",
44 "bsb_url": "http://${bsb_ip}:8080",
39 "request_parameters": $request_parameters45 "request_parameters": $request_parameters
40}46}
41EOF47EOF
42cat params.json48cat params.json
4349
44/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service master --output-file all.json50/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service master --output-file all.json
45request_parameters=$(echo $request_parameters | sed -e 's/^"//' -e 's/"$//')51
46# Convert to a format that can be passed to the child jobs52# Convert to a format that can be passed to the child jobs
47all_params=`cat all.json`53cat > child.params <<EOF
48cat > child.json <<EOF54request_parameters=$(cat all.json)
49"request_parameters": $all_params55EOF
50EOF]]></command>56 ]]></command>
51 </hudson.tasks.Shell>57 </hudson.tasks.Shell>
52 <hudson.plugins.parameterizedtrigger.TriggerBuilder>58 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
53 <configs>59 <configs>
@@ -59,7 +65,7 @@
59 </configs>65 </configs>
60 <configFactories>66 <configFactories>
61 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>67 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
62 <filePattern>child.json</filePattern>68 <filePattern>child.params</filePattern>
63 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>69 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
64 </configFactories>70 </configFactories>
65 <projects>lander_ppa_assigner</projects>71 <projects>lander_ppa_assigner</projects>
@@ -97,10 +103,10 @@
97/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service ppa_assigner --output-file all.json --prior-file all.json103/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service ppa_assigner --output-file all.json --prior-file all.json
98104
99# Convert to a format that can be passed to the child jobs105# Convert to a format that can be passed to the child jobs
100all_params=`cat all.json`106cat > child.params <<EOF
101cat > child.json <<EOF107request_parameters=$(cat all.json)
102request_parameters=$all_params108EOF
103EOF]]></command>109 ]]></command>
104 </hudson.tasks.Shell>110 </hudson.tasks.Shell>
105 <hudson.plugins.parameterizedtrigger.TriggerBuilder>111 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
106 <configs>112 <configs>
@@ -112,7 +118,7 @@
112 </configs>118 </configs>
113 <configFactories>119 <configFactories>
114 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>120 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
115 <filePattern>child.json</filePattern>121 <filePattern>child.params</filePattern>
116 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>122 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
117 </configFactories>123 </configFactories>
118 <projects>lander_branch_source_builder</projects>124 <projects>lander_branch_source_builder</projects>
@@ -150,10 +156,10 @@
150/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service bsbuilder --output-file all.json --prior-file all.json156/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service bsbuilder --output-file all.json --prior-file all.json
151157
152# Convert to a format that can be passed to the child jobs158# Convert to a format that can be passed to the child jobs
153all_params=`cat all.json`159cat > child.params <<EOF
154cat > child.json <<EOF160request_parameters=$(cat all.json)
155request_parameters=$all_params161EOF
156EOF]]></command>162 ]]></command>
157 </hudson.tasks.Shell>163 </hudson.tasks.Shell>
158 <hudson.plugins.parameterizedtrigger.TriggerBuilder>164 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
159 <configs>165 <configs>
@@ -165,7 +171,7 @@
165 </configs>171 </configs>
166 <configFactories>172 <configFactories>
167 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>173 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
168 <filePattern>child.json</filePattern>174 <filePattern>child.params</filePattern>
169 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>175 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
170 </configFactories>176 </configFactories>
171 <projects>lander_image_builder</projects>177 <projects>lander_image_builder</projects>
@@ -203,10 +209,10 @@
203/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service image_builder --output-file all.json --prior-file all.json209/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service image_builder --output-file all.json --prior-file all.json
204210
205# Convert to a format that can be passed to the child jobs211# Convert to a format that can be passed to the child jobs
206all_params=`cat all.json`212cat > child.params <<EOF
207cat > child.json <<EOF213request_parameters=$(cat all.json)
208request_parameters=$all_params214EOF
209EOF]]></command>215 ]]></command>
210 </hudson.tasks.Shell>216 </hudson.tasks.Shell>
211 <hudson.plugins.parameterizedtrigger.TriggerBuilder>217 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
212 <configs>218 <configs>
@@ -218,7 +224,7 @@
218 </configs>224 </configs>
219 <configFactories>225 <configFactories>
220 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>226 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
221 <filePattern>child.json</filePattern>227 <filePattern>child.params</filePattern>
222 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>228 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
223 </configFactories>229 </configFactories>
224 <projects>lander_test_runner</projects>230 <projects>lander_test_runner</projects>
@@ -256,10 +262,10 @@
256/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service test_runner --output-file all.json --prior-file all.json262/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service test_runner --output-file all.json --prior-file all.json
257263
258# Convert to a format that can be passed to the child jobs264# Convert to a format that can be passed to the child jobs
259all_params=`cat all.json`265cat > child.params <<EOF
260cat > child.json <<EOF266request_parameters=$(cat all.json)
261request_parameters=$all_params267EOF
262EOF]]></command>268 ]]></command>
263 </hudson.tasks.Shell>269 </hudson.tasks.Shell>
264 <hudson.plugins.parameterizedtrigger.TriggerBuilder>270 <hudson.plugins.parameterizedtrigger.TriggerBuilder>
265 <configs>271 <configs>
@@ -271,7 +277,7 @@
271 </configs>277 </configs>
272 <configFactories>278 <configFactories>
273 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>279 <hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
274 <filePattern>child.json</filePattern>280 <filePattern>child.params</filePattern>
275 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>281 </hudson.plugins.parameterizedtrigger.FileBuildParameterFactory>
276 </configFactories>282 </configFactories>
277 <projects>lander_publisher</projects>283 <projects>lander_publisher</projects>
@@ -309,10 +315,10 @@
309/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service publisher --output-file all.json --prior-file all.json315/srv/lander_jenkins/lander/bin/lander_merge_parameters.py --result-file params.json --service publisher --output-file all.json --prior-file all.json
310316
311# Convert to a format that can be passed to the child jobs317# Convert to a format that can be passed to the child jobs
312all_params=`cat all.json`318cat > child.params <<EOF
313cat > child.json <<EOF319request_parameters=$(cat all.json)
314request_parameters=$all_params320EOF
315EOF]]></command>321 ]]></command>
316 </hudson.tasks.Shell>322 </hudson.tasks.Shell>
317 </builders>323 </builders>
318 <publishers>324 <publishers>

Subscribers

People subscribed via source and target branches