Merge lp:~fginther/charms/trusty/jenkaas-slave/configure-slave into lp:~canonical-ci-engineering/charms/trusty/jenkaas-slave/trunk

Proposed by Francis Ginther
Status: Merged
Approved by: Francis Ginther
Approved revision: 6
Merged at revision: 4
Proposed branch: lp:~fginther/charms/trusty/jenkaas-slave/configure-slave
Merge into: lp:~canonical-ci-engineering/charms/trusty/jenkaas-slave/trunk
Diff against target: 52 lines (+25/-0)
2 files modified
hooks/actions.py (+24/-0)
hooks/services.py (+1/-0)
To merge this branch: bzr merge lp:~fginther/charms/trusty/jenkaas-slave/configure-slave
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+262375@code.launchpad.net

Commit message

Configure the upstart config files for the slave service to connect to the jenkaas master.

Description of the change

Configure the upstart config files for the slave service to connect to the jenkaas master.

The master charm still needs to be updated to configure the slave so that it can actually connect.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Looks good. I didn't know you could use the comma in a with block, neato!

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

> Looks good. I didn't know you could use the comma in a with block, neato!

Yep, it saves having to do a nested indent with a second 'with'.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/actions.py'
2--- hooks/actions.py 2015-06-16 19:02:24 +0000
3+++ hooks/actions.py 2015-06-18 18:10:39 +0000
4@@ -1,6 +1,8 @@
5 import glob
6 import os
7+import shutil
8 import subprocess
9+import tempfile
10
11 from charmhelpers import fetch
12 from charmhelpers.core import hookenv
13@@ -44,5 +46,27 @@
14 subprocess.check_call(['dpkg', '-i', package])
15
16
17+def configure_slave(service_name):
18+ hookenv.log('Configuring the slave')
19+ unit_name = hookenv.local_unit().replace('/', '-')
20+ master_url = 'http://{}:8080/'.format(
21+ hookenv.relation_get('master-address'))
22+ hookenv.log('Configuring {} to connect to {}'.format(
23+ unit_name, master_url))
24+
25+ config_path = '/etc/default/jenkins-slave'
26+ _unused, temp_path = tempfile.mkstemp()
27+ with open(config_path) as in_file, open(temp_path, 'w') as out_file:
28+ for line in in_file:
29+ if 'JENKINS_HOSTNAME=' in line:
30+ line = 'JENKINS_HOSTNAME={}\n'.format(unit_name)
31+ if 'JENKINS_URL=' in line:
32+ line = 'JENKINS_URL={}\n'.format(master_url)
33+ out_file.write(line)
34+ shutil.move(temp_path, config_path)
35+ # Set the file permissions to their original value
36+ os.chmod(config_path, 0o644)
37+
38+
39 def log_start(service_name):
40 hookenv.log('Starting service {}'.format(SERVICE_NAME))
41
42=== modified file 'hooks/services.py'
43--- hooks/services.py 2015-06-17 13:34:28 +0000
44+++ hooks/services.py 2015-06-18 18:10:39 +0000
45@@ -40,6 +40,7 @@
46 actions.basenode,
47 actions.install_service_dependencies,
48 actions.install_service_packages,
49+ actions.configure_slave,
50 actions.log_start,
51 ],
52 },

Subscribers

People subscribed via source and target branches