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

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 46bef5a2f27d5472df1d957999992fcfb0f96165
Merged at revision: 3d304ebbb02d47f0a3cf1b70fa534052ea6c545d
Proposed branch: ~hloeung/jenkins-agent-charm:master
Merge into: jenkins-agent-charm:master
Diff against target: 61 lines (+22/-2)
2 files modified
reactive/jenkins_slave.py (+2/-1)
tests/unit/test_jenkins_slave.py (+20/-1)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+365384@code.launchpad.net

Commit message

Add unit tests for configure_nagios()

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 :

I think these assertFalse calls don't do what you think they do. The assert methods raise an AssertionError exception when they fail; they do not return True/False.

review: Needs Fixing
Revision history for this message
Stuart Bishop (stub) wrote :

Yup. Missed one, but easy fix.

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

Change successfully merged at revision 3d304ebbb02d47f0a3cf1b70fa534052ea6c545d

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 1d5c545..21d174c 100755
3--- a/reactive/jenkins_slave.py
4+++ b/reactive/jenkins_slave.py
5@@ -12,6 +12,7 @@ def upgrade_charm():
6 status.maintenance('forcing reconfiguration on upgrade-charm')
7 reactive.clear_flag('jenkins-slave.active')
8 reactive.clear_flag('jenkins-slave.installed')
9+ reactive.clear_flag('nagios-nrpe.configured')
10
11
12 @reactive.when_not('jenkins-slave.installed')
13@@ -111,8 +112,8 @@ def blocked_on_jenkins_url():
14
15
16 @reactive.when('jenkins-slave.configured')
17-@reactive.when('nrpe-external-master.available')
18 @reactive.when('jenkins-slave.active')
19+@reactive.when('nrpe-external-master.available')
20 @reactive.when_not('nagios-nrpe.configured')
21 def configure_nagios(nagios):
22 status.maintenance('setting up NRPE checks')
23diff --git a/tests/unit/test_jenkins_slave.py b/tests/unit/test_jenkins_slave.py
24index 9793742..5f8742a 100644
25--- a/tests/unit/test_jenkins_slave.py
26+++ b/tests/unit/test_jenkins_slave.py
27@@ -83,7 +83,9 @@ class TestSetDefaultConf(unittest.TestCase):
28 '''Test correct flags set via upgrade-charm hook'''
29 jenkins_slave.upgrade_charm()
30 self.assertFalse(status.maintenance.assert_called())
31- expected = [mock.call('jenkins-slave.active'), mock.call('jenkins-slave.installed')]
32+ expected = [mock.call('jenkins-slave.active'),
33+ mock.call('jenkins-slave.installed'),
34+ mock.call('nagios-nrpe.configured')]
35 self.assertFalse(clear_flag.assert_has_calls(expected, any_order=True))
36
37 @mock.patch('charms.reactive.clear_flag')
38@@ -299,6 +301,23 @@ class TestSetDefaultConf(unittest.TestCase):
39 jenkins_slave.slave_relation()
40 self.assertFalse(clear_flag.assert_not_called())
41
42+ @mock.patch('charms.reactive.set_flag')
43+ @mock.patch('charmhelpers.contrib.charmsupport.nrpe.get_nagios_hostname')
44+ @mock.patch('charmhelpers.contrib.charmsupport.nrpe.NRPE')
45+ def test_configure_nagios(self, nrpe, get_nagios_hostname, set_flag):
46+ get_nagios_hostname.return_value = 'some-host.local'
47+ nrpe_instance_mock = nrpe(get_nagios_hostname(), primary=True)
48+ jenkins_slave.configure_nagios(None)
49+ status.maintenance.assert_called()
50+ want = [mock.call('jenkins_slave_ps', 'Jenkins Slave Process',
51+ '/usr/lib/nagios/plugins/check_procs -c 1:1 -a slave.jar')]
52+ nrpe_instance_mock.add_check.assert_has_calls(want, any_order=True)
53+
54+ nrpe_instance_mock.write.assert_called()
55+
56+ want = [mock.call('nagios-nrpe.configured')]
57+ set_flag.assert_has_calls(want, any_order=True)
58+
59 def test_write_default_conf_update(self):
60 jenkins_slave.write_default_conf('http://10.1.1.1:8080', self.user, self.group, self.conf_file)
61 self.assertTrue(conf_match(self.conf_file, 'JENKINS_URL', 'http://10.1.1.1:8080'))

Subscribers

People subscribed via source and target branches