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
1=== modified file 'charmhelpers/contrib/charmsupport/nrpe.py'
2--- charmhelpers/contrib/charmsupport/nrpe.py 2016-07-06 14:41:05 +0000
3+++ charmhelpers/contrib/charmsupport/nrpe.py 2016-07-29 10:25:11 +0000
4@@ -38,6 +38,7 @@
5 )
6
7 from charmhelpers.core.host import service
8+from charmhelpers.core import host
9
10 # This module adds compatibility with the nrpe-external-master and plain nrpe
11 # subordinate charms. To use it in your charm:
12@@ -332,16 +333,25 @@
13 :param str unit_name: Unit name to use in check description
14 """
15 for svc in services:
16+ # Don't add a check for these services from neutron-gateway
17+ if svc in ['ext-port', 'os-charm-phy-nic-mtu']:
18+ next
19+
20 upstart_init = '/etc/init/%s.conf' % svc
21 sysv_init = '/etc/init.d/%s' % svc
22- if os.path.exists(upstart_init):
23- # Don't add a check for these services from neutron-gateway
24- if svc not in ['ext-port', 'os-charm-phy-nic-mtu']:
25- nrpe.add_check(
26- shortname=svc,
27- description='process check {%s}' % unit_name,
28- check_cmd='check_upstart_job %s' % svc
29- )
30+
31+ if host.init_is_systemd():
32+ nrpe.add_check(
33+ shortname=svc,
34+ description='process check {%s}' % unit_name,
35+ check_cmd='check_systemd.py %s' % svc
36+ )
37+ elif os.path.exists(upstart_init):
38+ nrpe.add_check(
39+ shortname=svc,
40+ description='process check {%s}' % unit_name,
41+ check_cmd='check_upstart_job %s' % svc
42+ )
43 elif os.path.exists(sysv_init):
44 cronpath = '/etc/cron.d/nagios-service-check-%s' % svc
45 cron_file = ('*/5 * * * * root '
46
47=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
48--- tests/contrib/charmsupport/test_nrpe.py 2016-01-06 12:29:13 +0000
49+++ tests/contrib/charmsupport/test_nrpe.py 2016-07-29 10:25:11 +0000
50@@ -6,6 +6,7 @@
51 from mock import patch, call
52
53 from charmhelpers.contrib.charmsupport import nrpe
54+from charmhelpers.core import host
55
56
57 class NRPEBaseTestCase(TestCase):
58@@ -26,6 +27,7 @@
59 'relation_set': {'object': nrpe},
60 'relations_of_type': {'object': nrpe},
61 'service': {'object': nrpe},
62+ 'init_is_systemd': {'object': host},
63 }
64
65 def setUp(self):
66@@ -298,10 +300,14 @@
67 '/usr/lib/nagios/plugins/check_upstart_job',
68 '/etc/init.d/haproxy',
69 '/usr/lib/nagios/plugins/check_status_file.py',
70+ '/usr/lib/nagios/plugins/check_systemd.py'
71 ]
72 return init_file in files
73
74 self.patched['exists'].side_effect = _exists
75+
76+ # Test without systemd
77+ self.patched['init_is_systemd'].return_value = False
78 bill = nrpe.NRPE()
79 services = ['apache2', 'haproxy']
80 nrpe.add_init_service_checks(bill, services, 'testunit')
81@@ -314,3 +320,15 @@
82 self.assertEqual(bill.checks[0].check_cmd, expect_cmds['apache2'])
83 self.assertEqual(bill.checks[1].shortname, 'haproxy')
84 self.assertEqual(bill.checks[1].check_cmd, expect_cmds['haproxy'])
85+
86+ # Test with systemd
87+ self.patched['init_is_systemd'].return_value = True
88+ nrpe.add_init_service_checks(bill, services, 'testunit')
89+ expect_cmds = {
90+ 'apache2': '/usr/lib/nagios/plugins/check_systemd.py apache2',
91+ 'haproxy': '/usr/lib/nagios/plugins/check_systemd.py haproxy',
92+ }
93+ self.assertEqual(bill.checks[2].shortname, 'apache2')
94+ self.assertEqual(bill.checks[2].check_cmd, expect_cmds['apache2'])
95+ self.assertEqual(bill.checks[3].shortname, 'haproxy')
96+ self.assertEqual(bill.checks[3].check_cmd, expect_cmds['haproxy'])

Subscribers

People subscribed via source and target branches