Merge lp:~james-page/charm-helpers/systemd-support into lp:charm-helpers

Proposed by James Page
Status: Merged
Merged at revision: 513
Proposed branch: lp:~james-page/charm-helpers/systemd-support
Merge into: lp:charm-helpers
Diff against target: 414 lines (+140/-36)
3 files modified
charmhelpers/core/host.py (+34/-17)
tests/contrib/charmsupport/test_nrpe.py (+3/-3)
tests/core/test_host.py (+103/-16)
To merge this branch: bzr merge lp:~james-page/charm-helpers/systemd-support
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Adam Collard (community) Needs Fixing
Review via email: mp+281742@code.launchpad.net
To post a comment you must log in.
516. By James Page

Drop else for System ValueError raise.

517. By James Page

Tweak

Revision history for this message
Adam Collard (adam-collard) wrote :

First pass, several cleanups needed

review: Needs Fixing
518. By James Page

Feedback from review

519. By James Page

optimize is systemd

Revision history for this message
Liam Young (gnuoy) wrote :

approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/core/host.py'
--- charmhelpers/core/host.py 2015-11-27 20:57:05 +0000
+++ charmhelpers/core/host.py 2016-01-06 14:04:36 +0000
@@ -72,7 +72,9 @@
72 stopped = service_stop(service_name)72 stopped = service_stop(service_name)
73 upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))73 upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))
74 sysv_file = os.path.join(initd_dir, service_name)74 sysv_file = os.path.join(initd_dir, service_name)
75 if os.path.exists(upstart_file):75 if init_is_systemd():
76 service('disable', service_name)
77 elif os.path.exists(upstart_file):
76 override_path = os.path.join(78 override_path = os.path.join(
77 init_dir, '{}.override'.format(service_name))79 init_dir, '{}.override'.format(service_name))
78 with open(override_path, 'w') as fh:80 with open(override_path, 'w') as fh:
@@ -80,9 +82,9 @@
80 elif os.path.exists(sysv_file):82 elif os.path.exists(sysv_file):
81 subprocess.check_call(["update-rc.d", service_name, "disable"])83 subprocess.check_call(["update-rc.d", service_name, "disable"])
82 else:84 else:
83 # XXX: Support SystemD too
84 raise ValueError(85 raise ValueError(
85 "Unable to detect {0} as either Upstart {1} or SysV {2}".format(86 "Unable to detect {0} as SystemD, Upstart {1} or"
87 " SysV {2}".format(
86 service_name, upstart_file, sysv_file))88 service_name, upstart_file, sysv_file))
87 return stopped89 return stopped
8890
@@ -94,7 +96,9 @@
94 Reenable starting again at boot. Start the service"""96 Reenable starting again at boot. Start the service"""
95 upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))97 upstart_file = os.path.join(init_dir, "{}.conf".format(service_name))
96 sysv_file = os.path.join(initd_dir, service_name)98 sysv_file = os.path.join(initd_dir, service_name)
97 if os.path.exists(upstart_file):99 if init_is_systemd():
100 service('enable', service_name)
101 elif os.path.exists(upstart_file):
98 override_path = os.path.join(102 override_path = os.path.join(
99 init_dir, '{}.override'.format(service_name))103 init_dir, '{}.override'.format(service_name))
100 if os.path.exists(override_path):104 if os.path.exists(override_path):
@@ -102,9 +106,9 @@
102 elif os.path.exists(sysv_file):106 elif os.path.exists(sysv_file):
103 subprocess.check_call(["update-rc.d", service_name, "enable"])107 subprocess.check_call(["update-rc.d", service_name, "enable"])
104 else:108 else:
105 # XXX: Support SystemD too
106 raise ValueError(109 raise ValueError(
107 "Unable to detect {0} as either Upstart {1} or SysV {2}".format(110 "Unable to detect {0} as SystemD, Upstart {1} or"
111 " SysV {2}".format(
108 service_name, upstart_file, sysv_file))112 service_name, upstart_file, sysv_file))
109113
110 started = service_running(service_name)114 started = service_running(service_name)
@@ -115,23 +119,29 @@
115119
116def service(action, service_name):120def service(action, service_name):
117 """Control a system service"""121 """Control a system service"""
118 cmd = ['service', service_name, action]122 if init_is_systemd():
123 cmd = ['systemctl', action, service_name]
124 else:
125 cmd = ['service', service_name, action]
119 return subprocess.call(cmd) == 0126 return subprocess.call(cmd) == 0
120127
121128
122def service_running(service):129def service_running(service_name):
123 """Determine whether a system service is running"""130 """Determine whether a system service is running"""
124 try:131 if init_is_systemd():
125 output = subprocess.check_output(132 return service('is-active', service_name)
126 ['service', service, 'status'],
127 stderr=subprocess.STDOUT).decode('UTF-8')
128 except subprocess.CalledProcessError:
129 return False
130 else:133 else:
131 if ("start/running" in output or "is running" in output):134 try:
132 return True135 output = subprocess.check_output(
133 else:136 ['service', service_name, 'status'],
137 stderr=subprocess.STDOUT).decode('UTF-8')
138 except subprocess.CalledProcessError:
134 return False139 return False
140 else:
141 if ("start/running" in output or "is running" in output):
142 return True
143 else:
144 return False
135145
136146
137def service_available(service_name):147def service_available(service_name):
@@ -146,6 +156,13 @@
146 return True156 return True
147157
148158
159SYSTEMD_SYSTEM = '/run/systemd/system'
160
161
162def init_is_systemd():
163 return os.path.isdir(SYSTEMD_SYSTEM)
164
165
149def adduser(username, password=None, shell='/bin/bash', system_user=False,166def adduser(username, password=None, shell='/bin/bash', system_user=False,
150 primary_group=None, secondary_groups=None):167 primary_group=None, secondary_groups=None):
151 """168 """
152169
=== modified file 'tests/contrib/charmsupport/test_nrpe.py'
--- tests/contrib/charmsupport/test_nrpe.py 2015-10-29 23:52:26 +0000
+++ tests/contrib/charmsupport/test_nrpe.py 2016-01-06 14:04:36 +0000
@@ -25,6 +25,7 @@
25 'relation_ids': {'object': nrpe},25 'relation_ids': {'object': nrpe},
26 'relation_set': {'object': nrpe},26 'relation_set': {'object': nrpe},
27 'relations_of_type': {'object': nrpe},27 'relations_of_type': {'object': nrpe},
28 'service': {'object': nrpe},
28 }29 }
2930
30 def setUp(self):31 def setUp(self):
@@ -108,10 +109,9 @@
108109
109 self.assertEqual(None, checker.write())110 self.assertEqual(None, checker.write())
110111
111 expected = ['service', 'nagios-nrpe-server', 'restart']112 self.patched['service'].assert_called_with('restart', 'nagios-nrpe-server')
112 self.assertEqual(expected, self.patched['call'].call_args[0][0])
113 self.check_call_counts(config=1, getpwnam=1, getgrnam=1,113 self.check_call_counts(config=1, getpwnam=1, getgrnam=1,
114 exists=1, call=1)114 exists=1, service=1)
115115
116 def test_update_nrpe(self):116 def test_update_nrpe(self):
117 self.patched['config'].return_value = {'nagios_context': 'a',117 self.patched['config'].return_value = {'nagios_context': 'a',
118118
=== modified file 'tests/core/test_host.py'
--- tests/core/test_host.py 2015-11-27 20:57:05 +0000
+++ tests/core/test_host.py 2016-01-06 14:04:36 +0000
@@ -62,8 +62,25 @@
6262
6363
64class HelpersTest(TestCase):64class HelpersTest(TestCase):
65
66 @patch('os.path')
67 def test_init_is_systemd_upstart(self, path):
68 """Upstart based init is correctly detected"""
69 path.isdir.return_value = False
70 self.assertFalse(host.init_is_systemd())
71 path.isdir.assert_called_with('/run/systemd/system')
72
73 @patch('os.path')
74 def test_init_is_systemd_system(self, path):
75 """Systemd based init is correctly detected"""
76 path.isdir.return_value = True
77 self.assertTrue(host.init_is_systemd())
78 path.isdir.assert_called_with('/run/systemd/system')
79
80 @patch.object(host, 'init_is_systemd')
65 @patch('subprocess.call')81 @patch('subprocess.call')
66 def test_runs_service_action(self, mock_call):82 def test_runs_service_action(self, mock_call, systemd):
83 systemd.return_value = False
67 mock_call.return_value = 084 mock_call.return_value = 0
68 action = 'some-action'85 action = 'some-action'
69 service_name = 'foo-service'86 service_name = 'foo-service'
@@ -73,8 +90,24 @@
73 self.assertTrue(result)90 self.assertTrue(result)
74 mock_call.assert_called_with(['service', service_name, action])91 mock_call.assert_called_with(['service', service_name, action])
7592
76 @patch('subprocess.call')93 @patch.object(host, 'init_is_systemd')
77 def test_returns_false_when_service_fails(self, mock_call):94 @patch('subprocess.call')
95 def test_runs_systemctl_action(self, mock_call, systemd):
96 """Ensure that service calls under systemd call 'systemctl'."""
97 systemd.return_value = True
98 mock_call.return_value = 0
99 action = 'some-action'
100 service_name = 'foo-service'
101
102 result = host.service(action, service_name)
103
104 self.assertTrue(result)
105 mock_call.assert_called_with(['systemctl', action, service_name])
106
107 @patch.object(host, 'init_is_systemd')
108 @patch('subprocess.call')
109 def test_returns_false_when_service_fails(self, mock_call, systemd):
110 systemd.return_value = False
78 mock_call.return_value = 1111 mock_call.return_value = 1
79 action = 'some-action'112 action = 'some-action'
80 service_name = 'foo-service'113 service_name = 'foo-service'
@@ -108,13 +141,43 @@
108141
109 service.assert_called_with('restart', service_name)142 service.assert_called_with('restart', service_name)
110143
144 @patch.object(host, 'service_running')
145 @patch.object(host, 'init_is_systemd')
146 @patch.object(host, 'service')
147 def test_pauses_a_running_systemd_unit(self, service, systemd,
148 service_running):
149 """Pause on a running systemd unit will be stopped and disabled."""
150 service_name = 'foo-service'
151 service_running.return_value = True
152 systemd.return_value = True
153 self.assertTrue(host.service_pause(service_name))
154 service.assert_has_calls([
155 call('stop', service_name),
156 call('disable', service_name)])
157
158 @patch.object(host, 'service_running')
159 @patch.object(host, 'init_is_systemd')
160 @patch.object(host, 'service')
161 def test_resumes_a_stopped_systemd_unit(self, service, systemd,
162 service_running):
163 """Resume on a stopped systemd unit will be started and enabled."""
164 service_name = 'foo-service'
165 service_running.return_value = False
166 systemd.return_value = True
167 self.assertTrue(host.service_resume(service_name))
168 service.assert_has_calls([
169 call('enable', service_name),
170 call('start', service_name)])
171
172 @patch.object(host, 'init_is_systemd')
111 @patch('subprocess.check_output')173 @patch('subprocess.check_output')
112 @patch.object(host, 'service')174 @patch.object(host, 'service')
113 def test_pauses_a_running_upstart_service(self, service, check_output):175 def test_pauses_a_running_upstart_service(self, service, check_output, systemd):
114 """Pause on a running service will call service stop."""176 """Pause on a running service will call service stop."""
115 check_output.return_value = b'foo-service start/running, process 123'177 check_output.return_value = b'foo-service start/running, process 123'
116 service_name = 'foo-service'178 service_name = 'foo-service'
117 service.side_effect = [True]179 service.side_effect = [True]
180 systemd.return_value = False
118 tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")181 tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")
119 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))182 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
120 # Just needs to exist183 # Just needs to exist
@@ -130,13 +193,15 @@
130 override_contents = fh.read()193 override_contents = fh.read()
131 self.assertEqual("manual\n", override_contents)194 self.assertEqual("manual\n", override_contents)
132195
196 @patch.object(host, 'init_is_systemd')
133 @patch('subprocess.check_output')197 @patch('subprocess.check_output')
134 @patch.object(host, 'service')198 @patch.object(host, 'service')
135 def test_pauses_a_stopped_upstart_service(self, service, check_output):199 def test_pauses_a_stopped_upstart_service(self, service, check_output, systemd):
136 """Pause on a stopped service will not call service stop."""200 """Pause on a stopped service will not call service stop."""
137 check_output.return_value = b'foo-service stop/waiting'201 check_output.return_value = b'foo-service stop/waiting'
138 service_name = 'foo-service'202 service_name = 'foo-service'
139 service.side_effect = [True]203 service.side_effect = [True]
204 systemd.return_value = False
140 tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")205 tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")
141 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))206 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
142 # Just needs to exist207 # Just needs to exist
@@ -154,15 +219,17 @@
154 override_contents = fh.read()219 override_contents = fh.read()
155 self.assertEqual("manual\n", override_contents)220 self.assertEqual("manual\n", override_contents)
156221
222 @patch.object(host, 'init_is_systemd')
157 @patch('subprocess.check_output')223 @patch('subprocess.check_output')
158 @patch('subprocess.check_call')224 @patch('subprocess.check_call')
159 @patch.object(host, 'service')225 @patch.object(host, 'service')
160 def test_pauses_a_running_sysv_service(self, service, check_call,226 def test_pauses_a_running_sysv_service(self, service, check_call,
161 check_output):227 check_output, systemd):
162 """Pause calls service stop on a running sysv service."""228 """Pause calls service stop on a running sysv service."""
163 check_output.return_value = b'foo-service start/running, process 123'229 check_output.return_value = b'foo-service start/running, process 123'
164 service_name = 'foo-service'230 service_name = 'foo-service'
165 service.side_effect = [True]231 service.side_effect = [True]
232 systemd.return_value = False
166 tempdir = mkdtemp(prefix="test_pauses_a_sysv_service")233 tempdir = mkdtemp(prefix="test_pauses_a_sysv_service")
167 sysv_path = os.path.join(tempdir, service_name)234 sysv_path = os.path.join(tempdir, service_name)
168 # Just needs to exist235 # Just needs to exist
@@ -175,15 +242,17 @@
175 service.assert_called_with('stop', service_name)242 service.assert_called_with('stop', service_name)
176 check_call.assert_called_with(["update-rc.d", service_name, "disable"])243 check_call.assert_called_with(["update-rc.d", service_name, "disable"])
177244
245 @patch.object(host, 'init_is_systemd')
178 @patch('subprocess.check_output')246 @patch('subprocess.check_output')
179 @patch('subprocess.check_call')247 @patch('subprocess.check_call')
180 @patch.object(host, 'service')248 @patch.object(host, 'service')
181 def test_pauses_a_stopped_sysv_service(self, service, check_call,249 def test_pauses_a_stopped_sysv_service(self, service, check_call,
182 check_output):250 check_output, systemd):
183 """Pause does not call service stop on a stopped sysv service."""251 """Pause does not call service stop on a stopped sysv service."""
184 check_output.return_value = b'foo-service stop/waiting'252 check_output.return_value = b'foo-service stop/waiting'
185 service_name = 'foo-service'253 service_name = 'foo-service'
186 service.side_effect = [True]254 service.side_effect = [True]
255 systemd.return_value = False
187 tempdir = mkdtemp(prefix="test_pauses_a_sysv_service")256 tempdir = mkdtemp(prefix="test_pauses_a_sysv_service")
188 sysv_path = os.path.join(tempdir, service_name)257 sysv_path = os.path.join(tempdir, service_name)
189 # Just needs to exist258 # Just needs to exist
@@ -198,10 +267,12 @@
198 AssertionError, service.assert_called_with, 'stop', service_name)267 AssertionError, service.assert_called_with, 'stop', service_name)
199 check_call.assert_called_with(["update-rc.d", service_name, "disable"])268 check_call.assert_called_with(["update-rc.d", service_name, "disable"])
200269
270 @patch.object(host, 'init_is_systemd')
201 @patch.object(host, 'service')271 @patch.object(host, 'service')
202 def test_pause_with_unknown_service(self, service):272 def test_pause_with_unknown_service(self, service, systemd):
203 service_name = 'foo-service'273 service_name = 'foo-service'
204 service.side_effect = [True]274 service.side_effect = [True]
275 systemd.return_value = False
205 tempdir = mkdtemp(prefix="test_pauses_with_unknown_service")276 tempdir = mkdtemp(prefix="test_pauses_with_unknown_service")
206 self.addCleanup(rmtree, tempdir)277 self.addCleanup(rmtree, tempdir)
207 exception = self.assertRaises(278 exception = self.assertRaises(
@@ -211,13 +282,15 @@
211 "Unable to detect {0}".format(service_name), str(exception))282 "Unable to detect {0}".format(service_name), str(exception))
212 self.assertIn(tempdir, str(exception))283 self.assertIn(tempdir, str(exception))
213284
285 @patch.object(host, 'init_is_systemd')
214 @patch('subprocess.check_output')286 @patch('subprocess.check_output')
215 @patch.object(host, 'service')287 @patch.object(host, 'service')
216 def test_resumes_a_running_upstart_service(self, service, check_output):288 def test_resumes_a_running_upstart_service(self, service, check_output, systemd):
217 """When the service is already running, service start isn't called."""289 """When the service is already running, service start isn't called."""
218 check_output.return_value = b'foo-service start/running, process 111'290 check_output.return_value = b'foo-service start/running, process 111'
219 service_name = 'foo-service'291 service_name = 'foo-service'
220 service.side_effect = [True]292 service.side_effect = [True]
293 systemd.return_value = False
221 tempdir = mkdtemp(prefix="test_resumes_an_upstart_service")294 tempdir = mkdtemp(prefix="test_resumes_an_upstart_service")
222 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))295 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
223 with open(conf_path, "w") as fh:296 with open(conf_path, "w") as fh:
@@ -232,13 +305,15 @@
232 tempdir, "{}.override".format(service_name))305 tempdir, "{}.override".format(service_name))
233 self.assertFalse(os.path.exists(override_path))306 self.assertFalse(os.path.exists(override_path))
234307
308 @patch.object(host, 'init_is_systemd')
235 @patch('subprocess.check_output')309 @patch('subprocess.check_output')
236 @patch.object(host, 'service')310 @patch.object(host, 'service')
237 def test_resumes_a_stopped_upstart_service(self, service, check_output):311 def test_resumes_a_stopped_upstart_service(self, service, check_output, systemd):
238 """When the service is stopped, service start is called."""312 """When the service is stopped, service start is called."""
239 check_output.return_value = b'foo-service stop/waiting'313 check_output.return_value = b'foo-service stop/waiting'
240 service_name = 'foo-service'314 service_name = 'foo-service'
241 service.side_effect = [True]315 service.side_effect = [True]
316 systemd.return_value = False
242 tempdir = mkdtemp(prefix="test_resumes_an_upstart_service")317 tempdir = mkdtemp(prefix="test_resumes_an_upstart_service")
243 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))318 conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
244 with open(conf_path, "w") as fh:319 with open(conf_path, "w") as fh:
@@ -251,14 +326,16 @@
251 tempdir, "{}.override".format(service_name))326 tempdir, "{}.override".format(service_name))
252 self.assertFalse(os.path.exists(override_path))327 self.assertFalse(os.path.exists(override_path))
253328
329 @patch.object(host, 'init_is_systemd')
254 @patch('subprocess.check_output')330 @patch('subprocess.check_output')
255 @patch('subprocess.check_call')331 @patch('subprocess.check_call')
256 @patch.object(host, 'service')332 @patch.object(host, 'service')
257 def test_resumes_a_sysv_service(self, service, check_call, check_output):333 def test_resumes_a_sysv_service(self, service, check_call, check_output, systemd):
258 """When process is in a stop/waiting state, service start is called."""334 """When process is in a stop/waiting state, service start is called."""
259 check_output.return_value = b'foo-service stop/waiting'335 check_output.return_value = b'foo-service stop/waiting'
260 service_name = 'foo-service'336 service_name = 'foo-service'
261 service.side_effect = [True]337 service.side_effect = [True]
338 systemd.return_value = False
262 tempdir = mkdtemp(prefix="test_resumes_a_sysv_service")339 tempdir = mkdtemp(prefix="test_resumes_a_sysv_service")
263 sysv_path = os.path.join(tempdir, service_name)340 sysv_path = os.path.join(tempdir, service_name)
264 # Just needs to exist341 # Just needs to exist
@@ -271,15 +348,17 @@
271 service.assert_called_with('start', service_name)348 service.assert_called_with('start', service_name)
272 check_call.assert_called_with(["update-rc.d", service_name, "enable"])349 check_call.assert_called_with(["update-rc.d", service_name, "enable"])
273350
351 @patch.object(host, 'init_is_systemd')
274 @patch('subprocess.check_output')352 @patch('subprocess.check_output')
275 @patch('subprocess.check_call')353 @patch('subprocess.check_call')
276 @patch.object(host, 'service')354 @patch.object(host, 'service')
277 def test_resume_a_running_sysv_service(self, service, check_call,355 def test_resume_a_running_sysv_service(self, service, check_call,
278 check_output):356 check_output, systemd):
279 """When process is already running, service start isn't called."""357 """When process is already running, service start isn't called."""
280 check_output.return_value = b'foo-service start/running, process 123'358 check_output.return_value = b'foo-service start/running, process 123'
281 service_name = 'foo-service'359 service_name = 'foo-service'
282 service.side_effect = [True]360 service.side_effect = [True]
361 systemd.return_value = False
283 tempdir = mkdtemp(prefix="test_resumes_a_sysv_service")362 tempdir = mkdtemp(prefix="test_resumes_a_sysv_service")
284 sysv_path = os.path.join(tempdir, service_name)363 sysv_path = os.path.join(tempdir, service_name)
285 # Just needs to exist364 # Just needs to exist
@@ -294,10 +373,12 @@
294 AssertionError, service.assert_called_with, 'start', service_name)373 AssertionError, service.assert_called_with, 'start', service_name)
295 check_call.assert_called_with(["update-rc.d", service_name, "enable"])374 check_call.assert_called_with(["update-rc.d", service_name, "enable"])
296375
376 @patch.object(host, 'init_is_systemd')
297 @patch.object(host, 'service')377 @patch.object(host, 'service')
298 def test_resume_with_unknown_service(self, service):378 def test_resume_with_unknown_service(self, service, systemd):
299 service_name = 'foo-service'379 service_name = 'foo-service'
300 service.side_effect = [True]380 service.side_effect = [True]
381 systemd.return_value = False
301 tempdir = mkdtemp(prefix="test_resumes_with_unknown_service")382 tempdir = mkdtemp(prefix="test_resumes_with_unknown_service")
302 self.addCleanup(rmtree, tempdir)383 self.addCleanup(rmtree, tempdir)
303 exception = self.assertRaises(384 exception = self.assertRaises(
@@ -379,18 +460,24 @@
379 call('restart', service_name)460 call('restart', service_name)
380 ])461 ])
381462
463 @patch.object(host, 'init_is_systemd')
382 @patch('subprocess.check_output')464 @patch('subprocess.check_output')
383 def test_service_running_on_stopped_service(self, check_output):465 def test_service_running_on_stopped_service(self, check_output, systemd):
466 systemd.return_value = False
384 check_output.return_value = b'foo stop/waiting'467 check_output.return_value = b'foo stop/waiting'
385 self.assertFalse(host.service_running('foo'))468 self.assertFalse(host.service_running('foo'))
386469
470 @patch.object(host, 'init_is_systemd')
387 @patch('subprocess.check_output')471 @patch('subprocess.check_output')
388 def test_service_running_on_running_service(self, check_output):472 def test_service_running_on_running_service(self, check_output, systemd):
473 systemd.return_value = False
389 check_output.return_value = b'foo start/running, process 23871'474 check_output.return_value = b'foo start/running, process 23871'
390 self.assertTrue(host.service_running('foo'))475 self.assertTrue(host.service_running('foo'))
391476
477 @patch.object(host, 'init_is_systemd')
392 @patch('subprocess.check_output')478 @patch('subprocess.check_output')
393 def test_service_running_on_unknown_service(self, check_output):479 def test_service_running_on_unknown_service(self, check_output, systemd):
480 systemd.return_value = False
394 exc = subprocess.CalledProcessError(1, ['status'])481 exc = subprocess.CalledProcessError(1, ['status'])
395 check_output.side_effect = exc482 check_output.side_effect = exc
396 self.assertFalse(host.service_running('foo'))483 self.assertFalse(host.service_running('foo'))

Subscribers

People subscribed via source and target branches