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

Proposed by Larry Price
Status: Merged
Approved by: Christopher Townsend
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 Approve
Libertine CI Bot continuous-integration Approve
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.
Revision history for this message
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)
Revision history for this message
Christopher Townsend (townsend) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'python/libertine/service/operations_monitor.py'
--- python/libertine/service/operations_monitor.py 2017-03-07 18:38:05 +0000
+++ python/libertine/service/operations_monitor.py 2017-03-27 20:07:32 +0000
@@ -15,6 +15,7 @@
1515
16import dbus.service16import dbus.service
17import threading17import threading
18import uuid
1819
19from . import constants, download20from . import constants, download
20from libertine import utils21from libertine import utils
@@ -27,7 +28,7 @@
27 dbus.service.Object.__init__(self, conn=connection, object_path=constants.OPERATIONS_MONITOR_OBJECT)28 dbus.service.Object.__init__(self, conn=connection, object_path=constants.OPERATIONS_MONITOR_OBJECT)
2829
29 def new_operation(self):30 def new_operation(self):
30 self._operations.append(download.Download(self.connection, hex(int(time()*10000000))[2:]))31 self._operations.append(download.Download(self.connection, str(uuid.uuid4().fields[-1])))
31 return self._operations[-1].id32 return self._operations[-1].id
3233
33 def remove_from_connection(self, path):34 def remove_from_connection(self, path):
3435
=== modified file 'python/libertine/service/task_dispatcher.py'
--- python/libertine/service/task_dispatcher.py 2017-03-09 14:40:58 +0000
+++ python/libertine/service/task_dispatcher.py 2017-03-27 20:07:32 +0000
@@ -16,19 +16,9 @@
16import libertine.ContainersConfig16import libertine.ContainersConfig
17from libertine.service.container import Container17from libertine.service.container import Container
18from libertine.service.tasks import *18from libertine.service.tasks import *
19from threading import Lock
20from libertine import utils19from libertine import utils
2120
2221
23# Decorator to refresh database before making a call
24def _refresh_config(func):
25 def wrapper(*args, **kwargs):
26 args[0]._config.refresh_database()
27 return func(*args, **kwargs)
28
29 return wrapper
30
31
32class TaskDispatcher(object):22class TaskDispatcher(object):
33 def __init__(self, monitor, client):23 def __init__(self, monitor, client):
34 self._monitor = monitor24 self._monitor = monitor
@@ -68,49 +58,40 @@
6858
69 # Tasks (usually) run within a container59 # Tasks (usually) run within a container
7060
71 @_refresh_config
72 def search(self, container_id, query):61 def search(self, container_id, query):
73 utils.get_logger().debug("dispatching search in container '%s' for package '%s'" % (container_id, query))62 utils.get_logger().debug("dispatching search in container '%s' for package '%s'" % (container_id, query))
74 return self._find_or_create_container(container_id).search(query)63 return self._find_or_create_container(container_id).search(query)
7564
76 @_refresh_config
77 def app_info(self, container_id, app_id):65 def app_info(self, container_id, app_id):
78 utils.get_logger().debug("dispatching app_info in container '%s' for package '%s'" % (container_id, app_id))66 utils.get_logger().debug("dispatching app_info in container '%s' for package '%s'" % (container_id, app_id))
79 return self._find_or_create_container(container_id).app_info(app_id)67 return self._find_or_create_container(container_id).app_info(app_id)
8068
81 @_refresh_config
82 def install(self, container_id, package_name):69 def install(self, container_id, package_name):
83 utils.get_logger().debug("dispatching install of package '%s' from container '%s'" % (package_name, container_id))70 utils.get_logger().debug("dispatching install of package '%s' from container '%s'" % (package_name, container_id))
84 return self._find_or_create_container(container_id).install(package_name)71 return self._find_or_create_container(container_id).install(package_name)
8572
86 @_refresh_config
87 def remove(self, container_id, package_name):73 def remove(self, container_id, package_name):
88 utils.get_logger().debug("dispatching remove of package '%s' from container '%s'" % (package_name, container_id))74 utils.get_logger().debug("dispatching remove of package '%s' from container '%s'" % (package_name, container_id))
89 return self._find_or_create_container(container_id).remove(package_name)75 return self._find_or_create_container(container_id).remove(package_name)
9076
91 @_refresh_config
92 def create(self, container_id, container_name, distro, container_type, enable_multiarch):77 def create(self, container_id, container_name, distro, container_type, enable_multiarch):
93 utils.get_logger().debug("dispatching create of container '%s'" % container_id)78 utils.get_logger().debug("dispatching create of container '%s'" % container_id)
94 return self._find_or_create_container(container_id).create(container_name, distro, container_type, enable_multiarch)79 return self._find_or_create_container(container_id).create(container_name, distro, container_type, enable_multiarch)
9580
96 @_refresh_config
97 def destroy(self, container_id):81 def destroy(self, container_id):
98 utils.get_logger().debug("dispatching destroy container '%s'" % container_id)82 utils.get_logger().debug("dispatching destroy container '%s'" % container_id)
99 return self._find_or_create_container(container_id).destroy()83 return self._find_or_create_container(container_id).destroy()
10084
101 @_refresh_config
102 def update(self, container_id):85 def update(self, container_id):
103 utils.get_logger().debug("dispatching update container '%s'" % container_id)86 utils.get_logger().debug("dispatching update container '%s'" % container_id)
104 return self._find_or_create_container(container_id).update()87 return self._find_or_create_container(container_id).update()
10588
106 @_refresh_config
107 def list_app_ids(self, container_id):89 def list_app_ids(self, container_id):
108 utils.get_logger().debug("dispatching list apps ids in container '%s'" % container_id)90 utils.get_logger().debug("dispatching list apps ids in container '%s'" % container_id)
109 return self._find_or_create_container(container_id).list_app_ids()91 return self._find_or_create_container(container_id).list_app_ids()
11092
111 # Containerless Tasks93 # Containerless Tasks
11294
113 @_refresh_config
114 def container_info(self, container_id):95 def container_info(self, container_id):
115 utils.get_logger().debug("dispatching get info for container '%s'" % container_id)96 utils.get_logger().debug("dispatching get info for container '%s'" % container_id)
11697
@@ -124,7 +105,6 @@
124105
125 return task.id106 return task.id
126107
127 @_refresh_config
128 def list(self):108 def list(self):
129 utils.get_logger().debug("dispatching list all containers")109 utils.get_logger().debug("dispatching list all containers")
130110
131111
=== modified file 'python/libertine/service/tasks/base_task.py'
--- python/libertine/service/tasks/base_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/base_task.py 2017-03-27 20:07:32 +0000
@@ -66,6 +66,8 @@
66 return thread66 return thread
6767
68 def run(self):68 def run(self):
69 self._refresh_database()
70
69 if not self._before():71 if not self._before():
70 self._monitor.finished(self._operation_id)72 self._monitor.finished(self._operation_id)
71 self._delayed_callback()73 self._delayed_callback()
@@ -73,15 +75,25 @@
7375
74 if self._lock is not None:76 if self._lock is not None:
75 with self._lock:77 with self._lock:
78 self._refresh_database(False)
76 self._run()79 self._run()
77 else:80 else:
81 self._refresh_database()
78 self._run()82 self._run()
7983
80 if self.running:84 if self.running:
81 self._monitor.finished(self._operation_id)85 self._finished()
8286
83 self._delayed_callback()87 self._delayed_callback()
8488
89 def _refresh_database(self, require_lock=True):
90 if self._config:
91 if require_lock and self._lock is not None:
92 with self._lock:
93 self._config.refresh_database()
94 else:
95 self._config.refresh_database()
96
85 @abstractmethod97 @abstractmethod
86 def _run(self):98 def _run(self):
87 pass99 pass
@@ -92,6 +104,9 @@
92 def _data(self, message):104 def _data(self, message):
93 self._monitor.data(self._operation_id, message)105 self._monitor.data(self._operation_id, message)
94106
107 def _finished(self):
108 self._monitor.finished(self._operation_id)
109
95 def _error(self, message):110 def _error(self, message):
96 self._monitor.error(self._operation_id, message)111 self._monitor.error(self._operation_id, message)
97112
98113
=== modified file 'python/libertine/service/tasks/create_task.py'
--- python/libertine/service/tasks/create_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/create_task.py 2017-03-27 20:07:32 +0000
@@ -39,9 +39,10 @@
39 self._error("Creating container '%s' failed" % self._container)39 self._error("Creating container '%s' failed" % self._container)
40 else:40 else:
41 self._config.update_container_install_status(self._container, "ready")41 self._config.update_container_install_status(self._container, "ready")
42 self._finished()
42 except RuntimeError as e:43 except RuntimeError as e:
44 self._config.delete_container(self._container)
43 self._error(str(e))45 self._error(str(e))
44 self._config.delete_container(self._container)
4546
46 def _before(self):47 def _before(self):
47 utils.get_logger().debug("CreateTask::_before")48 utils.get_logger().debug("CreateTask::_before")
4849
=== modified file 'python/libertine/service/tasks/destroy_task.py'
--- python/libertine/service/tasks/destroy_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/destroy_task.py 2017-03-27 20:07:32 +0000
@@ -32,6 +32,7 @@
32 return32 return
3333
34 self._config.delete_container(self._container)34 self._config.delete_container(self._container)
35 self._finished()
3536
36 def _before(self):37 def _before(self):
37 utils.get_logger().debug("CreateTask::_before")38 utils.get_logger().debug("CreateTask::_before")
3839
=== modified file 'python/libertine/service/tasks/install_task.py'
--- python/libertine/service/tasks/install_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/install_task.py 2017-03-27 20:07:32 +0000
@@ -35,6 +35,7 @@
35 container = LibertineContainer(self._container, self._config, self._client)35 container = LibertineContainer(self._container, self._config, self._client)
36 if container.install_package(self._package):36 if container.install_package(self._package):
37 self._config.update_package_install_status(self._container, self._package, "installed")37 self._config.update_package_install_status(self._container, self._package, "installed")
38 self._finished()
38 else:39 else:
39 self._config.delete_package(self._container, self._package)40 self._config.delete_package(self._container, self._package)
40 self._error("Package installation failed for '%s'" % self._package)41 self._error("Package installation failed for '%s'" % self._package)
4142
=== modified file 'python/libertine/service/tasks/list_task.py'
--- python/libertine/service/tasks/list_task.py 2017-03-07 18:38:05 +0000
+++ python/libertine/service/tasks/list_task.py 2017-03-27 20:07:32 +0000
@@ -25,3 +25,4 @@
2525
26 def _run(self):26 def _run(self):
27 self._data(json.dumps(self._config.get_containers()))27 self._data(json.dumps(self._config.get_containers()))
28 self._finished()
2829
=== modified file 'python/libertine/service/tasks/remove_task.py'
--- python/libertine/service/tasks/remove_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/remove_task.py 2017-03-27 20:07:32 +0000
@@ -34,6 +34,7 @@
34 container = LibertineContainer(self._container, self._config, self._client)34 container = LibertineContainer(self._container, self._config, self._client)
35 if container.remove_package(self._package):35 if container.remove_package(self._package):
36 self._config.delete_package(self._container, self._package)36 self._config.delete_package(self._container, self._package)
37 self._finished()
37 else:38 else:
38 self._config.update_package_install_status(self._container, self._package, 'installed')39 self._config.update_package_install_status(self._container, self._package, 'installed')
39 self._error("Package removal failed for '%s'" % self._package)40 self._error("Package removal failed for '%s'" % self._package)
4041
=== modified file 'tests/integration/CMakeLists.txt'
--- tests/integration/CMakeLists.txt 2017-03-07 18:38:05 +0000
+++ tests/integration/CMakeLists.txt 2017-03-27 20:07:32 +0000
@@ -1,7 +1,7 @@
1add_test(test_libertine_service dbus-run-session -- /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/test_libertine_service.py)1add_test(test_libertine_service dbus-run-session -- /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/test_libertine_service.py)
2set_tests_properties(test_libertine_service2set_tests_properties(test_libertine_service
3 PROPERTIES ENVIRONMENT3 PROPERTIES ENVIRONMENT
4 "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;LIBERTINE_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};")4 "LIBERTINE_DEBUG=2;PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};XDG_DATA_HOME=/tmp")
55
6add_executable(6add_executable(
7 test_liblibertine7 test_liblibertine
88
=== modified file 'tests/integration/test_libertine_service.py'
--- tests/integration/test_libertine_service.py 2017-03-10 16:37:59 +0000
+++ tests/integration/test_libertine_service.py 2017-03-27 20:07:32 +0000
@@ -42,18 +42,14 @@
42 def setUpClass(cls):42 def setUpClass(cls):
43 cls._tempdir = tempfile.TemporaryDirectory()43 cls._tempdir = tempfile.TemporaryDirectory()
4444
45 environ = os.environ.copy()45 os.environ['XDG_DATA_HOME'] = cls._tempdir.name
46 environ['XDG_DATA_HOME'] = cls._tempdir.name46 cls._process = pexpect.spawnu('libertined --debug', env=os.environ.copy())
47
48 cls._process = pexpect.spawnu('libertined --debug', env=environ)
49 cls._process.logfile = sys.stdout47 cls._process.logfile = sys.stdout
5048
51 # give libertined enough time to start the whole process49 # give libertined enough time to start the whole process
52 verbosity = environ.get('LIBERTINE_DEBUG', '1')50 verbosity = os.environ.get('LIBERTINE_DEBUG', '1')
53 if verbosity == '1':51 if verbosity != '0':
54 cls._process.expect(['.+\n', pexpect.TIMEOUT], timeout=1)52 cls._process.expect(['libertined ready', pexpect.TIMEOUT], timeout=5)
55 elif environ['LIBERTINE_DEBUG'] == '2':
56 cls._process.expect(['.+\n.+\n.+\n', pexpect.TIMEOUT], timeout=1)
5753
58 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)54 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
59 cls._loop = GLib.MainLoop()55 cls._loop = GLib.MainLoop()
@@ -68,6 +64,7 @@
68 cls._tempdir.cleanup()64 cls._tempdir.cleanup()
6965
70 def setUp(self):66 def setUp(self):
67 os.environ['XDG_DATA_HOME'] = TestLibertineService._tempdir.name
71 self.error = None68 self.error = None
72 self.result = None69 self.result = None
73 self.event = threading.Event()70 self.event = threading.Event()
@@ -95,7 +92,7 @@
9592
96 def tearDown(self):93 def tearDown(self):
97 for signal in self.signals:94 for signal in self.signals:
98 self._bus._clean_up_signal_match(signal)95 signal.remove()
9996
100 def _finished_handler(self, path):97 def _finished_handler(self, path):
101 if self.path == path:98 if self.path == path:
@@ -114,12 +111,11 @@
114 self.event.clear()111 self.event.clear()
115 self.result = None112 self.result = None
116113
114 monitor = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_MONITOR_OBJECT)
117 self.path = func()115 self.path = func()
118116
119 monitor = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_MONITOR_OBJECT)117 while monitor.running(self.path):
120 if monitor.running(self.path):118 self.event.wait(.1)
121 self.event.wait(5)
122 self.assertIsNone(self.error)
123119
124 self.assertEqual('', monitor.last_error(self.path))120 self.assertEqual('', monitor.last_error(self.path))
125 self.result = monitor.result(self.path)121 self.result = monitor.result(self.path)
126122
=== modified file 'tools/libertined'
--- tools/libertined 2017-03-13 13:56:53 +0000
+++ tools/libertined 2017-03-27 20:07:32 +0000
@@ -140,7 +140,7 @@
140 config = Config()140 config = Config()
141141
142 with OutputRedirector(config):142 with OutputRedirector(config):
143 utils.get_logger().info("Starting libertine service")143 utils.get_logger().info("Initializing libertined...")
144 loop = Loop()144 loop = Loop()
145145
146 try:146 try:
@@ -156,6 +156,7 @@
156 container_control.ContainerControl(manager.connection, client)156 container_control.ContainerControl(manager.connection, client)
157157
158 try:158 try:
159 utils.get_logger().info("libertined ready")
159 loop.run()160 loop.run()
160 except KeyboardInterrupt:161 except KeyboardInterrupt:
161 utils.get_logger().debug("keyboard interrupt received")162 utils.get_logger().debug("keyboard interrupt received")

Subscribers

People subscribed via source and target branches