Merge ~alejdg/jenkins-agent-charm:fix_master_relation_setup into jenkins-agent-charm:master

Proposed by Alexandre Gomes
Status: Merged
Approved by: Alexandre Gomes
Approved revision: 9a360f34a99e3b26c64b6e133264d5f1879c859d
Merged at revision: ac9b1d1220c1670af0dbb92bde13f1883d66b497
Proposed branch: ~alejdg/jenkins-agent-charm:fix_master_relation_setup
Merge into: jenkins-agent-charm:master
Diff against target: 84 lines (+12/-7)
4 files modified
files/download-slave.sh (+2/-2)
reactive/jenkins_slave.py (+7/-3)
templates/jenkins-slave-default (+1/-1)
tests/unit/test_jenkins_slave.py (+2/-1)
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+394136@code.launchpad.net

Commit message

Make sure secret is not overwritten outside of the relation context

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision ac9b1d1220c1670af0dbb92bde13f1883d66b497

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/files/download-slave.sh b/files/download-slave.sh
index 831f066..dfe1462 100755
--- a/files/download-slave.sh
+++ b/files/download-slave.sh
@@ -29,7 +29,7 @@ if [ -s ${SLAVE_JAR}.new ] && [ -s ${JENKINS_JNLP}.new ]
29then29then
30 mv ${SLAVE_JAR}.new ${SLAVE_JAR}30 mv ${SLAVE_JAR}.new ${SLAVE_JAR}
31 mv ${JENKINS_JNLP}.new ${JENKINS_JNLP}31 mv ${JENKINS_JNLP}.new ${JENKINS_JNLP}
32 exit 032 exit 0
33else33else
34 exit 134 exit 1
35fi35fi
diff --git a/reactive/jenkins_slave.py b/reactive/jenkins_slave.py
index 615084e..be3b256 100644
--- a/reactive/jenkins_slave.py
+++ b/reactive/jenkins_slave.py
@@ -96,7 +96,7 @@ def configure_jenkins_slave():
96 write_default_conf(config.get('master_url'))96 write_default_conf(config.get('master_url'))
97 elif kv.get('url'):97 elif kv.get('url'):
98 status.maintenance("Using url from relation as 'master_url'")98 status.maintenance("Using url from relation as 'master_url'")
99 write_default_conf(kv.get('url'))99 write_default_conf(kv.get('url'), kv.get('secret'))
100 else:100 else:
101 status.maintenance("No 'master_url' set; not configuring slave at this time.")101 status.maintenance("No 'master_url' set; not configuring slave at this time.")
102 status.blocked("requires either slave relation or 'master_url'")102 status.blocked("requires either slave relation or 'master_url'")
@@ -168,6 +168,7 @@ def slave_relation_changed():
168def slave_relation_removed():168def slave_relation_removed():
169 kv = unitdata.kv()169 kv = unitdata.kv()
170 kv.set('url', None)170 kv.set('url', None)
171 kv.set('secret', None)
171 reactive.clear_flag('slave-relation.available')172 reactive.clear_flag('slave-relation.available')
172173
173174
@@ -186,8 +187,9 @@ def slave_relation():
186187
187 url = hookenv.relation_get('url')188 url = hookenv.relation_get('url')
188 if url:189 if url:
189 kv.set('url', url)
190 secret = hookenv.relation_get('secret')190 secret = hookenv.relation_get('secret')
191 kv.set('url', url)
192 kv.set('secret', secret)
191 write_default_conf(url, secret=secret)193 write_default_conf(url, secret=secret)
192 else:194 else:
193 hookenv.log("Master hasn't exported its url yet, exiting...")195 hookenv.log("Master hasn't exported its url yet, exiting...")
@@ -229,7 +231,9 @@ def file_to_units(local_path, unit_path, perms=None, owner='root', group='root')
229 host.write_file(path=unit_path, content=fh.read().encode(), owner=owner, group=group, perms=file_perms)231 host.write_file(path=unit_path, content=fh.read().encode(), owner=owner, group=group, perms=file_perms)
230232
231233
232def write_default_conf(master_url=None, owner='root', group='root', conf_path='/etc/default/jenkins-slave', secret=None):234def write_default_conf(
235 master_url=None, owner='root', group='root', conf_path='/etc/default/jenkins-slave', secret=None
236):
233 templates_dir = os.path.join(hookenv.charm_dir(), 'templates')237 templates_dir = os.path.join(hookenv.charm_dir(), 'templates')
234 slave_host = hookenv.local_unit().replace('/', '-')238 slave_host = hookenv.local_unit().replace('/', '-')
235 templating.render(239 templating.render(
diff --git a/templates/jenkins-slave-default b/templates/jenkins-slave-default
index fcf5d35..b3b2148 100644
--- a/templates/jenkins-slave-default
+++ b/templates/jenkins-slave-default
@@ -65,7 +65,7 @@ JENKINS_JNLP="${JENKINS_HOME}/agent.jnlp"
6565
66# Arguments to pass to jenkins slave on startup66# Arguments to pass to jenkins slave on startup
67{% if secret %}67{% if secret %}
68JENKINS_SLAVE_SECRET="{{ secret 68JENKINS_SLAVE_SECRET="{{ secret }}"
6969
70JENKINS_ARGS="-jnlpUrl file:${JENKINS_JNLP} -secret ${JENKINS_SLAVE_SECRET}"70JENKINS_ARGS="-jnlpUrl file:${JENKINS_JNLP} -secret ${JENKINS_SLAVE_SECRET}"
71{% else %}71{% else %}
diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_slave.py
index d10d787..a0c1677 100644
--- a/tests/unit/test_jenkins_slave.py
+++ b/tests/unit/test_jenkins_slave.py
@@ -290,7 +290,8 @@ class TestSetDefaultConf(unittest.TestCase):
290 config.return_value = {'master_url': ''}290 config.return_value = {'master_url': ''}
291 relation_get.return_value = 'http://10.1.1.1:8080'291 relation_get.return_value = 'http://10.1.1.1:8080'
292 jenkins_slave.slave_relation()292 jenkins_slave.slave_relation()
293 self.assertFalse(relation_get.assert_called_once_with('url'))293 expected = [mock.call('url'), mock.call('secret')]
294 self.assertFalse(relation_get.assert_has_calls(expected))
294 self.assertFalse(clear_flag.assert_called_once_with('jenkins-slave.active'))295 self.assertFalse(clear_flag.assert_called_once_with('jenkins-slave.active'))
295 self.assertFalse(set_flag.assert_called_once_with('slave-relation.configured'))296 self.assertFalse(set_flag.assert_called_once_with('slave-relation.configured'))
296 expected = [297 expected = [

Subscribers

People subscribed via source and target branches