aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2012-01-03 12:25:23 +0100
committerMichał Górny <mgorny@gentoo.org>2012-01-03 12:25:23 +0100
commit46362b19ba3fe2e56879e54c276533d642ccc7c5 (patch)
treedf1543cdc08847aac03b33e3ef90b68b434b5f5b
parentMove repo startup code to an idle. (diff)
downloadpms-test-suite-46362b19ba3fe2e56879e54c276533d642ccc7c5.tar.gz
pms-test-suite-46362b19ba3fe2e56879e54c276533d642ccc7c5.tar.bz2
pms-test-suite-46362b19ba3fe2e56879e54c276533d642ccc7c5.zip
Support running local D-Bus bus.
-rw-r--r--bus.conf (renamed from org.gentoo.pmstestsuite.conf)14
-rw-r--r--pmstestsuite/cli.py57
-rw-r--r--pmstestsuite/dbus_handler.py27
-rw-r--r--pmstestsuite/repository/pms_eclass.py2
-rwxr-xr-xsetup.py3
5 files changed, 67 insertions, 36 deletions
diff --git a/org.gentoo.pmstestsuite.conf b/bus.conf
index fcde79c..a078c1c 100644
--- a/org.gentoo.pmstestsuite.conf
+++ b/bus.conf
@@ -3,10 +3,16 @@
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
- <!-- For testing, allow everyone. XXX: restrict it -->
+ <type>session</type>
+ <listen>unix:tmpdir=/tmp</listen>
+
+ <user>portage</user> <!-- XXX -->
+
<policy context="default">
- <allow own="org.gentoo.pmstestsuite"/>
- <allow send_destination="org.gentoo.pmstestsuite"/>
- <allow receive_sender="org.gentoo.pmstestsuite"/>
+ <allow user="root"/>
+
+ <allow send_destination="*" eavesdrop="true"/>
+ <allow eavesdrop="true"/>
+ <allow own="*"/>
</policy>
</busconfig>
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 <mgorny@gentoo.org>
+# (c) 2011-2012 Michał Górny <mgorny@gentoo.org>
# 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 <mgorny@gentoo.org>
+# (c) 2011-2012 Michał Górny <mgorny@gentoo.org>
# 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',