Merge lp:~larryprice/libertine/libertined-test-stable into lp:libertine

Proposed by Larry Price on 2017-03-27
Status: Merged
Approved by: Christopher Townsend on 2017-03-27
Approved revision: 412
Merged at revision: 451
Proposed branch: lp:~larryprice/libertine/libertined-test-stable
Merge into: lp:libertine
Diff against target: 308 lines (+37/-39)
11 files modified
python/libertine/service/operations_monitor.py (+2/-1)
python/libertine/service/task_dispatcher.py (+0/-20)
python/libertine/service/tasks/base_task.py (+16/-1)
python/libertine/service/tasks/create_task.py (+2/-1)
python/libertine/service/tasks/destroy_task.py (+1/-0)
python/libertine/service/tasks/install_task.py (+1/-0)
python/libertine/service/tasks/list_task.py (+1/-0)
python/libertine/service/tasks/remove_task.py (+1/-0)
tests/integration/CMakeLists.txt (+1/-1)
tests/integration/test_libertine_service.py (+10/-14)
tools/libertined (+2/-1)
To merge this branch: bzr merge lp:~larryprice/libertine/libertined-test-stable
Reviewer Review Type Date Requested Status
Christopher Townsend 2017-03-27 Approve on 2017-03-27
Libertine CI Bot continuous-integration Approve on 2017-03-27
Review via email: mp+321110@code.launchpad.net

Commit message

Modifications to make test_libertine_service more stable.

Description of the change

Modifications to make test_libertine_service more stable.

To post a comment you must log in.
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:412
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/492/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/890
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/734
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/734
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/734
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/734
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/900
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/891
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/891/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/891
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/891/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/891
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/891/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/891
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/891/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/492/rebuild

review: Approve (continuous-integration)
Christopher Townsend (townsend) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'python/libertine/service/operations_monitor.py'
2--- python/libertine/service/operations_monitor.py 2017-03-07 18:38:05 +0000
3+++ python/libertine/service/operations_monitor.py 2017-03-27 20:07:32 +0000
4@@ -15,6 +15,7 @@
5
6 import dbus.service
7 import threading
8+import uuid
9
10 from . import constants, download
11 from libertine import utils
12@@ -27,7 +28,7 @@
13 dbus.service.Object.__init__(self, conn=connection, object_path=constants.OPERATIONS_MONITOR_OBJECT)
14
15 def new_operation(self):
16- self._operations.append(download.Download(self.connection, hex(int(time()*10000000))[2:]))
17+ self._operations.append(download.Download(self.connection, str(uuid.uuid4().fields[-1])))
18 return self._operations[-1].id
19
20 def remove_from_connection(self, path):
21
22=== modified file 'python/libertine/service/task_dispatcher.py'
23--- python/libertine/service/task_dispatcher.py 2017-03-09 14:40:58 +0000
24+++ python/libertine/service/task_dispatcher.py 2017-03-27 20:07:32 +0000
25@@ -16,19 +16,9 @@
26 import libertine.ContainersConfig
27 from libertine.service.container import Container
28 from libertine.service.tasks import *
29-from threading import Lock
30 from libertine import utils
31
32
33-# Decorator to refresh database before making a call
34-def _refresh_config(func):
35- def wrapper(*args, **kwargs):
36- args[0]._config.refresh_database()
37- return func(*args, **kwargs)
38-
39- return wrapper
40-
41-
42 class TaskDispatcher(object):
43 def __init__(self, monitor, client):
44 self._monitor = monitor
45@@ -68,49 +58,40 @@
46
47 # Tasks (usually) run within a container
48
49- @_refresh_config
50 def search(self, container_id, query):
51 utils.get_logger().debug("dispatching search in container '%s' for package '%s'" % (container_id, query))
52 return self._find_or_create_container(container_id).search(query)
53
54- @_refresh_config
55 def app_info(self, container_id, app_id):
56 utils.get_logger().debug("dispatching app_info in container '%s' for package '%s'" % (container_id, app_id))
57 return self._find_or_create_container(container_id).app_info(app_id)
58
59- @_refresh_config
60 def install(self, container_id, package_name):
61 utils.get_logger().debug("dispatching install of package '%s' from container '%s'" % (package_name, container_id))
62 return self._find_or_create_container(container_id).install(package_name)
63
64- @_refresh_config
65 def remove(self, container_id, package_name):
66 utils.get_logger().debug("dispatching remove of package '%s' from container '%s'" % (package_name, container_id))
67 return self._find_or_create_container(container_id).remove(package_name)
68
69- @_refresh_config
70 def create(self, container_id, container_name, distro, container_type, enable_multiarch):
71 utils.get_logger().debug("dispatching create of container '%s'" % container_id)
72 return self._find_or_create_container(container_id).create(container_name, distro, container_type, enable_multiarch)
73
74- @_refresh_config
75 def destroy(self, container_id):
76 utils.get_logger().debug("dispatching destroy container '%s'" % container_id)
77 return self._find_or_create_container(container_id).destroy()
78
79- @_refresh_config
80 def update(self, container_id):
81 utils.get_logger().debug("dispatching update container '%s'" % container_id)
82 return self._find_or_create_container(container_id).update()
83
84- @_refresh_config
85 def list_app_ids(self, container_id):
86 utils.get_logger().debug("dispatching list apps ids in container '%s'" % container_id)
87 return self._find_or_create_container(container_id).list_app_ids()
88
89 # Containerless Tasks
90
91- @_refresh_config
92 def container_info(self, container_id):
93 utils.get_logger().debug("dispatching get info for container '%s'" % container_id)
94
95@@ -124,7 +105,6 @@
96
97 return task.id
98
99- @_refresh_config
100 def list(self):
101 utils.get_logger().debug("dispatching list all containers")
102
103
104=== modified file 'python/libertine/service/tasks/base_task.py'
105--- python/libertine/service/tasks/base_task.py 2017-03-09 16:02:22 +0000
106+++ python/libertine/service/tasks/base_task.py 2017-03-27 20:07:32 +0000
107@@ -66,6 +66,8 @@
108 return thread
109
110 def run(self):
111+ self._refresh_database()
112+
113 if not self._before():
114 self._monitor.finished(self._operation_id)
115 self._delayed_callback()
116@@ -73,15 +75,25 @@
117
118 if self._lock is not None:
119 with self._lock:
120+ self._refresh_database(False)
121 self._run()
122 else:
123+ self._refresh_database()
124 self._run()
125
126 if self.running:
127- self._monitor.finished(self._operation_id)
128+ self._finished()
129
130 self._delayed_callback()
131
132+ def _refresh_database(self, require_lock=True):
133+ if self._config:
134+ if require_lock and self._lock is not None:
135+ with self._lock:
136+ self._config.refresh_database()
137+ else:
138+ self._config.refresh_database()
139+
140 @abstractmethod
141 def _run(self):
142 pass
143@@ -92,6 +104,9 @@
144 def _data(self, message):
145 self._monitor.data(self._operation_id, message)
146
147+ def _finished(self):
148+ self._monitor.finished(self._operation_id)
149+
150 def _error(self, message):
151 self._monitor.error(self._operation_id, message)
152
153
154=== modified file 'python/libertine/service/tasks/create_task.py'
155--- python/libertine/service/tasks/create_task.py 2017-03-09 16:02:22 +0000
156+++ python/libertine/service/tasks/create_task.py 2017-03-27 20:07:32 +0000
157@@ -39,9 +39,10 @@
158 self._error("Creating container '%s' failed" % self._container)
159 else:
160 self._config.update_container_install_status(self._container, "ready")
161+ self._finished()
162 except RuntimeError as e:
163+ self._config.delete_container(self._container)
164 self._error(str(e))
165- self._config.delete_container(self._container)
166
167 def _before(self):
168 utils.get_logger().debug("CreateTask::_before")
169
170=== modified file 'python/libertine/service/tasks/destroy_task.py'
171--- python/libertine/service/tasks/destroy_task.py 2017-03-09 16:02:22 +0000
172+++ python/libertine/service/tasks/destroy_task.py 2017-03-27 20:07:32 +0000
173@@ -32,6 +32,7 @@
174 return
175
176 self._config.delete_container(self._container)
177+ self._finished()
178
179 def _before(self):
180 utils.get_logger().debug("CreateTask::_before")
181
182=== modified file 'python/libertine/service/tasks/install_task.py'
183--- python/libertine/service/tasks/install_task.py 2017-03-09 16:02:22 +0000
184+++ python/libertine/service/tasks/install_task.py 2017-03-27 20:07:32 +0000
185@@ -35,6 +35,7 @@
186 container = LibertineContainer(self._container, self._config, self._client)
187 if container.install_package(self._package):
188 self._config.update_package_install_status(self._container, self._package, "installed")
189+ self._finished()
190 else:
191 self._config.delete_package(self._container, self._package)
192 self._error("Package installation failed for '%s'" % self._package)
193
194=== modified file 'python/libertine/service/tasks/list_task.py'
195--- python/libertine/service/tasks/list_task.py 2017-03-07 18:38:05 +0000
196+++ python/libertine/service/tasks/list_task.py 2017-03-27 20:07:32 +0000
197@@ -25,3 +25,4 @@
198
199 def _run(self):
200 self._data(json.dumps(self._config.get_containers()))
201+ self._finished()
202
203=== modified file 'python/libertine/service/tasks/remove_task.py'
204--- python/libertine/service/tasks/remove_task.py 2017-03-09 16:02:22 +0000
205+++ python/libertine/service/tasks/remove_task.py 2017-03-27 20:07:32 +0000
206@@ -34,6 +34,7 @@
207 container = LibertineContainer(self._container, self._config, self._client)
208 if container.remove_package(self._package):
209 self._config.delete_package(self._container, self._package)
210+ self._finished()
211 else:
212 self._config.update_package_install_status(self._container, self._package, 'installed')
213 self._error("Package removal failed for '%s'" % self._package)
214
215=== modified file 'tests/integration/CMakeLists.txt'
216--- tests/integration/CMakeLists.txt 2017-03-07 18:38:05 +0000
217+++ tests/integration/CMakeLists.txt 2017-03-27 20:07:32 +0000
218@@ -1,7 +1,7 @@
219 add_test(test_libertine_service dbus-run-session -- /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/test_libertine_service.py)
220 set_tests_properties(test_libertine_service
221 PROPERTIES ENVIRONMENT
222- "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;LIBERTINE_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};")
223+ "LIBERTINE_DEBUG=2;PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};XDG_DATA_HOME=/tmp")
224
225 add_executable(
226 test_liblibertine
227
228=== modified file 'tests/integration/test_libertine_service.py'
229--- tests/integration/test_libertine_service.py 2017-03-10 16:37:59 +0000
230+++ tests/integration/test_libertine_service.py 2017-03-27 20:07:32 +0000
231@@ -42,18 +42,14 @@
232 def setUpClass(cls):
233 cls._tempdir = tempfile.TemporaryDirectory()
234
235- environ = os.environ.copy()
236- environ['XDG_DATA_HOME'] = cls._tempdir.name
237-
238- cls._process = pexpect.spawnu('libertined --debug', env=environ)
239+ os.environ['XDG_DATA_HOME'] = cls._tempdir.name
240+ cls._process = pexpect.spawnu('libertined --debug', env=os.environ.copy())
241 cls._process.logfile = sys.stdout
242
243 # give libertined enough time to start the whole process
244- verbosity = environ.get('LIBERTINE_DEBUG', '1')
245- if verbosity == '1':
246- cls._process.expect(['.+\n', pexpect.TIMEOUT], timeout=1)
247- elif environ['LIBERTINE_DEBUG'] == '2':
248- cls._process.expect(['.+\n.+\n.+\n', pexpect.TIMEOUT], timeout=1)
249+ verbosity = os.environ.get('LIBERTINE_DEBUG', '1')
250+ if verbosity != '0':
251+ cls._process.expect(['libertined ready', pexpect.TIMEOUT], timeout=5)
252
253 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
254 cls._loop = GLib.MainLoop()
255@@ -68,6 +64,7 @@
256 cls._tempdir.cleanup()
257
258 def setUp(self):
259+ os.environ['XDG_DATA_HOME'] = TestLibertineService._tempdir.name
260 self.error = None
261 self.result = None
262 self.event = threading.Event()
263@@ -95,7 +92,7 @@
264
265 def tearDown(self):
266 for signal in self.signals:
267- self._bus._clean_up_signal_match(signal)
268+ signal.remove()
269
270 def _finished_handler(self, path):
271 if self.path == path:
272@@ -114,12 +111,11 @@
273 self.event.clear()
274 self.result = None
275
276+ monitor = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_MONITOR_OBJECT)
277 self.path = func()
278
279- monitor = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_MONITOR_OBJECT)
280- if monitor.running(self.path):
281- self.event.wait(5)
282- self.assertIsNone(self.error)
283+ while monitor.running(self.path):
284+ self.event.wait(.1)
285
286 self.assertEqual('', monitor.last_error(self.path))
287 self.result = monitor.result(self.path)
288
289=== modified file 'tools/libertined'
290--- tools/libertined 2017-03-13 13:56:53 +0000
291+++ tools/libertined 2017-03-27 20:07:32 +0000
292@@ -140,7 +140,7 @@
293 config = Config()
294
295 with OutputRedirector(config):
296- utils.get_logger().info("Starting libertine service")
297+ utils.get_logger().info("Initializing libertined...")
298 loop = Loop()
299
300 try:
301@@ -156,6 +156,7 @@
302 container_control.ContainerControl(manager.connection, client)
303
304 try:
305+ utils.get_logger().info("libertined ready")
306 loop.run()
307 except KeyboardInterrupt:
308 utils.get_logger().debug("keyboard interrupt received")

Subscribers

People subscribed via source and target branches