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
diff --git a/reactive/jenkins_slave.py b/reactive/jenkins_slave.py
index 68421be..7bbb1a2 100755
--- a/reactive/jenkins_slave.py
+++ b/reactive/jenkins_slave.py
@@ -125,6 +125,9 @@ def configure_nagios(nagios):
125@reactive.when('jenkins-slave.configured')125@reactive.when('jenkins-slave.configured')
126@reactive.when_not('jenkins-slave.active')126@reactive.when_not('jenkins-slave.active')
127def set_active():127def set_active():
128 config = hookenv.config()
129 kv = unitdata.kv()
130
128 # Startup the jenkins-slave service. This is called in the131 # Startup the jenkins-slave service. This is called in the
129 # install, config-changed and upgrade-charm paths. It needs to be132 # install, config-changed and upgrade-charm paths. It needs to be
130 # tolerant of a running or stopped jenkins-slave.133 # tolerant of a running or stopped jenkins-slave.
@@ -135,8 +138,17 @@ def set_active():
135 status.maintenance('Starting jenkins-slave...')138 status.maintenance('Starting jenkins-slave...')
136 host.service_start('jenkins-slave')139 host.service_start('jenkins-slave')
137140
141 master_url = config.get('master_url')
142 if master_url:
143 status.active('ready - using jenkins {} (master_url)'.format(master_url))
144 elif kv.get('url'):
145 url = kv.get('url')
146 status.active('ready - using jenkins {} (relation)'.format(url))
147 else:
148 status.blocked("set_active() but no jenkins master")
149 return
150
138 reactive.set_flag('jenkins-slave.active')151 reactive.set_flag('jenkins-slave.active')
139 status.active('ready')
140152
141153
142# We can't use interface:jenkins-slave yet as it's not implemented.154# We can't use interface:jenkins-slave yet as it's not implemented.
@@ -158,6 +170,7 @@ def slave_relation_removed():
158@reactive.when_not('slave-relation.configured')170@reactive.when_not('slave-relation.configured')
159def slave_relation():171def slave_relation():
160 status.maintenance('setting up jenkins via slave relation')172 status.maintenance('setting up jenkins via slave relation')
173
161 config = hookenv.config()174 config = hookenv.config()
162 kv = unitdata.kv()175 kv = unitdata.kv()
163176
diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_slave.py
index efcdb7f..3ef3484 100644
--- a/tests/unit/test_jenkins_slave.py
+++ b/tests/unit/test_jenkins_slave.py
@@ -231,6 +231,23 @@ class TestSetDefaultConf(unittest.TestCase):
231 self.assertFalse(service_start.assert_called_once_with('jenkins-slave'))231 self.assertFalse(service_start.assert_called_once_with('jenkins-slave'))
232 self.assertFalse(service_restart.assert_not_called())232 self.assertFalse(service_restart.assert_not_called())
233233
234 @mock.patch('charms.reactive.set_flag')
235 @mock.patch('charmhelpers.core.hookenv.config')
236 @mock.patch('charmhelpers.core.unitdata.kv')
237 @mock.patch('charmhelpers.core.host.service_running')
238 @mock.patch('charmhelpers.core.host.service_start')
239 def test_set_active_master_url_or_relation(self, service_start, service_running, unitdata_kv, config, set_flag):
240 service_running.return_value = False
241 config.return_value = {'master_url': 'http://ext-jenkins-be.internal:8080'}
242 jenkins_slave.set_active()
243 status.active.assert_called_once_with('ready - using jenkins http://ext-jenkins-be.internal:8080 (master_url)')
244
245 config.return_value = {}
246 unitdata_kv.return_value = {'url': 'http://my-jenkins-be.internal:8080'}
247 status.active.reset_mock()
248 jenkins_slave.set_active()
249 status.active.assert_called_once_with('ready - using jenkins http://my-jenkins-be.internal:8080 (relation)')
250
234 @mock.patch('charms.reactive.clear_flag')251 @mock.patch('charms.reactive.clear_flag')
235 @mock.patch('charms.reactive.set_flag')252 @mock.patch('charms.reactive.set_flag')
236 def test_hook_slave_relation_changed_flags(self, set_flag, clear_flag):253 def test_hook_slave_relation_changed_flags(self, set_flag, clear_flag):

Subscribers

People subscribed via source and target branches