1 |
commit: 46362b19ba3fe2e56879e54c276533d642ccc7c5 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 3 11:25:23 2012 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 3 11:25:23 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/pms-test-suite.git;a=commit;h=46362b19 |
7 |
|
8 |
Support running local D-Bus bus. |
9 |
|
10 |
--- |
11 |
org.gentoo.pmstestsuite.conf => bus.conf | 14 +++++-- |
12 |
pmstestsuite/cli.py | 57 +++++++++++++++++------------ |
13 |
pmstestsuite/dbus_handler.py | 27 ++++++++++++-- |
14 |
pmstestsuite/repository/pms_eclass.py | 2 +- |
15 |
setup.py | 3 -- |
16 |
5 files changed, 67 insertions(+), 36 deletions(-) |
17 |
|
18 |
diff --git a/org.gentoo.pmstestsuite.conf b/bus.conf |
19 |
similarity index 52% |
20 |
rename from org.gentoo.pmstestsuite.conf |
21 |
rename to bus.conf |
22 |
index fcde79c..a078c1c 100644 |
23 |
--- a/org.gentoo.pmstestsuite.conf |
24 |
+++ b/bus.conf |
25 |
@@ -3,10 +3,16 @@ |
26 |
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> |
27 |
|
28 |
<busconfig> |
29 |
- <!-- For testing, allow everyone. XXX: restrict it --> |
30 |
+ <type>session</type> |
31 |
+ <listen>unix:tmpdir=/tmp</listen> |
32 |
+ |
33 |
+ <user>portage</user> <!-- XXX --> |
34 |
+ |
35 |
<policy context="default"> |
36 |
- <allow own="org.gentoo.pmstestsuite"/> |
37 |
- <allow send_destination="org.gentoo.pmstestsuite"/> |
38 |
- <allow receive_sender="org.gentoo.pmstestsuite"/> |
39 |
+ <allow user="root"/> |
40 |
+ |
41 |
+ <allow send_destination="*" eavesdrop="true"/> |
42 |
+ <allow eavesdrop="true"/> |
43 |
+ <allow own="*"/> |
44 |
</policy> |
45 |
</busconfig> |
46 |
|
47 |
diff --git a/pmstestsuite/cli.py b/pmstestsuite/cli.py |
48 |
index 3efd658..73468d1 100644 |
49 |
--- a/pmstestsuite/cli.py |
50 |
+++ b/pmstestsuite/cli.py |
51 |
@@ -1,5 +1,5 @@ |
52 |
# vim:fileencoding=utf-8 |
53 |
-# (c) 2011 Michał Górny <mgorny@g.o> |
54 |
+# (c) 2011-2012 Michał Górny <mgorny@g.o> |
55 |
# Released under the terms of the 2-clause BSD license. |
56 |
|
57 |
from __future__ import print_function |
58 |
@@ -156,26 +156,31 @@ class PMSTestSuiteCLI(object): |
59 |
except (EnvironmentError, KeyError, ValueError) as e: |
60 |
opt.error('Repository open failed: %s' % e) |
61 |
|
62 |
- dbus_hdlr = DBusHandler() |
63 |
+ dbus_uid = pm.config.userpriv_uid if pm.config.userpriv_enabled \ |
64 |
+ else None |
65 |
+ self.dbus_hdlr = DBusHandler(uid = dbus_uid) |
66 |
|
67 |
try: |
68 |
- self.test_library = load_library(opts.library_name, |
69 |
- thorough = opts.thorough, undefined = opts.undefined, |
70 |
- dbus_hdlr = dbus_hdlr) |
71 |
- except (ImportError, TypeError) as e: |
72 |
- opt.error('Test library load failed: %s' % e) |
73 |
- |
74 |
- for pm in self.pms: |
75 |
- pm.package_limit = opts.limit_pkgs |
76 |
- self.create_repo_only = opts.create_repo_only |
77 |
- self.update_manifests = not opts.no_manifests |
78 |
- self.verbose = opts.verbose |
79 |
- |
80 |
- limit_tests = set() |
81 |
- for t in opts.tests: |
82 |
- limit_tests.update(t.split()) |
83 |
- if limit_tests: |
84 |
- self.test_library.limit_tests(limit_tests) |
85 |
+ try: |
86 |
+ self.test_library = load_library(opts.library_name, |
87 |
+ thorough = opts.thorough, undefined = opts.undefined, |
88 |
+ dbus_hdlr = self.dbus_hdlr) |
89 |
+ except (ImportError, TypeError) as e: |
90 |
+ opt.error('Test library load failed: %s' % e) |
91 |
+ |
92 |
+ for pm in self.pms: |
93 |
+ pm.package_limit = opts.limit_pkgs |
94 |
+ self.create_repo_only = opts.create_repo_only |
95 |
+ self.update_manifests = not opts.no_manifests |
96 |
+ self.verbose = opts.verbose |
97 |
+ |
98 |
+ limit_tests = set() |
99 |
+ for t in opts.tests: |
100 |
+ limit_tests.update(t.split()) |
101 |
+ if limit_tests: |
102 |
+ self.test_library.limit_tests(limit_tests) |
103 |
+ except Exception: |
104 |
+ dbus_hdlr.terminate() |
105 |
|
106 |
def _print_stage(self, text): |
107 |
print('-> [%s] %s...' % (self.pm.name, text)) |
108 |
@@ -288,10 +293,14 @@ class PMSTestSuiteCLI(object): |
109 |
def main(self, argv): |
110 |
self._start(*argv) |
111 |
|
112 |
- gobject.idle_add(self.generate_and_start) |
113 |
- |
114 |
- self.ret = 1 |
115 |
- self.loop = gobject.MainLoop() |
116 |
- self.loop.run() |
117 |
+ try: |
118 |
+ gobject.idle_add(self.generate_and_start) |
119 |
+ |
120 |
+ self.ret = 1 |
121 |
+ self.loop = gobject.MainLoop() |
122 |
+ self.loop.run() |
123 |
+ finally: |
124 |
+ # Ensure to terminate the spawned D-Bus. |
125 |
+ self.dbus_hdlr.terminate() |
126 |
|
127 |
return self.ret |
128 |
|
129 |
diff --git a/pmstestsuite/dbus_handler.py b/pmstestsuite/dbus_handler.py |
130 |
index 6f50140..9a8c529 100644 |
131 |
--- a/pmstestsuite/dbus_handler.py |
132 |
+++ b/pmstestsuite/dbus_handler.py |
133 |
@@ -1,8 +1,8 @@ |
134 |
# vim:fileencoding=utf-8 |
135 |
-# (c) 2011 Michał Górny <mgorny@g.o> |
136 |
+# (c) 2011-2012 Michał Górny <mgorny@g.o> |
137 |
# Released under the terms of the 2-clause BSD license. |
138 |
|
139 |
-import dbus |
140 |
+import dbus, os, signal |
141 |
from dbus.mainloop.glib import DBusGMainLoop |
142 |
|
143 |
dbus_interface_name = 'org.gentoo.pmstestsuite' |
144 |
@@ -12,8 +12,27 @@ dbus_object_prefix = '/org/gentoo/pmstestsuite' |
145 |
class DBusHandler(object): |
146 |
""" A class handling all D-Bus interaction for PMS Test Suite. """ |
147 |
|
148 |
- def __init__(self): |
149 |
+ def start_dbus(self, uid): |
150 |
+ (read_fd, write_fd) = os.pipe() |
151 |
+ self.dbus_pid = os.fork() |
152 |
+ if self.dbus_pid == 0: |
153 |
+ os.close(read_fd) |
154 |
+ os.execlp('dbus-daemon', 'dbus-daemon', '--nofork', |
155 |
+ '--config-file=bus.conf', # XXX: path |
156 |
+ '--print-address=%d' % write_fd) |
157 |
+ else: |
158 |
+ addr = os.read(read_fd, 1024) |
159 |
+ os.close(write_fd) |
160 |
+ |
161 |
+ self.bus_address = addr.strip() |
162 |
+ |
163 |
+ def terminate(self): |
164 |
+ os.kill(self.dbus_pid, signal.SIGTERM) |
165 |
+ |
166 |
+ def __init__(self, uid): |
167 |
""" Initialize DBusHandler. Add it to main GLib loop. """ |
168 |
DBusGMainLoop(set_as_default=True) |
169 |
- self.bus = dbus.SystemBus() |
170 |
+ self.start_dbus(uid) |
171 |
+ os.environ['DBUS_SESSION_BUS_ADDRESS'] = self.bus_address |
172 |
+ self.bus = dbus.SessionBus() |
173 |
self.busname = dbus.service.BusName(dbus_bus_name, self.bus) |
174 |
|
175 |
diff --git a/pmstestsuite/repository/pms_eclass.py b/pmstestsuite/repository/pms_eclass.py |
176 |
index 336a22a..97caa9a 100644 |
177 |
--- a/pmstestsuite/repository/pms_eclass.py |
178 |
+++ b/pmstestsuite/repository/pms_eclass.py |
179 |
@@ -31,7 +31,7 @@ pms-test_dbus_call() { |
180 |
|
181 |
PMS_TEST_DBUS_P=${P//-/_} |
182 |
dbus-send \\ |
183 |
- --system \\ |
184 |
+ --session \\ |
185 |
--print-reply \\ |
186 |
--type=method_call \\ |
187 |
--dest=%s \\ |
188 |
|
189 |
diff --git a/setup.py b/setup.py |
190 |
index ad08d83..8233cd5 100755 |
191 |
--- a/setup.py |
192 |
+++ b/setup.py |
193 |
@@ -73,9 +73,6 @@ setup( |
194 |
scripts = [ |
195 |
'pms-tester' |
196 |
], |
197 |
- data_files = [ |
198 |
- ('/etc/dbus-1/system.d', ['org.gentoo.pmstestsuite.conf']) |
199 |
- ], |
200 |
|
201 |
classifiers = [ |
202 |
'Development Status :: 4 - Beta', |