Merge lp:~mvo/click/lp1232130-kill-on-remove into lp:click/devel

Proposed by Michael Vogt
Status: Merged
Merged at revision: 525
Proposed branch: lp:~mvo/click/lp1232130-kill-on-remove
Merge into: lp:click/devel
Diff against target: 140 lines (+86/-2)
3 files modified
click/tests/helpers.py (+8/-0)
click/tests/test_user.py (+28/-2)
lib/click/user.vala (+50/-0)
To merge this branch: bzr merge lp:~mvo/click/lp1232130-kill-on-remove
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Colin Watson Approve
Review via email: mp+236298@code.launchpad.net

Commit message

Stop apps if necessary when uninstalling them.

Description of the change

Another branch where I would love to get some feedback if the direction looks good. If so, I will refactor the code to be cleaner. Please let me know if you would prefer to avoid the new make_file_with_content() helper and if you want me to use mkfile instead (maybe my version is a bit too specific for a general test helper).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:430
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mvo/click/lp1232130-kill-on-remove/+merge/236298/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/click-devel-ci/79/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/click-devel-utopic-amd64-ci/81
    SUCCESS: http://jenkins.qa.ubuntu.com/job/click-devel-utopic-armhf-ci/79
        deb: http://jenkins.qa.ubuntu.com/job/click-devel-utopic-armhf-ci/79/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/click-devel-utopic-i386-ci/79

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/click-devel-ci/79/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click/tests/helpers.py'
--- click/tests/helpers.py 2014-06-23 21:14:06 +0000
+++ click/tests/helpers.py 2014-09-29 11:15:22 +0000
@@ -326,3 +326,11 @@
326def touch(path):326def touch(path):
327 with mkfile(path, mode="a"):327 with mkfile(path, mode="a"):
328 pass328 pass
329
330
331def make_file_with_content(filename, content, mode=0o644):
332 """Create a file with the given content and mode"""
333 Click.ensuredir(os.path.dirname(filename))
334 with open(filename, "w") as f:
335 f.write(content)
336 os.chmod(filename, 0o755)
329337
=== modified file 'click/tests/test_user.py'
--- click/tests/test_user.py 2014-07-09 12:56:21 +0000
+++ click/tests/test_user.py 2014-09-29 11:15:22 +0000
@@ -26,12 +26,18 @@
26import json26import json
27import os27import os
28import shutil28import shutil
29from textwrap import dedent
2930
30from gi.repository import Click, GLib31from gi.repository import Click, GLib
3132
32from click.json_helpers import json_array_to_python, json_object_to_python33from click.json_helpers import json_array_to_python, json_object_to_python
33from click.tests.gimock_types import Passwd34from click.tests.gimock_types import Passwd
34from click.tests.helpers import TestCase, mkfile, touch35from click.tests.helpers import (
36 TestCase,
37 mkfile,
38 make_file_with_content,
39 touch,
40)
3541
3642
37class TestClickUser(TestCase):43class TestClickUser(TestCase):
@@ -53,7 +59,8 @@
53 a_1_0 = os.path.join(self.temp_dir, "custom", "a", "1.0")59 a_1_0 = os.path.join(self.temp_dir, "custom", "a", "1.0")
54 os.makedirs(a_1_0)60 os.makedirs(a_1_0)
55 with mkfile(os.path.join(a_1_0, ".click", "info", "a.manifest")) as m:61 with mkfile(os.path.join(a_1_0, ".click", "info", "a.manifest")) as m:
56 json.dump({"name": "a", "version": "1.0"}, m)62 json.dump({"name": "a", "version": "1.0",
63 "hooks": {"a-app": {}}}, m)
57 b_2_0 = os.path.join(self.temp_dir, "custom", "b", "2.0")64 b_2_0 = os.path.join(self.temp_dir, "custom", "b", "2.0")
58 os.makedirs(b_2_0)65 os.makedirs(b_2_0)
59 with mkfile(os.path.join(b_2_0, ".click", "info", "b.manifest")) as m:66 with mkfile(os.path.join(b_2_0, ".click", "info", "b.manifest")) as m:
@@ -549,3 +556,22 @@
549 self.assertEqual("2.0", registry.get_version("b"))556 self.assertEqual("2.0", registry.get_version("b"))
550 self.assertEqual(b_overlay, registry.get_path("b"))557 self.assertEqual(b_overlay, registry.get_path("b"))
551 self.assertTrue(registry.is_removable("b"))558 self.assertTrue(registry.is_removable("b"))
559
560 def test_app_stops_on_remove(self):
561 fake_app_stop = os.path.join(self.temp_dir, "bin", "ubuntu-app-stop")
562 fake_app_stop_output = os.path.join(self.temp_dir, "fake-app-stop.out")
563 fake_app_stop_content = dedent("""\
564 #!/bin/sh
565 echo "$@" >> %s
566 """ % fake_app_stop_output)
567 make_file_with_content(fake_app_stop, fake_app_stop_content, 0o755)
568 # its ok to modify env here, click.helpers.TestCase will take care
569 # of it
570 os.environ["PATH"] = "%s:%s" % (
571 os.path.dirname(fake_app_stop), os.environ["PATH"])
572 # get a app with manifest etc all
573 _, registry = self._setUpMultiDB()
574 registry.remove("a")
575 # ensure that stop was called with the right app
576 with open(fake_app_stop_output) as f:
577 self.assertEqual("a_a-app_1.1", f.read().strip())
552578
=== modified file 'lib/click/user.vala'
--- lib/click/user.vala 2014-07-11 17:16:35 +0000
+++ lib/click/user.vala 2014-09-29 11:15:22 +0000
@@ -598,6 +598,48 @@
598 old_version, version, name);598 old_version, version, name);
599 }599 }
600600
601 private bool
602 stop_running_app (string package, string version)
603 {
604 var res = true;
605 if (! find_on_path ("ubuntu-app-stop"))
606 return false;
607
608 Json.Object manifest;
609 try {
610 manifest = get_manifest (package);
611 } catch (Error e) {
612 warning ("Can not get manifest for %s", package);
613 return false;
614 }
615
616 if (! manifest.has_member ("hooks")) {
617 warning ("No hooks in manifest %s", package);
618 return false;
619 }
620 var hooks = manifest.get_object_member ("hooks");
621 foreach (unowned string app_name in
622 hooks.get_members ())
623 {
624 // FIXME: move this into a "stop_single_app" helper
625 string[] command = {
626 "ubuntu-app-stop",
627 @"$(package)_$(app_name)_$(version)"
628 };
629 try {
630 int exit_status;
631 Process.spawn_sync (null, command, null,
632 SpawnFlags.SEARCH_PATH |
633 SpawnFlags.STDOUT_TO_DEV_NULL,
634 null, null, null, out exit_status);
635 res &= Process.check_exit_status (exit_status);
636 } catch (Error e) {
637 res &= false;
638 }
639 }
640 return res;
641 }
642
601 /**643 /**
602 * remove:644 * remove:
603 * @package: A package name.645 * @package: A package name.
@@ -636,6 +678,14 @@
636 regain_privileges ();678 regain_privileges ();
637 }679 }
638 }680 }
681
682 drop_privileges ();
683 try {
684 stop_running_app (package, old_version);
685 } finally {
686 regain_privileges ();
687 }
688
639 if (! is_pseudo_user)689 if (! is_pseudo_user)
640 package_remove_hooks (db, package, old_version, name);690 package_remove_hooks (db, package, old_version, name);
641 }691 }

Subscribers

People subscribed via source and target branches

to all changes: