From 46362b19ba3fe2e56879e54c276533d642ccc7c5 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Tue, 3 Jan 2012 12:25:23 +0100 Subject: Support running local D-Bus bus. --- bus.conf | 18 +++++++++++ org.gentoo.pmstestsuite.conf | 12 -------- pmstestsuite/cli.py | 57 ++++++++++++++++++++--------------- pmstestsuite/dbus_handler.py | 27 ++++++++++++++--- pmstestsuite/repository/pms_eclass.py | 2 +- setup.py | 3 -- 6 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 bus.conf delete mode 100644 org.gentoo.pmstestsuite.conf diff --git a/bus.conf b/bus.conf new file mode 100644 index 0000000..a078c1c --- /dev/null +++ b/bus.conf @@ -0,0 +1,18 @@ + + + + + session + unix:tmpdir=/tmp + + portage + + + + + + + + + diff --git a/org.gentoo.pmstestsuite.conf b/org.gentoo.pmstestsuite.conf deleted file mode 100644 index fcde79c..0000000 --- a/org.gentoo.pmstestsuite.conf +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py index 3efd658..73468d1 100644 --- a/pmstestsuite/cli.py +++ b/pmstestsuite/cli.py @@ -1,5 +1,5 @@ # vim:fileencoding=utf-8 -# (c) 2011 Michał Górny +# (c) 2011-2012 Michał Górny # Released under the terms of the 2-clause BSD license. from __future__ import print_function @@ -156,26 +156,31 @@ class PMSTestSuiteCLI(object): except (EnvironmentError, KeyError, ValueError) as e: opt.error('Repository open failed: %s' % e) - dbus_hdlr = DBusHandler() + dbus_uid = pm.config.userpriv_uid if pm.config.userpriv_enabled \ + else None + self.dbus_hdlr = DBusHandler(uid = dbus_uid) try: - self.test_library = load_library(opts.library_name, - thorough = opts.thorough, undefined = opts.undefined, - dbus_hdlr = dbus_hdlr) - except (ImportError, TypeError) as e: - opt.error('Test library load failed: %s' % e) - - for pm in self.pms: - pm.package_limit = opts.limit_pkgs - self.create_repo_only = opts.create_repo_only - self.update_manifests = not opts.no_manifests - self.verbose = opts.verbose - - limit_tests = set() - for t in opts.tests: - limit_tests.update(t.split()) - if limit_tests: - self.test_library.limit_tests(limit_tests) + try: + self.test_library = load_library(opts.library_name, + thorough = opts.thorough, undefined = opts.undefined, + dbus_hdlr = self.dbus_hdlr) + except (ImportError, TypeError) as e: + opt.error('Test library load failed: %s' % e) + + for pm in self.pms: + pm.package_limit = opts.limit_pkgs + self.create_repo_only = opts.create_repo_only + self.update_manifests = not opts.no_manifests + self.verbose = opts.verbose + + limit_tests = set() + for t in opts.tests: + limit_tests.update(t.split()) + if limit_tests: + self.test_library.limit_tests(limit_tests) + except Exception: + dbus_hdlr.terminate() def _print_stage(self, text): print('-> [%s] %s...' % (self.pm.name, text)) @@ -288,10 +293,14 @@ class PMSTestSuiteCLI(object): def main(self, argv): self._start(*argv) - gobject.idle_add(self.generate_and_start) - - self.ret = 1 - self.loop = gobject.MainLoop() - self.loop.run() + try: + gobject.idle_add(self.generate_and_start) + + self.ret = 1 + self.loop = gobject.MainLoop() + self.loop.run() + finally: + # Ensure to terminate the spawned D-Bus. + self.dbus_hdlr.terminate() return self.ret diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py index 6f50140..9a8c529 100644 --- a/pmstestsuite/dbus_handler.py +++ b/pmstestsuite/dbus_handler.py @@ -1,8 +1,8 @@ # vim:fileencoding=utf-8 -# (c) 2011 Michał Górny +# (c) 2011-2012 Michał Górny # Released under the terms of the 2-clause BSD license. -import dbus +import dbus, os, signal from dbus.mainloop.glib import DBusGMainLoop dbus_interface_name = 'org.gentoo.pmstestsuite' @@ -12,8 +12,27 @@ dbus_object_prefix = '/org/gentoo/pmstestsuite' class DBusHandler(object): """ A class handling all D-Bus interaction for PMS Test Suite. """ - def __init__(self): + def start_dbus(self, uid): + (read_fd, write_fd) = os.pipe() + self.dbus_pid = os.fork() + if self.dbus_pid == 0: + os.close(read_fd) + os.execlp('dbus-daemon', 'dbus-daemon', '--nofork', + '--config-file=bus.conf', # XXX: path + '--print-address=%d' % write_fd) + else: + addr = os.read(read_fd, 1024) + os.close(write_fd) + + self.bus_address = addr.strip() + + def terminate(self): + os.kill(self.dbus_pid, signal.SIGTERM) + + def __init__(self, uid): """ Initialize DBusHandler. Add it to main GLib loop. """ DBusGMainLoop(set_as_default=True) - self.bus = dbus.SystemBus() + self.start_dbus(uid) + os.environ['DBUS_SESSION_BUS_ADDRESS'] = self.bus_address + self.bus = dbus.SessionBus() self.busname = dbus.service.BusName(dbus_bus_name, self.bus) diff --git a/pmstestsuite/repository/pms_eclass.py b/pmstestsuite/repository/pms_eclass.py index 336a22a..97caa9a 100644 --- a/pmstestsuite/repository/pms_eclass.py +++ b/pmstestsuite/repository/pms_eclass.py @@ -31,7 +31,7 @@ pms-test_dbus_call() { PMS_TEST_DBUS_P=${P//-/_} dbus-send \\ - --system \\ + --session \\ --print-reply \\ --type=method_call \\ --dest=%s \\ diff --git a/setup.py b/setup.py index ad08d83..8233cd5 100755 --- a/setup.py +++ b/setup.py @@ -73,9 +73,6 @@ setup( scripts = [ 'pms-tester' ], - data_files = [ - ('/etc/dbus-1/system.d', ['org.gentoo.pmstestsuite.conf']) - ], classifiers = [ 'Development Status :: 4 - Beta', -- cgit v1.2.3-65-gdbad