Merge ~hloeung/jenkins-agent-charm:master into jenkins-agent-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 256e606f9ee52ad291aa9942e02095f5ee9f9104
Merged at revision: 625fa31b6ed259ed3fc0e84afa091fa2aa05c16a
Proposed branch: ~hloeung/jenkins-agent-charm:master
Merge into: jenkins-agent-charm:master
Diff against target: 69 lines (+31/-1)
2 files modified
reactive/jenkins_slave.py (+14/-1)
tests/unit/test_jenkins_slave.py (+17/-0)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Haw Loeung Needs Resubmitting
Canonical IS Reviewers Pending
Review via email: mp+371237@code.launchpad.net

Commit message

Update status to show which jenkins master is being used

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
Stuart Bishop (stub) wrote :

Looks OK, but the implementation will fail outside of relation hooks per inline comment.

review: Needs Fixing
Revision history for this message
Haw Loeung (hloeung) :
Revision history for this message
Haw Loeung (hloeung) :
review: Needs Resubmitting
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

You might have a few unneeded mocks per inline comments, which can be removed if that is the case.

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

Change successfully merged at revision 625fa31b6ed259ed3fc0e84afa091fa2aa05c16a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/jenkins_slave.py b/reactive/jenkins_slave.py
2index 68421be..7bbb1a2 100755
3--- a/reactive/jenkins_slave.py
4+++ b/reactive/jenkins_slave.py
5@@ -125,6 +125,9 @@ def configure_nagios(nagios):
6 @reactive.when('jenkins-slave.configured')
7 @reactive.when_not('jenkins-slave.active')
8 def set_active():
9+ config = hookenv.config()
10+ kv = unitdata.kv()
11+
12 # Startup the jenkins-slave service. This is called in the
13 # install, config-changed and upgrade-charm paths. It needs to be
14 # tolerant of a running or stopped jenkins-slave.
15@@ -135,8 +138,17 @@ def set_active():
16 status.maintenance('Starting jenkins-slave...')
17 host.service_start('jenkins-slave')
18
19+ master_url = config.get('master_url')
20+ if master_url:
21+ status.active('ready - using jenkins {} (master_url)'.format(master_url))
22+ elif kv.get('url'):
23+ url = kv.get('url')
24+ status.active('ready - using jenkins {} (relation)'.format(url))
25+ else:
26+ status.blocked("set_active() but no jenkins master")
27+ return
28+
29 reactive.set_flag('jenkins-slave.active')
30- status.active('ready')
31
32
33 # We can't use interface:jenkins-slave yet as it's not implemented.
34@@ -158,6 +170,7 @@ def slave_relation_removed():
35 @reactive.when_not('slave-relation.configured')
36 def slave_relation():
37 status.maintenance('setting up jenkins via slave relation')
38+
39 config = hookenv.config()
40 kv = unitdata.kv()
41
42diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_slave.py
43index efcdb7f..3ef3484 100644
44--- a/tests/unit/test_jenkins_slave.py
45+++ b/tests/unit/test_jenkins_slave.py
46@@ -231,6 +231,23 @@ class TestSetDefaultConf(unittest.TestCase):
47 self.assertFalse(service_start.assert_called_once_with('jenkins-slave'))
48 self.assertFalse(service_restart.assert_not_called())
49
50+ @mock.patch('charms.reactive.set_flag')
51+ @mock.patch('charmhelpers.core.hookenv.config')
52+ @mock.patch('charmhelpers.core.unitdata.kv')
53+ @mock.patch('charmhelpers.core.host.service_running')
54+ @mock.patch('charmhelpers.core.host.service_start')
55+ def test_set_active_master_url_or_relation(self, service_start, service_running, unitdata_kv, config, set_flag):
56+ service_running.return_value = False
57+ config.return_value = {'master_url': 'http://ext-jenkins-be.internal:8080'}
58+ jenkins_slave.set_active()
59+ status.active.assert_called_once_with('ready - using jenkins http://ext-jenkins-be.internal:8080 (master_url)')
60+
61+ config.return_value = {}
62+ unitdata_kv.return_value = {'url': 'http://my-jenkins-be.internal:8080'}
63+ status.active.reset_mock()
64+ jenkins_slave.set_active()
65+ status.active.assert_called_once_with('ready - using jenkins http://my-jenkins-be.internal:8080 (relation)')
66+
67 @mock.patch('charms.reactive.clear_flag')
68 @mock.patch('charms.reactive.set_flag')
69 def test_hook_slave_relation_changed_flags(self, set_flag, clear_flag):

Subscribers

People subscribed via source and target branches