Merge lp:~thedac/charm-helpers/active-stopped-check into lp:charm-helpers

Proposed by David Ames
Status: Merged
Merged at revision: 572
Proposed branch: lp:~thedac/charm-helpers/active-stopped-check
Merge into: lp:charm-helpers
Diff against target: 51 lines (+10/-1)
2 files modified
charmhelpers/core/host.py (+4/-0)
tests/core/test_host.py (+6/-1)
To merge this branch: bzr merge lp:~thedac/charm-helpers/active-stopped-check
Reviewer Review Type Date Requested Status
Alex Kavanagh Approve
charmers Pending
Review via email: mp+294665@code.launchpad.net

Description of the change

service_running is returning false positives. Actively check for stopped messages and return False.

Serivces are actually down:
# initctl list |grep cinder-
cinder-volume stop/waiting
cinder-api stop/waiting
cinder-scheduler stop/waiting

But fall through systemv check shows them up:
# service --status-all 2>&1|grep cinder-
 [ + ] cinder-api
 [ + ] cinder-scheduler
 [ + ] cinder-volume

To post a comment you must log in.
573. By David Ames

Enhance the comment

Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

Looks good to me.

review: Approve
574. By David Ames

Make service_running unit tests more robust

Revision history for this message
Alex Kavanagh (ajkavanagh) wrote :

Reviewed added tests. Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2016-04-08 15:09:08 +0000
3+++ charmhelpers/core/host.py 2016-05-13 16:30:32 +0000
4@@ -152,6 +152,10 @@
5 if ("start/running" in output or "is running" in output or
6 "up and running" in output):
7 return True
8+ # Actively check for upstart stopped message(s) as the fall through
9+ # SystemV check can return false positives
10+ if ("stop/waiting" in output):
11+ return False
12 # Check System V scripts init script return codes
13 if service_name in systemv_services_running():
14 return True
15
16=== modified file 'tests/core/test_host.py'
17--- tests/core/test_host.py 2016-04-08 13:55:23 +0000
18+++ tests/core/test_host.py 2016-05-13 16:30:32 +0000
19@@ -467,12 +467,15 @@
20 call('restart', service_name)
21 ])
22
23+ @patch.object(host, 'systemv_services_running')
24 @patch.object(host, 'init_is_systemd')
25 @patch('subprocess.check_output')
26- def test_service_running_on_stopped_service(self, check_output, systemd):
27+ def test_service_running_on_stopped_service(self, check_output, systemd,
28+ systemv_services_running):
29 systemd.return_value = False
30 check_output.return_value = b'foo stop/waiting'
31 self.assertFalse(host.service_running('foo'))
32+ self.assertFalse(systemv_services_running.called)
33
34 @patch.object(host, 'init_is_systemd')
35 @patch('subprocess.check_output')
36@@ -505,6 +508,7 @@
37 check_output.return_value = b' * Unhelpfull guff, thanks a lot rabbit'
38 systemv_services_running.return_value = [u'udev', u'rabbitmq-server']
39 self.assertTrue(host.service_running('rabbitmq-server'))
40+ self.assertTrue(systemv_services_running.called)
41
42 @patch.object(host, 'systemv_services_running')
43 @patch.object(host, 'init_is_systemd')
44@@ -515,6 +519,7 @@
45 check_output.return_value = b' * Unhelpfull guff, thanks a lot rabbit'
46 systemv_services_running.return_value = [u'udev', u'rabbitmq-server']
47 self.assertFalse(host.service_running('keystone'))
48+ self.assertTrue(systemv_services_running.called)
49
50 @patch('subprocess.check_output')
51 def test_systemv_services_running(self, check_output):

Subscribers

People subscribed via source and target branches