Merge lp:~gnuoy/charm-helpers/quote-pidof-svc into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 650
Proposed branch: lp:~gnuoy/charm-helpers/quote-pidof-svc
Merge into: lp:charm-helpers
Diff against target: 118 lines (+21/-16)
2 files modified
charmhelpers/contrib/amulet/utils.py (+1/-1)
tests/contrib/amulet/test_utils.py (+20/-15)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/quote-pidof-svc
Reviewer Review Type Date Requested Status
David Ames (community) Approve
James Page Approve
Review via email: mp+308381@code.launchpad.net
To post a comment you must log in.
650. By Liam Young

Quote service to examine as it might contain whitespace in systemd land

Revision history for this message
James Page (james-page) :
review: Approve
651. By Liam Young

Update unit tests

Revision history for this message
David Ames (thedac) wrote :

Looks good. Merging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/amulet/utils.py'
--- charmhelpers/contrib/amulet/utils.py 2016-07-06 14:41:05 +0000
+++ charmhelpers/contrib/amulet/utils.py 2016-10-13 13:46:03 +0000
@@ -546,7 +546,7 @@
546 raise if it is present.546 raise if it is present.
547 :returns: List of process IDs547 :returns: List of process IDs
548 """548 """
549 cmd = 'pidof -x {}'.format(process_name)549 cmd = 'pidof -x "{}"'.format(process_name)
550 if not expect_success:550 if not expect_success:
551 cmd += " || exit 0 && exit 1"551 cmd += " || exit 0 && exit 1"
552 output, code = sentry_unit.run(cmd)552 output, code = sentry_unit.run(cmd)
553553
=== modified file 'tests/contrib/amulet/test_utils.py'
--- tests/contrib/amulet/test_utils.py 2016-04-05 21:46:12 +0000
+++ tests/contrib/amulet/test_utils.py 2016-10-13 13:46:03 +0000
@@ -224,7 +224,7 @@
224 """224 """
225 Normal execution returns a list of pids225 Normal execution returns a list of pids
226 """226 """
227 self.sentry_unit.commands["pidof -x foo"] = ("123 124 125", 0)227 self.sentry_unit.commands['pidof -x "foo"'] = ("123 124 125", 0)
228 result = self.utils.get_process_id_list(self.sentry_unit, "foo")228 result = self.utils.get_process_id_list(self.sentry_unit, "foo")
229 self.assertEqual(["123", "124", "125"], result)229 self.assertEqual(["123", "124", "125"], result)
230230
@@ -234,21 +234,21 @@
234 to find a given process results in an amulet.FAIL being234 to find a given process results in an amulet.FAIL being
235 raised.235 raised.
236 """236 """
237 self.sentry_unit.commands["pidof -x foo"] = ("", 1)237 self.sentry_unit.commands['pidof -x "foo"'] = ("", 1)
238 with self.assertRaises(SystemExit) as cm, captured_output() as (238 with self.assertRaises(SystemExit) as cm, captured_output() as (
239 out, err):239 out, err):
240 self.utils.get_process_id_list(self.sentry_unit, "foo")240 self.utils.get_process_id_list(self.sentry_unit, "foo")
241 the_exception = cm.exception241 the_exception = cm.exception
242 self.assertEqual(1, the_exception.code)242 self.assertEqual(1, the_exception.code)
243 self.assertEqual(243 self.assertEqual(
244 "foo `pidof -x foo` returned 1", out.getvalue().rstrip())244 'foo `pidof -x "foo"` returned 1', out.getvalue().rstrip())
245245
246 def test_looks_for_scripts(self):246 def test_looks_for_scripts(self):
247 """247 """
248 pidof command uses -x to return a list of pids of scripts248 pidof command uses -x to return a list of pids of scripts
249 """249 """
250 self.sentry_unit.commands["pidof foo"] = ("", 1)250 self.sentry_unit.commands["pidof foo"] = ("", 1)
251 self.sentry_unit.commands["pidof -x foo"] = ("123 124 125", 0)251 self.sentry_unit.commands['pidof -x "foo"'] = ("123 124 125", 0)
252 result = self.utils.get_process_id_list(self.sentry_unit, "foo")252 result = self.utils.get_process_id_list(self.sentry_unit, "foo")
253 self.assertEqual(["123", "124", "125"], result)253 self.assertEqual(["123", "124", "125"], result)
254254
@@ -257,8 +257,10 @@
257 By setting expectation that there are no pids running the logic257 By setting expectation that there are no pids running the logic
258 about when to fail is reversed.258 about when to fail is reversed.
259 """259 """
260 self.sentry_unit.commands["pidof -x foo || exit 0 && exit 1"] = ("", 0)260 self.sentry_unit.commands[
261 self.sentry_unit.commands["pidof -x bar || exit 0 && exit 1"] = ("", 1)261 'pidof -x "foo" || exit 0 && exit 1'] = ("", 0)
262 self.sentry_unit.commands[
263 'pidof -x "bar" || exit 0 && exit 1'] = ("", 1)
262 result = self.utils.get_process_id_list(264 result = self.utils.get_process_id_list(
263 self.sentry_unit, "foo", expect_success=False)265 self.sentry_unit, "foo", expect_success=False)
264 self.assertEqual([], result)266 self.assertEqual([], result)
@@ -269,7 +271,7 @@
269 the_exception = cm.exception271 the_exception = cm.exception
270 self.assertEqual(1, the_exception.code)272 self.assertEqual(1, the_exception.code)
271 self.assertEqual(273 self.assertEqual(
272 "foo `pidof -x bar || exit 0 && exit 1` returned 1",274 'foo `pidof -x "bar" || exit 0 && exit 1` returned 1',
273 out.getvalue().rstrip())275 out.getvalue().rstrip())
274276
275277
@@ -285,8 +287,8 @@
285 PIDs for each unit.287 PIDs for each unit.
286 """288 """
287 second_sentry = FakeSentry(name="bar")289 second_sentry = FakeSentry(name="bar")
288 self.sentry_unit.commands["pidof -x foo"] = ("123 124", 0)290 self.sentry_unit.commands['pidof -x "foo"'] = ("123 124", 0)
289 second_sentry.commands["pidof -x bar"] = ("456 457", 0)291 second_sentry.commands['pidof -x "bar"'] = ("456 457", 0)
290292
291 result = self.utils.get_unit_process_ids({293 result = self.utils.get_unit_process_ids({
292 self.sentry_unit: ["foo"], second_sentry: ["bar"]})294 self.sentry_unit: ["foo"], second_sentry: ["bar"]})
@@ -299,8 +301,9 @@
299 Expected failures return empty lists.301 Expected failures return empty lists.
300 """302 """
301 second_sentry = FakeSentry(name="bar")303 second_sentry = FakeSentry(name="bar")
302 self.sentry_unit.commands["pidof -x foo || exit 0 && exit 1"] = ("", 0)304 self.sentry_unit.commands[
303 second_sentry.commands["pidof -x bar || exit 0 && exit 1"] = ("", 0)305 'pidof -x "foo" || exit 0 && exit 1'] = ("", 0)
306 second_sentry.commands['pidof -x "bar" || exit 0 && exit 1'] = ("", 0)
304307
305 result = self.utils.get_unit_process_ids(308 result = self.utils.get_unit_process_ids(
306 {self.sentry_unit: ["foo"], second_sentry: ["bar"]},309 {self.sentry_unit: ["foo"], second_sentry: ["bar"]},
@@ -320,8 +323,9 @@
320 """323 """
321 We can get the status of a unit.324 We can get the status of a unit.
322 """325 """
323 self.sentry_unit.commands["status-get --format=json --include-data"] = (326 self.sentry_unit.commands[
324 """{"status": "active", "message": "foo"}""", 0)327 "status-get --format=json --include-data"] = (
328 """{"status": "active", "message": "foo"}""", 0)
325 self.assertEqual(self.utils.status_get(self.sentry_unit),329 self.assertEqual(self.utils.status_get(self.sentry_unit),
326 (u"active", u"foo"))330 (u"active", u"foo"))
327331
@@ -330,8 +334,9 @@
330 Older releases of Juju have no status-get command. In those334 Older releases of Juju have no status-get command. In those
331 cases we should return the "unknown" status.335 cases we should return the "unknown" status.
332 """336 """
333 self.sentry_unit.commands["status-get --format=json --include-data"] = (337 self.sentry_unit.commands[
334 "status-get: command not found", 127)338 "status-get --format=json --include-data"] = (
339 "status-get: command not found", 127)
335 self.assertEqual(self.utils.status_get(self.sentry_unit),340 self.assertEqual(self.utils.status_get(self.sentry_unit),
336 (u"unknown", u""))341 (u"unknown", u""))
337342

Subscribers

People subscribed via source and target branches