Merge lp:~axino/charm-helpers/systemd into lp:charm-helpers

Proposed by Junien F
Status: Merged
Merged at revision: 615
Proposed branch: lp:~axino/charm-helpers/systemd
Merge into: lp:charm-helpers
Diff against target: 96 lines (+36/-8)
2 files modified
charmhelpers/contrib/charmsupport/nrpe.py (+18/-8)
tests/contrib/charmsupport/test_nrpe.py (+18/-0)
To merge this branch: bzr merge lp:~axino/charm-helpers/systemd
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+301468@code.launchpad.net

Description of the change

[axino] nrpe: make add_init_service_checks support systemd

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good. Having a hardcoded list of services known to fail is bogus, but that doesn't need to be fixed here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/charmsupport/nrpe.py'
--- charmhelpers/contrib/charmsupport/nrpe.py 2016-07-06 14:41:05 +0000
+++ charmhelpers/contrib/charmsupport/nrpe.py 2016-07-29 10:25:11 +0000
@@ -38,6 +38,7 @@
38)38)
3939
40from charmhelpers.core.host import service40from charmhelpers.core.host import service
41from charmhelpers.core import host
4142
42# This module adds compatibility with the nrpe-external-master and plain nrpe43# This module adds compatibility with the nrpe-external-master and plain nrpe
43# subordinate charms. To use it in your charm:44# subordinate charms. To use it in your charm:
@@ -332,16 +333,25 @@
332 :param str unit_name: Unit name to use in check description333 :param str unit_name: Unit name to use in check description
333 """334 """
334 for svc in services:335 for svc in services:
336 # Don't add a check for these services from neutron-gateway
337 if svc in ['ext-port', 'os-charm-phy-nic-mtu']:
338 next
339
335 upstart_init = '/etc/init/%s.conf' % svc340 upstart_init = '/etc/init/%s.conf' % svc
336 sysv_init = '/etc/init.d/%s' % svc341 sysv_init = '/etc/init.d/%s' % svc
337 if os.path.exists(upstart_init):342
338 # Don't add a check for these services from neutron-gateway343 if host.init_is_systemd():
339 if svc not in ['ext-port', 'os-charm-phy-nic-mtu']:344 nrpe.add_check(
340 nrpe.add_check(345 shortname=svc,
341 shortname=svc,346 description='process check {%s}' % unit_name,
342 description='process check {%s}' % unit_name,347 check_cmd='check_systemd.py %s' % svc
343 check_cmd='check_upstart_job %s' % svc348 )
344 )349 elif os.path.exists(upstart_init):
350 nrpe.add_check(
351 shortname=svc,
352 description='process check {%s}' % unit_name,
353 check_cmd='check_upstart_job %s' % svc
354 )
345 elif os.path.exists(sysv_init):355 elif os.path.exists(sysv_init):
346 cronpath = '/etc/cron.d/nagios-service-check-%s' % svc356 cronpath = '/etc/cron.d/nagios-service-check-%s' % svc
347 cron_file = ('*/5 * * * * root '357 cron_file = ('*/5 * * * * root '
348358
=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
--- tests/contrib/charmsupport/test_nrpe.py 2016-01-06 12:29:13 +0000
+++ tests/contrib/charmsupport/test_nrpe.py 2016-07-29 10:25:11 +0000
@@ -6,6 +6,7 @@
6from mock import patch, call6from mock import patch, call
77
8from charmhelpers.contrib.charmsupport import nrpe8from charmhelpers.contrib.charmsupport import nrpe
9from charmhelpers.core import host
910
1011
11class NRPEBaseTestCase(TestCase):12class NRPEBaseTestCase(TestCase):
@@ -26,6 +27,7 @@
26 'relation_set': {'object': nrpe},27 'relation_set': {'object': nrpe},
27 'relations_of_type': {'object': nrpe},28 'relations_of_type': {'object': nrpe},
28 'service': {'object': nrpe},29 'service': {'object': nrpe},
30 'init_is_systemd': {'object': host},
29 }31 }
3032
31 def setUp(self):33 def setUp(self):
@@ -298,10 +300,14 @@
298 '/usr/lib/nagios/plugins/check_upstart_job',300 '/usr/lib/nagios/plugins/check_upstart_job',
299 '/etc/init.d/haproxy',301 '/etc/init.d/haproxy',
300 '/usr/lib/nagios/plugins/check_status_file.py',302 '/usr/lib/nagios/plugins/check_status_file.py',
303 '/usr/lib/nagios/plugins/check_systemd.py'
301 ]304 ]
302 return init_file in files305 return init_file in files
303306
304 self.patched['exists'].side_effect = _exists307 self.patched['exists'].side_effect = _exists
308
309 # Test without systemd
310 self.patched['init_is_systemd'].return_value = False
305 bill = nrpe.NRPE()311 bill = nrpe.NRPE()
306 services = ['apache2', 'haproxy']312 services = ['apache2', 'haproxy']
307 nrpe.add_init_service_checks(bill, services, 'testunit')313 nrpe.add_init_service_checks(bill, services, 'testunit')
@@ -314,3 +320,15 @@
314 self.assertEqual(bill.checks[0].check_cmd, expect_cmds['apache2'])320 self.assertEqual(bill.checks[0].check_cmd, expect_cmds['apache2'])
315 self.assertEqual(bill.checks[1].shortname, 'haproxy')321 self.assertEqual(bill.checks[1].shortname, 'haproxy')
316 self.assertEqual(bill.checks[1].check_cmd, expect_cmds['haproxy'])322 self.assertEqual(bill.checks[1].check_cmd, expect_cmds['haproxy'])
323
324 # Test with systemd
325 self.patched['init_is_systemd'].return_value = True
326 nrpe.add_init_service_checks(bill, services, 'testunit')
327 expect_cmds = {
328 'apache2': '/usr/lib/nagios/plugins/check_systemd.py apache2',
329 'haproxy': '/usr/lib/nagios/plugins/check_systemd.py haproxy',
330 }
331 self.assertEqual(bill.checks[2].shortname, 'apache2')
332 self.assertEqual(bill.checks[2].check_cmd, expect_cmds['apache2'])
333 self.assertEqual(bill.checks[3].shortname, 'haproxy')
334 self.assertEqual(bill.checks[3].check_cmd, expect_cmds['haproxy'])

Subscribers

People subscribed via source and target branches