Merge lp:~larryprice/libertine/libertined-output into lp:libertine

Proposed by Larry Price
Status: Needs review
Proposed branch: lp:~larryprice/libertine/libertined-output
Merge into: lp:libertine
Diff against target: 1602 lines (+380/-258)
37 files modified
python/libertine/Libertine.py (+3/-4)
python/libertine/LxdContainer.py (+4/-3)
python/libertine/service/apt.py (+0/-1)
python/libertine/service/container.py (+22/-52)
python/libertine/service/download.py (+17/-21)
python/libertine/service/operations.py (+8/-8)
python/libertine/service/operations_monitor.py (+4/-0)
python/libertine/service/output_redirector.py (+67/-0)
python/libertine/service/task_dispatcher.py (+14/-26)
python/libertine/service/task_dispatcher_base.py (+49/-0)
python/libertine/service/tasks/app_info_task.py (+10/-8)
python/libertine/service/tasks/base_task.py (+51/-23)
python/libertine/service/tasks/container_info_task.py (+2/-2)
python/libertine/service/tasks/create_task.py (+13/-2)
python/libertine/service/tasks/destroy_task.py (+10/-9)
python/libertine/service/tasks/install_task.py (+26/-11)
python/libertine/service/tasks/list_app_ids_task.py (+2/-2)
python/libertine/service/tasks/list_task.py (+2/-2)
python/libertine/service/tasks/remove_task.py (+4/-3)
python/libertine/service/tasks/search_task.py (+11/-5)
python/libertine/service/tasks/update_task.py (+17/-4)
tests/integration/CMakeLists.txt (+2/-2)
tests/integration/test_libertine_service.py (+1/-0)
tests/unit/service/CMakeLists.txt (+1/-1)
tests/unit/service/tasks/test_app_info_task.py (+0/-2)
tests/unit/service/tasks/test_container_info_task.py (+0/-1)
tests/unit/service/tasks/test_create_task.py (+0/-10)
tests/unit/service/tasks/test_destroy_task.py (+0/-3)
tests/unit/service/tasks/test_install_task.py (+0/-3)
tests/unit/service/tasks/test_list_app_ids_task.py (+0/-2)
tests/unit/service/tasks/test_list_task.py (+0/-1)
tests/unit/service/tasks/test_remove_task.py (+0/-3)
tests/unit/service/tasks/test_search_task.py (+0/-1)
tests/unit/service/tasks/test_update_task.py (+0/-3)
tests/unit/service/test_container.py (+30/-30)
tests/unit/service/test_task_dispatcher.py (+10/-9)
tools/libertined (+0/-1)
To merge this branch: bzr merge lp:~larryprice/libertine/libertined-output
Reviewer Review Type Date Requested Status
Libertine CI Bot continuous-integration Needs Fixing
Libertine Developers Pending
Review via email: mp+321754@code.launchpad.net

This proposal supersedes a proposal from 2017-03-20.

Commit message

Forward task output from libertined to d-bus clients.

Description of the change

Forward task output from libertined to d-bus clients.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal

PASSED: Continuous integration, rev:468
https://jenkins.canonical.com/libertine/job/lp-libertine-ci/487/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/883
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/727
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=zesty,testname=default/727
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/727
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=zesty,testname=default/727
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/893
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/884
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/884/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/884
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=zesty/884/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/884
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/884/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/884
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=zesty/884/artifact/output/*zip*/output.zip

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

review: Approve (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

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

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

review: Approve (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

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

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

review: Approve (continuous-integration)
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
472. By Larry Price

merge

473. By Larry Price

chmod

Unmerged revisions

473. By Larry Price

chmod

472. By Larry Price

merge

471. By Larry Price

undoing po changes

470. By Larry Price

fixing test

469. By Larry Price

another merge attempt

468. By Larry Price

ok up cleanup cycle in test

467. By Larry Price

use XDG_DATA_HOME instead of HOME in OutputRedirector

466. By Larry Price

merge

465. By Larry Price

make dir tree if not exist

464. By Larry Price

undo accidents

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'python/libertine/Libertine.py'
--- python/libertine/Libertine.py 2017-03-23 19:23:20 +0000
+++ python/libertine/Libertine.py 2017-04-07 16:34:30 +0000
@@ -258,12 +258,14 @@
258258
259 return ret259 return ret
260260
261 def remove_package(self, package_name):261 def remove_package(self, package_name, no_dialog=False):
262 """262 """
263 Removes a package from the container.263 Removes a package from the container.
264264
265 :param package_name: The name of the package to be removed.265 :param package_name: The name of the package to be removed.
266 """266 """
267 if no_dialog:
268 os.environ['DEBIAN_FRONTEND'] = 'teletype'
267 if self.run_in_container(_apt_command_prefix() + " purge '" + package_name + "'") != 0:269 if self.run_in_container(_apt_command_prefix() + " purge '" + package_name + "'") != 0:
268 return False270 return False
269 return self.run_in_container(_apt_command_prefix() + "autoremove --purge") == 0271 return self.run_in_container(_apt_command_prefix() + "autoremove --purge") == 0
@@ -478,9 +480,6 @@
478 """480 """
479 try:481 try:
480 with ContainerRunning(self.container):482 with ContainerRunning(self.container):
481 if no_dialog:
482 os.environ['DEBIAN_FRONTEND'] = 'teletype'
483
484 self.containers_config.update_container_install_status(self.container_id, "removing packages")483 self.containers_config.update_container_install_status(self.container_id, "removing packages")
485 retval = self.container.remove_package(package_name)484 retval = self.container.remove_package(package_name)
486485
487486
=== modified file 'python/libertine/LxdContainer.py'
--- python/libertine/LxdContainer.py 2017-03-23 19:23:20 +0000
+++ python/libertine/LxdContainer.py 2017-04-07 16:34:30 +0000
@@ -112,7 +112,8 @@
112def lxd_container(client, container_id):112def lxd_container(client, container_id):
113 try:113 try:
114 return client.containers.get(container_id)114 return client.containers.get(container_id)
115 except pylxd.exceptions.LXDAPIException:115 except pylxd.exceptions.LXDAPIException as e:
116 utils.get_logger().error(str(e))
116 return None117 return None
117118
118119
@@ -458,8 +459,8 @@
458 _add_local_files_for_ual(self._container)459 _add_local_files_for_ual(self._container)
459 return ret460 return ret
460461
461 def remove_package(self, package_name):462 def remove_package(self, package_name, no_dialog=False):
462 ret = super().remove_package(package_name)463 ret = super().remove_package(package_name, no_dialog)
463 _remove_local_files_for_ual(self._container)464 _remove_local_files_for_ual(self._container)
464 return ret465 return ret
465466
466467
=== modified file 'python/libertine/service/apt.py'
--- python/libertine/service/apt.py 2017-01-24 18:00:57 +0000
+++ python/libertine/service/apt.py 2017-04-07 16:34:30 +0000
@@ -54,7 +54,6 @@
54 app_data["summary"] = app.versions[0].summary54 app_data["summary"] = app.versions[0].summary
55 app_data["website"] = app.versions[0].homepage55 app_data["website"] = app.versions[0].homepage
56 app_data["description"] = app.versions[0].description56 app_data["description"] = app.versions[0].description
57 app_data["package"] = app.name
5857
59 return app_data58 return app_data
6059
6160
=== modified file 'python/libertine/service/container.py'
--- python/libertine/service/container.py 2017-03-23 19:23:20 +0000
+++ python/libertine/service/container.py 2017-04-07 16:34:30 +0000
@@ -12,24 +12,23 @@
12# You should have received a copy of the GNU General Public License12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
15
16from libertine import utils
17from libertine.service.task_dispatcher_base import TaskDispatcherBase
15from libertine.service.tasks import *18from libertine.service.tasks import *
16from libertine import utils19from multiprocessing import Lock
17from threading import Lock
1820
19if not utils.is_snap_environment():21if not utils.is_snap_environment():
20 from libertine.service import apt22 from libertine.service import apt
2123
2224
23class Container(object):25class Container(TaskDispatcherBase):
24 def __init__(self, container_id, config, monitor, client, callback):26 def __init__(self, container_id, config, monitor, client, callback):
27 super().__init__(monitor, client)
25 self._id = container_id28 self._id = container_id
26 self._config = config29 self._config = config
27 self._monitor = monitor
28 self._client = client
29 self._callback = callback30 self._callback = callback
30
31 self._lock = Lock()31 self._lock = Lock()
32 self._tasks = []
3332
34 if utils.is_snap_environment():33 if utils.is_snap_environment():
35 utils.get_logger().warning(utils._("Using AptCache not currently supported in snap environment"))34 utils.get_logger().warning(utils._("Using AptCache not currently supported in snap environment"))
@@ -37,13 +36,9 @@
37 else:36 else:
38 self._cache = apt.AptCache(self.id)37 self._cache = apt.AptCache(self.id)
3938
40 def _cleanup_task(self, task):39 def _cleanup(self):
41 utils.get_logger().debug("cleaning up tasks for container '%s'" % self.id)40 super()._cleanup()
4241 if not self._tasks:
43 if task in self._tasks:
44 self._tasks.remove(task)
45
46 if len(self._tasks) == 0:
47 self._callback(self)42 self._callback(self)
4843
49 @property44 @property
@@ -54,7 +49,7 @@
54 def tasks(self):49 def tasks(self):
55 return [task.id for task in self._tasks if task.running]50 return [task.id for task in self._tasks if task.running]
5651
57 def install(self, package_name):52 def install(self, package_name, update_cache):
58 utils.get_logger().debug("Install package '%s' from container '%s'" % (package_name, self.id))53 utils.get_logger().debug("Install package '%s' from container '%s'" % (package_name, self.id))
5954
60 tasks = [t for t in self._tasks if t.matches(package_name, InstallTask) and t.running]55 tasks = [t for t in self._tasks if t.matches(package_name, InstallTask) and t.running]
@@ -62,10 +57,8 @@
62 utils.get_logger().debug("Install already in progress for '%s':'%s'" % (package_name, self.id))57 utils.get_logger().debug("Install already in progress for '%s':'%s'" % (package_name, self.id))
63 return tasks[0].id58 return tasks[0].id
6459
65 task = InstallTask(package_name, self.id, self._config, self._lock, self._monitor, self._client, self._cleanup_task)60 return self._add_task(InstallTask(package_name, self.id, update_cache, self._config,
66 self._tasks.append(task)61 self._lock, self._monitor, self._client))
67 task.start()
68 return task.id
6962
70 def remove(self, package_name):63 def remove(self, package_name):
71 utils.get_logger().debug("Remove package '%s' from container '%s'" % (package_name, self.id))64 utils.get_logger().debug("Remove package '%s' from container '%s'" % (package_name, self.id))
@@ -75,10 +68,7 @@
75 utils.get_logger().debug("Remove already in progress for '%s':'%s'" % (package_name, self.id))68 utils.get_logger().debug("Remove already in progress for '%s':'%s'" % (package_name, self.id))
76 return tasks[0].id69 return tasks[0].id
7770
78 task = RemoveTask(package_name, self.id, self._config, self._lock, self._monitor, self._client, self._cleanup_task)71 return self._add_task(RemoveTask(package_name, self.id, self._config, self._lock, self._monitor, self._client))
79 self._tasks.append(task)
80 task.start()
81 return task.id
8272
83 def create(self, container_name, distro, container_type, enable_multiarch):73 def create(self, container_name, distro, container_type, enable_multiarch):
84 utils.get_logger().debug("Create container with ID '%s'" % self.id)74 utils.get_logger().debug("Create container with ID '%s'" % self.id)
@@ -88,13 +78,10 @@
88 utils.get_logger().debug("Create already in progress for '%s'" % self.id)78 utils.get_logger().debug("Create already in progress for '%s'" % self.id)
89 return tasks[0].id79 return tasks[0].id
9080
91 task = CreateTask(self.id, container_name, distro, container_type, enable_multiarch,81 return self._add_task(CreateTask(self.id, container_name, distro, container_type, enable_multiarch,
92 self._config, self._lock, self._monitor, self._client, self._cleanup_task)82 self._config, self._lock, self._monitor, self._client))
93 self._tasks.append(task)
94 task.start()
95 return task.id
9683
97 def destroy(self):84 def destroy(self, force):
98 utils.get_logger().debug("Destroy container with ID '%s'" % self.id)85 utils.get_logger().debug("Destroy container with ID '%s'" % self.id)
9986
100 tasks = [t for t in self._tasks if t.matches(self.id, DestroyTask) and t.running]87 tasks = [t for t in self._tasks if t.matches(self.id, DestroyTask) and t.running]
@@ -102,10 +89,7 @@
102 utils.get_logger().debug("Destroy already in progress for '%s'" % self.id)89 utils.get_logger().debug("Destroy already in progress for '%s'" % self.id)
103 return tasks[0].id90 return tasks[0].id
10491
105 task = DestroyTask(self.id, self._config, self._lock, self._monitor, self._client, self._cleanup_task)92 return self._add_task(DestroyTask(self.id, self._config, force, self._lock, self._monitor, self._client))
106 self._tasks.append(task)
107 task.start()
108 return task.id
10993
110 def update(self):94 def update(self):
111 utils.get_logger().debug("Update container with ID '%s'" % self.id)95 utils.get_logger().debug("Update container with ID '%s'" % self.id)
@@ -115,21 +99,14 @@
115 utils.get_logger().debug("Update already in progress for '%s'" % self.id)99 utils.get_logger().debug("Update already in progress for '%s'" % self.id)
116 return tasks[0].id100 return tasks[0].id
117101
118 task = UpdateTask(self.id, self._config, self._lock, self._monitor, self._client, self._cleanup_task)102 return self._add_task(UpdateTask(self.id, self._config, self._lock, self._monitor, self._client))
119 self._tasks.append(task)
120 task.start()
121 return task.id
122103
123 # Tasks which don't require starting/stopping the container104 # Tasks which don't require starting/stopping the container
124105
125 def list_app_ids(self):106 def list_app_ids(self):
126 utils.get_logger().debug("List all app ids in container '%s'" % self.id)107 utils.get_logger().debug("List all app ids in container '%s'" % self.id)
127108
128 task = ListAppIdsTask(self.id, self._config, self._monitor, self._client, self._cleanup_task)109 return self._add_task(ListAppIdsTask(self.id, self._config, self._monitor, self._client))
129
130 self._tasks.append(task)
131 task.start()
132 return task.id
133110
134 def search(self, query):111 def search(self, query):
135 utils.get_logger().debug("search container '%s' for package '%s'" % (self.id, query))112 utils.get_logger().debug("search container '%s' for package '%s'" % (self.id, query))
@@ -137,11 +114,7 @@
137 if utils.is_snap_environment():114 if utils.is_snap_environment():
138 raise Exception("This operation is not currently supported within the snap")115 raise Exception("This operation is not currently supported within the snap")
139116
140 task = SearchTask(self.id, self._cache, query, self._monitor, self._cleanup_task)117 return self._add_task(SearchTask(self.id, self._cache, query, self._config, self._monitor, self._client))
141 self._tasks.append(task)
142 task.start()
143
144 return task.id
145118
146 def app_info(self, package_name):119 def app_info(self, package_name):
147 utils.get_logger().debug("get info for package '%s' in container '%s'" % (package_name, self.id))120 utils.get_logger().debug("get info for package '%s' in container '%s'" % (package_name, self.id))
@@ -150,8 +123,5 @@
150 raise Exception("This operation is not currently supported within the snap")123 raise Exception("This operation is not currently supported within the snap")
151124
152 related_task_ids = [t.id for t in self._tasks if t.package == package_name and t.running]125 related_task_ids = [t.id for t in self._tasks if t.package == package_name and t.running]
153 task = AppInfoTask(self.id, self._cache, package_name, related_task_ids, self._config, self._monitor, self._cleanup_task)126 return self._add_task(AppInfoTask(self.id, self._cache, package_name, related_task_ids,
154127 self._config, self._monitor, self._client))
155 self._tasks.append(task)
156 task.start()
157 return task.id
158128
=== modified file 'python/libertine/service/download.py'
--- python/libertine/service/download.py 2017-03-07 18:38:05 +0000
+++ python/libertine/service/download.py 2017-04-07 16:34:30 +0000
@@ -14,7 +14,7 @@
1414
1515
16import dbus.service16import dbus.service
17import threading17import multiprocessing
1818
19from . import constants19from . import constants
20from libertine import utils20from libertine import utils
@@ -23,39 +23,35 @@
2323
24class Download(dbus.service.Object):24class Download(dbus.service.Object):
25 def __init__(self, connection, id):25 def __init__(self, connection, id):
26 self._finished = False26 self._finished = multiprocessing.Event()
27 self._result = ''27 self._result = multiprocessing.SimpleQueue()
28 self._error = ''28 self._error = multiprocessing.SimpleQueue()
29 dbus.service.Object.__init__(self, conn=connection, object_path=(constants.DOWNLOAD_OBJECT % id))29 dbus.service.Object.__init__(self, conn=connection, object_path=(constants.DOWNLOAD_OBJECT % id))
3030
31 # Disabled until something requires the Download interface
32 # self.emit_processing()
33
34 # This is currently how services using the Ubuntu SDK to show progress
35 # determine whether or not an operation is running.
36 def emit_processing(self):
37 if not self.done:
38 self.processing(self.id)
39 threading.Timer(0.5, self.emit_processing).start()
40
41 @property31 @property
42 def id(self):32 def id(self):
43 return self._object_path33 return self._object_path
4434
45 @property35 @property
46 def done(self):36 def done(self):
47 return self._finished37 return self._finished.is_set()
4838
49 @property39 @property
50 def result(self):40 def result(self):
51 return self._result.strip()41 if self._result.empty():
42 return ''
43
44 return self._result.get()
5245
53 @property46 @property
54 def last_error(self):47 def last_error(self):
55 return self._error48 if self._error.empty():
49 return ''
50
51 return self._error.get()
5652
57 def data(self, message):53 def data(self, message):
58 self._result += message + '\n'54 self._result.put(message)
5955
60 # Signals to satisfy the download interface56 # Signals to satisfy the download interface
6157
@@ -66,7 +62,7 @@
66 @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o')62 @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o')
67 def finished(self, path):63 def finished(self, path):
68 utils.get_logger().debug("emit finished('%s')" % path)64 utils.get_logger().debug("emit finished('%s')" % path)
69 self._finished = True65 self._finished.set()
7066
71 @dbus.service.signal(constants.DOWNLOAD_INTERFACE)67 @dbus.service.signal(constants.DOWNLOAD_INTERFACE)
72 def progress(self, received, total):68 def progress(self, received, total):
@@ -75,5 +71,5 @@
75 @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='s')71 @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='s')
76 def error(self, message):72 def error(self, message):
77 utils.get_logger().error("emit error(%s)" % message)73 utils.get_logger().error("emit error(%s)" % message)
78 self._error = message74 self._error.put(message)
79 self._finished = True75 self._finished.set()
8076
=== modified file 'python/libertine/service/operations.py'
--- python/libertine/service/operations.py 2017-03-09 14:40:58 +0000
+++ python/libertine/service/operations.py 2017-04-07 16:34:30 +0000
@@ -72,11 +72,11 @@
72 return self._dispatcher.create(container_id, container_name, distro, container_type, enable_multiarch)72 return self._dispatcher.create(container_id, container_name, distro, container_type, enable_multiarch)
7373
74 @dbus.service.method(constants.OPERATIONS_INTERFACE,74 @dbus.service.method(constants.OPERATIONS_INTERFACE,
75 in_signature='s',75 in_signature='sb',
76 out_signature='o')76 out_signature='o')
77 def destroy(self, container_id):77 def destroy(self, container_id, force=False):
78 utils.get_logger().debug("destroy('{}')".format(container_id))78 utils.get_logger().debug("destroy('{}', {})".format(container_id, force))
79 return self._dispatcher.destroy(container_id)79 return self._dispatcher.destroy(container_id, force)
8080
81 @dbus.service.method(constants.OPERATIONS_INTERFACE,81 @dbus.service.method(constants.OPERATIONS_INTERFACE,
82 in_signature='s',82 in_signature='s',
@@ -86,11 +86,11 @@
86 return self._dispatcher.update(container_id)86 return self._dispatcher.update(container_id)
8787
88 @dbus.service.method(constants.OPERATIONS_INTERFACE,88 @dbus.service.method(constants.OPERATIONS_INTERFACE,
89 in_signature='ss',89 in_signature='ssb',
90 out_signature='o')90 out_signature='o')
91 def install(self, container_id, package_name):91 def install(self, container_id, package_name, update_cache=False):
92 utils.get_logger().debug("install('%s', '%s')" % (container_id, package_name))92 utils.get_logger().debug("install('{}', '{}', '{}')".format(container_id, package_name, update_cache))
93 return self._dispatcher.install(container_id, package_name)93 return self._dispatcher.install(container_id, package_name, update_cache)
9494
95 @dbus.service.method(constants.OPERATIONS_INTERFACE,95 @dbus.service.method(constants.OPERATIONS_INTERFACE,
96 in_signature='ss',96 in_signature='ss',
9797
=== modified file 'python/libertine/service/operations_monitor.py'
--- python/libertine/service/operations_monitor.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/operations_monitor.py 2017-04-07 16:34:30 +0000
@@ -68,6 +68,10 @@
68 if op:68 if op:
69 op.data(message)69 op.data(message)
7070
71 @dbus.service.signal(constants.OPERATIONS_MONITOR_INTERFACE, signature='os')
72 def output(self, path, message):
73 utils.get_logger().debug(message)
74
71 @dbus.service.method(constants.OPERATIONS_MONITOR_INTERFACE, in_signature='o', out_signature='b')75 @dbus.service.method(constants.OPERATIONS_MONITOR_INTERFACE, in_signature='o', out_signature='b')
72 def running(self, path):76 def running(self, path):
73 op = self._operation(path)77 op = self._operation(path)
7478
=== added file 'python/libertine/service/output_redirector.py'
--- python/libertine/service/output_redirector.py 1970-01-01 00:00:00 +0000
+++ python/libertine/service/output_redirector.py 2017-04-07 16:34:30 +0000
@@ -0,0 +1,67 @@
1# Copyright 2017 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 3 of the License.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15
16import os
17import sys
18
19from libertine import utils
20
21
22class OutputRedirector(object):
23 def __init__(self, ident, cleanup=True):
24 self.cleanup = cleanup
25
26 if utils.is_snap_environment():
27 self.cache_path = '%s/.cache/libertined' % os.environ['SNAP_USER_COMMON']
28 else:
29 self.cache_path = os.path.join(os.getenv(('XDG_DATA_HOME'), os.getenv('HOME')), '.cache/libertined')
30
31 self.path = '{}/{}.log'.format(self.cache_path, ident)
32 self._output_file = None
33 self._copied_stdout = None
34 self._copied_stderr = None
35
36 def _fileno(self, file_or_fd):
37 return getattr(file_or_fd, 'fileno', lambda: file_or_fd)()
38
39 def _do_redirect(self, stream):
40 fd = self._fileno(stream)
41 copied_stream = os.fdopen(os.dup(fd), 'wb')
42 stream.flush()
43 os.dup2(self._fileno(self._output_file), fd)
44 return copied_stream, fd
45
46 def _undo_redirect(self, stream, stream_fd, copied_stream):
47 stream.flush()
48 os.dup2(copied_stream.fileno(), stream_fd)
49 copied_stream.close()
50
51 def __enter__(self):
52 os.makedirs(self.cache_path, exist_ok=True)
53 self._output_file = open(self.path, 'w')
54 self._copied_stdout, self.stdout_fd = self._do_redirect(sys.stdout)
55 self._copied_stderr, self.stderr_fd = self._do_redirect(sys.stderr)
56
57 return self
58
59 def __exit__(self, type, value, tb):
60 if self._copied_stdout and self.stdout_fd:
61 self._undo_redirect(sys.stdout, self.stdout_fd, self._copied_stdout)
62 if self._copied_stderr and self.stderr_fd:
63 self._undo_redirect(sys.stderr, self.stderr_fd, self._copied_stderr)
64 if self._output_file:
65 self._output_file.close()
66 if self.cleanup and os.path.exists(self.path):
67 os.remove(self.path)
068
=== modified file 'python/libertine/service/task_dispatcher.py'
--- python/libertine/service/task_dispatcher.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/task_dispatcher.py 2017-04-07 16:34:30 +0000
@@ -14,25 +14,20 @@
1414
1515
16import libertine.ContainersConfig16import libertine.ContainersConfig
17
18from libertine import utils
17from libertine.service.container import Container19from libertine.service.container import Container
20from libertine.service.task_dispatcher_base import TaskDispatcherBase
18from libertine.service.tasks import *21from libertine.service.tasks import *
19from libertine import utils22from multiprocessing import Lock
2023
2124
22class TaskDispatcher(object):25class TaskDispatcher(TaskDispatcherBase):
23 def __init__(self, monitor, client):26 def __init__(self, monitor, client):
24 self._monitor = monitor27 super().__init__(monitor, client)
25 self._client = client
26 self._config = libertine.ContainersConfig.ContainersConfig()28 self._config = libertine.ContainersConfig.ContainersConfig()
27 self._containerless_tasks = []
28 self._tasks = []
29 self._containers = []29 self._containers = []
3030
31 def _cleanup_task(self, task):
32 utils.get_logger().debug("cleaning up containerless task '%s'" % task.id)
33 if task in self._tasks:
34 self._tasks.remove(task)
35
36 def _cleanup_container(self, container):31 def _cleanup_container(self, container):
37 utils.get_logger().debug("cleaning up container '%s'" % container.id)32 utils.get_logger().debug("cleaning up container '%s'" % container.id)
38 if container in self._containers:33 if container in self._containers:
@@ -66,9 +61,9 @@
66 utils.get_logger().debug("dispatching app_info in container '%s' for package '%s'" % (container_id, app_id))61 utils.get_logger().debug("dispatching app_info in container '%s' for package '%s'" % (container_id, app_id))
67 return self._find_or_create_container(container_id).app_info(app_id)62 return self._find_or_create_container(container_id).app_info(app_id)
6863
69 def install(self, container_id, package_name):64 def install(self, container_id, package_name, update_cache):
70 utils.get_logger().debug("dispatching install of package '%s' from container '%s'" % (package_name, container_id))65 utils.get_logger().debug("dispatching install of package '%s' from container '%s'" % (package_name, container_id))
71 return self._find_or_create_container(container_id).install(package_name)66 return self._find_or_create_container(container_id).install(package_name, update_cache)
7267
73 def remove(self, container_id, package_name):68 def remove(self, container_id, package_name):
74 utils.get_logger().debug("dispatching remove of package '%s' from container '%s'" % (package_name, container_id))69 utils.get_logger().debug("dispatching remove of package '%s' from container '%s'" % (package_name, container_id))
@@ -78,9 +73,9 @@
78 utils.get_logger().debug("dispatching create of container '%s'" % container_id)73 utils.get_logger().debug("dispatching create of container '%s'" % container_id)
79 return self._find_or_create_container(container_id).create(container_name, distro, container_type, enable_multiarch)74 return self._find_or_create_container(container_id).create(container_name, distro, container_type, enable_multiarch)
8075
81 def destroy(self, container_id):76 def destroy(self, container_id, force):
82 utils.get_logger().debug("dispatching destroy container '%s'" % container_id)77 utils.get_logger().debug("dispatching destroy container '%s'" % container_id)
83 return self._find_or_create_container(container_id).destroy()78 return self._find_or_create_container(container_id).destroy(force)
8479
85 def update(self, container_id):80 def update(self, container_id):
86 utils.get_logger().debug("dispatching update container '%s'" % container_id)81 utils.get_logger().debug("dispatching update container '%s'" % container_id)
@@ -99,17 +94,10 @@
99 container = self._find_container(container_id)94 container = self._find_container(container_id)
100 if container is not None:95 if container is not None:
101 related_task_ids = container.tasks96 related_task_ids = container.tasks
102 task = ContainerInfoTask(container_id, related_task_ids, self._config, self._monitor, self._cleanup_task)
103 self._tasks.append(task)
104 task.start()
10597
106 return task.id98 return self._add_task(ContainerInfoTask(container_id, related_task_ids, self._config, self._monitor))
10799
108 def list(self):100 def list(self):
109 utils.get_logger().debug("dispatching list all containers")101 utils.get_logger().debug("dispatching list all containers")
110102
111 task = ListTask(self._config, self._monitor, self._cleanup_task)103 return self._add_task(ListTask(self._config, self._monitor))
112 self._tasks.append(task)
113 task.start()
114
115 return task.id
116104
=== added file 'python/libertine/service/task_dispatcher_base.py'
--- python/libertine/service/task_dispatcher_base.py 1970-01-01 00:00:00 +0000
+++ python/libertine/service/task_dispatcher_base.py 2017-04-07 16:34:30 +0000
@@ -0,0 +1,49 @@
1# Copyright 2017 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; version 3 of the License.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15
16import multiprocessing
17import os
18
19from libertine import utils
20from threading import Timer
21
22
23class TaskDispatcherBase(object):
24 def __init__(self, monitor, client):
25 self._monitor = monitor
26 self._client = client
27 self._tasks = []
28
29 self._cleanup_cycle = 1
30 if os.getenv("LIBERTINED_TESTING", False):
31 self._cleanup_cycle = 0.1
32
33 def _cleanup(self):
34 for task in [task for task in self._tasks if task.should_delete]:
35 utils.get_logger().debug("Cleaning up task '{}'".format(task.id))
36 task.thread.join()
37 self._monitor.remove_from_connection(task.id)
38 self._tasks.remove(task)
39
40 if len(self._tasks) > 0:
41 Timer(self._cleanup_cycle, self._cleanup).start()
42
43 def _add_task(self, task):
44 self._tasks.append(task)
45 task.start()
46 if len(self._tasks) == 1:
47 Timer(self._cleanup_cycle, self._cleanup).start()
48
49 return task.id
050
=== modified file 'python/libertine/service/tasks/app_info_task.py'
--- python/libertine/service/tasks/app_info_task.py 2017-03-07 20:56:42 +0000
+++ python/libertine/service/tasks/app_info_task.py 2017-04-07 16:34:30 +0000
@@ -13,22 +13,24 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16from .base_task import BaseTask16from .base_task import ContainerBaseTask
17from libertine import utils17from libertine import utils
1818
1919
20class AppInfoTask(BaseTask):20class AppInfoTask(ContainerBaseTask):
21 def __init__(self, container_id, cache, app_id, tasks, config, monitor, callback):21 def __init__(self, container_id, cache, app_id, tasks, config, monitor, client):
22 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, callback=callback)22 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, client=client)
23 self._cache = cache23 self._cache = cache
24 self._app_id = app_id24 self._app_id = app_id
25 self._tasks = tasks25 self._tasks = tasks
2626
27 def _run(self):27 def _run(self):
28 app = self._cache.app_info(self._app_id)28 app = {}
29 if app == {}:29 if self._cache:
30 self._error("Could not find app info for '%s' in container '%s'" % (self._app_id, self._container))30 app = self._cache.app_info(self._app_id)
31 return31 if app == {}:
32 self._error("Could not find app info for '%s' in container '%s'" % (self._app_id, self._container))
33 return
3234
33 app['status'] = self._config.get_package_install_status(self._container, app['package']) or ''35 app['status'] = self._config.get_package_install_status(self._container, app['package']) or ''
34 app['task_ids'] = self._tasks36 app['task_ids'] = self._tasks
3537
=== modified file 'python/libertine/service/tasks/base_task.py'
--- python/libertine/service/tasks/base_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/base_task.py 2017-04-07 16:34:30 +0000
@@ -13,9 +13,13 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16import threading16import multiprocessing
17import os
18import time
1719
18from abc import ABCMeta, abstractmethod20from abc import ABCMeta, abstractmethod
21from libertine import utils
22from libertine.service import output_redirector
1923
2024
21class BaseTask(metaclass=ABCMeta):25class BaseTask(metaclass=ABCMeta):
@@ -25,14 +29,14 @@
25 in a separate thread. Override _before to implement pre-execution actions29 in a separate thread. Override _before to implement pre-execution actions
26 without locking; if _before returns False, _run will not be executed.30 without locking; if _before returns False, _run will not be executed.
27 """31 """
28 def __init__(self, lock, container_id, config, monitor, callback):32 def __init__(self, lock, container_id, config, monitor):
29 self._lock = lock33 self._lock = lock
30 self._container = container_id34 self._container = container_id
31 self._config = config35 self._config = config
32 self._callback = callback36 self._finished_at = multiprocessing.SimpleQueue()
33 self._monitor = monitor37 self._monitor = monitor
34 self._operation_id = None38 self._operation_id = None
35 self._instant_callback = False # for testing39 self._delete_at = None
3640
37 def matches(self, container, klass):41 def matches(self, container, klass):
38 return self._container == container and self.__class__ == klass42 return self._container == container and self.__class__ == klass
@@ -53,38 +57,62 @@
53 def running(self):57 def running(self):
54 return not self._monitor.done(self._operation_id)58 return not self._monitor.done(self._operation_id)
5559
56 def _delayed_callback(self):60 @property
57 if self._instant_callback:61 def should_delete(self):
58 self._callback(self)62 if not self._finished_at.empty():
59 else:63 self._delete_at = self._finished_at.get()
60 threading.Timer(10, lambda: (self._monitor.remove_from_connection(self._operation_id), self._callback(self))).start()64 if not os.getenv("LIBERTINED_TESTING"):
65 self._delete_at += 5
66
67 if self._delete_at:
68 return self._delete_at < time.time()
69
70 return False
71
72 def _finish(self):
73 self._finished_at.put(time.time())
6174
62 def start(self):75 def start(self):
63 self._operation_id = self._monitor.new_operation()76 self._operation_id = self._monitor.new_operation()
64 thread = threading.Thread(target=self.run)77 self.thread = multiprocessing.Process(target=self.run)
65 thread.start()78 self.thread.start()
66 return thread79 return self.thread
80
81 def watch_file(self, finished, path):
82 with open(path, 'rb') as thefile:
83 thefile.seek(0, 2)
84 while not finished.is_set():
85 finished.wait(0.1)
86 line = thefile.readline().decode('utf-8').rstrip()
87 while line:
88 self._monitor.output(self._operation_id, message)
89 line = thefile.readline().decode('utf-8').rstrip()
6790
68 def run(self):91 def run(self):
69 self._refresh_database()92 self._refresh_database()
7093
71 if not self._before():94 if not self._before():
72 self._monitor.finished(self._operation_id)95 self._monitor.finished(self._operation_id)
73 self._delayed_callback()96 self._finish()
74 return97 return
7598
76 if self._lock is not None:99 with output_redirector.OutputRedirector(self._operation_id.split("/")[-1]) as redirector:
77 with self._lock:100 end_watch = multiprocessing.Event()
78 self._refresh_database(False)101 multiprocessing.Process(target=self.watch_file, args=(end_watch, redirector.path)).start()
102 if self._lock is not None:
103 with self._lock:
104 self._refresh_database(False)
105 self._run()
106 else:
107 self._refresh_database()
79 self._run()108 self._run()
80 else:109
81 self._refresh_database()110 end_watch.set()
82 self._run()
83111
84 if self.running:112 if self.running:
85 self._finished()113 self._monitor.finished(self._operation_id)
86114
87 self._delayed_callback()115 self._finish()
88116
89 def _refresh_database(self, require_lock=True):117 def _refresh_database(self, require_lock=True):
90 if self._config:118 if self._config:
@@ -112,6 +140,6 @@
112140
113141
114class ContainerBaseTask(BaseTask):142class ContainerBaseTask(BaseTask):
115 def __init__(self, lock, container_id, config, monitor, client, callback):143 def __init__(self, lock, container_id, config, monitor, client):
116 super().__init__(lock=lock, container_id=container_id, config=config, monitor=monitor, callback=callback)144 super().__init__(lock=lock, container_id=container_id, config=config, monitor=monitor)
117 self._client = client145 self._client = client
118146
=== modified file 'python/libertine/service/tasks/container_info_task.py'
--- python/libertine/service/tasks/container_info_task.py 2017-03-06 19:50:12 +0000
+++ python/libertine/service/tasks/container_info_task.py 2017-04-07 16:34:30 +0000
@@ -20,8 +20,8 @@
2020
2121
22class ContainerInfoTask(BaseTask):22class ContainerInfoTask(BaseTask):
23 def __init__(self, container_id, tasks, config, monitor, callback):23 def __init__(self, container_id, tasks, config, monitor):
24 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, callback=callback)24 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor)
25 self._tasks = tasks25 self._tasks = tasks
2626
27 def _run(self):27 def _run(self):
2828
=== modified file 'python/libertine/service/tasks/create_task.py'
--- python/libertine/service/tasks/create_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/create_task.py 2017-04-07 16:34:30 +0000
@@ -13,6 +13,8 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16import re
17
16from .base_task import ContainerBaseTask18from .base_task import ContainerBaseTask
17from libertine import LibertineContainer, utils19from libertine import LibertineContainer, utils
18from libertine.HostInfo import HostInfo20from libertine.HostInfo import HostInfo
@@ -20,9 +22,9 @@
2022
21class CreateTask(ContainerBaseTask):23class CreateTask(ContainerBaseTask):
22 def __init__(self, container_id, container_name, distro, container_type, enable_multiarch,24 def __init__(self, container_id, container_name, distro, container_type, enable_multiarch,
23 config, lock, monitor, client, callback):25 config, lock, monitor, client):
24 super().__init__(lock=lock, container_id=container_id, config=config,26 super().__init__(lock=lock, container_id=container_id, config=config,
25 monitor=monitor, client=client, callback=callback)27 monitor=monitor, client=client)
26 self._name = container_name28 self._name = container_name
27 self._distro = distro29 self._distro = distro
28 self._type = container_type30 self._type = container_type
@@ -39,6 +41,7 @@
39 self._error("Creating container '%s' failed" % self._container)41 self._error("Creating container '%s' failed" % self._container)
40 else:42 else:
41 self._config.update_container_install_status(self._container, "ready")43 self._config.update_container_install_status(self._container, "ready")
44 utils.refresh_libertine_scope()
42 self._finished()45 self._finished()
43 except RuntimeError as e:46 except RuntimeError as e:
44 self._config.delete_container(self._container)47 self._config.delete_container(self._container)
@@ -50,6 +53,10 @@
50 self._error("Container '%s' already exists" % self._container)53 self._error("Container '%s' already exists" % self._container)
51 return False54 return False
5255
56 if re.match("^[a-z0-9][a-z0-9+.-]+$", self._container) is None:
57 self._error("Container id '%s' invalid. ID must be of form ([a-z0-9][a-z0-9+.-]+)." % self._container)
58 return False
59
53 info = HostInfo()60 info = HostInfo()
54 if not self._distro:61 if not self._distro:
55 self._distro = info.get_host_distro_release()62 self._distro = info.get_host_distro_release()
@@ -72,6 +79,10 @@
7279
73 if self._multiarch:80 if self._multiarch:
74 self._config.update_container_multiarch_support(self._container, 'enabled')81 self._config.update_container_multiarch_support(self._container, 'enabled')
82 else:
83 self._config.update_container_multiarch_support(self._container, 'disabled')
84
85 self._config.update_container_locale(self._container, info.get_host_locale())
7586
76 self._config.update_container_install_status(self._container, 'installing')87 self._config.update_container_install_status(self._container, 'installing')
77 return True88 return True
7889
=== modified file 'python/libertine/service/tasks/destroy_task.py'
--- python/libertine/service/tasks/destroy_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/destroy_task.py 2017-04-07 16:34:30 +0000
@@ -18,27 +18,28 @@
1818
1919
20class DestroyTask(ContainerBaseTask):20class DestroyTask(ContainerBaseTask):
21 def __init__(self, container_id, config, lock, monitor, client, callback):21 def __init__(self, container_id, config, force, lock, monitor, client):
22 super().__init__(lock=lock, container_id=container_id, config=config,22 super().__init__(lock=lock, container_id=container_id, config=config,
23 monitor=monitor, client=client, callback=callback)23 monitor=monitor, client=client)
24 self._force = force
2425
25 def _run(self):26 def _run(self):
26 utils.get_logger().debug("Destroying container '%s'" % self._container)27 utils.get_logger().debug("Destroying container '%s'" % self._container)
2728
28 container = LibertineContainer(self._container, self._config, self._client)29 container = LibertineContainer(self._container, self._config, self._client)
29 if not container.destroy_libertine_container():30 if not container.destroy_libertine_container(self._force):
30 self._error("Destroying container '%s' failed" % self._container)31 self._error("Destroying container '%s' failed" % self._container)
31 self._config.update_container_install_status(self._container, "ready")32 self._config.update_container_install_status(self._container, self._fallback)
32 return33 return
3334
35 self._config.update_container_install_status(self._container, "removed")
34 self._config.delete_container(self._container)36 self._config.delete_container(self._container)
35 self._finished()37 self._finished()
3638
39 utils.refresh_libertine_scope()
40
37 def _before(self):41 def _before(self):
38 utils.get_logger().debug("CreateTask::_before")42 utils.get_logger().debug("DestroyTask::_before")
39 if self._config._get_value_by_key(self._container, 'installStatus') != 'ready':43 self._fallback = self._config.get_container_install_status(self._container)
40 self._error("Container '%s' does not exist" % self._container)
41 return False
42
43 self._config.update_container_install_status(self._container, 'removing')44 self._config.update_container_install_status(self._container, 'removing')
44 return True45 return True
4546
=== modified file 'python/libertine/service/tasks/install_task.py'
--- python/libertine/service/tasks/install_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/install_task.py 2017-04-07 16:34:30 +0000
@@ -13,15 +13,19 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16import os
17
16from .base_task import ContainerBaseTask18from .base_task import ContainerBaseTask
17from libertine import LibertineContainer, utils19from libertine import LibertineContainer, utils
1820
1921
20class InstallTask(ContainerBaseTask):22class InstallTask(ContainerBaseTask):
21 def __init__(self, package_name, container_id, config, lock, monitor, client, callback):23 def __init__(self, package_name, container_id, update_cache, config, lock, monitor, client):
22 super().__init__(lock=lock, container_id=container_id, config=config,24 super().__init__(lock=lock, container_id=container_id, config=config,
23 monitor=monitor, client=client, callback=callback)25 monitor=monitor, client=client)
24 self._package = package_name26 self._package = package_name
27 self._package_name = package_name
28 self._update_cache = update_cache
2529
26 def matches(self, package, klass):30 def matches(self, package, klass):
27 return self._package == package and self.__class__ == klass31 return self._package == package and self.__class__ == klass
@@ -33,19 +37,30 @@
33 def _run(self):37 def _run(self):
34 utils.get_logger().debug("Installing package '%s'" % self._package)38 utils.get_logger().debug("Installing package '%s'" % self._package)
35 container = LibertineContainer(self._container, self._config, self._client)39 container = LibertineContainer(self._container, self._config, self._client)
36 if container.install_package(self._package):40 if container.install_package(self._package, update_cache=self._update_cache, no_dialog=True):
37 self._config.update_package_install_status(self._container, self._package, "installed")41 self._config.update_package_install_status(self._container, self._package_name, "installed")
42 utils.refresh_libertine_scope()
38 self._finished()43 self._finished()
39 else:44 else:
40 self._config.delete_package(self._container, self._package)45 self._config.delete_package(self._container, self._package_name)
41 self._error("Package installation failed for '%s'" % self._package)46 self._error("Package installation failed for '%s'" % self._package)
4247
43 def _before(self):48 def _before(self):
44 utils.get_logger().debug("InstallTask::_before")49 utils.get_logger().debug("InstallTask::_before")
45 if self._config.package_exists(self._container, self._package):50 is_debian_package = self._package.endswith('.deb')
46 self._error("Package '%s' already exists, skipping install" % self._package)51 if is_debian_package:
47 return False52 if os.path.exists(self._package):
53 self._package_name = utils.get_deb_package_name(self._package)
54 else:
55 libertine.utils.get_logger().error("'%s' does not exist." % self._package)
56 return False
57
58 if self._config.package_exists(self._container, self._package_name):
59 if not is_debian_package:
60 self._error("Package '%s' is already installed" % self._package_name)
61 return False
48 else:62 else:
49 self._config.add_new_package(self._container, self._package)63 self._config.add_new_package(self._container, self._package_name)
50 self._config.update_package_install_status(self._container, self._package, "installing")64
51 return True65 self._config.update_package_install_status(self._container, self._package_name, "installing")
66 return True
5267
=== modified file 'python/libertine/service/tasks/list_app_ids_task.py'
--- python/libertine/service/tasks/list_app_ids_task.py 2017-03-16 19:59:08 +0000
+++ python/libertine/service/tasks/list_app_ids_task.py 2017-04-07 16:34:30 +0000
@@ -20,8 +20,8 @@
2020
2121
22class ListAppIdsTask(ContainerBaseTask):22class ListAppIdsTask(ContainerBaseTask):
23 def __init__(self, container_id, config, monitor, client, callback):23 def __init__(self, container_id, config, monitor, client):
24 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, client=client, callback=callback)24 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, client=client)
2525
26 def _run(self):26 def _run(self):
27 utils.get_logger().debug("Listing app ids from container '%s'" % self._container)27 utils.get_logger().debug("Listing app ids from container '%s'" % self._container)
2828
=== modified file 'python/libertine/service/tasks/list_task.py'
--- python/libertine/service/tasks/list_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/list_task.py 2017-04-07 16:34:30 +0000
@@ -20,8 +20,8 @@
2020
2121
22class ListTask(BaseTask):22class ListTask(BaseTask):
23 def __init__(self, config, monitor, callback):23 def __init__(self, config, monitor):
24 super().__init__(lock=None, container_id=None, config=config, monitor=monitor, callback=callback)24 super().__init__(lock=None, container_id=None, config=config, monitor=monitor)
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()))
2828
=== modified file 'python/libertine/service/tasks/remove_task.py'
--- python/libertine/service/tasks/remove_task.py 2017-03-27 20:06:39 +0000
+++ python/libertine/service/tasks/remove_task.py 2017-04-07 16:34:30 +0000
@@ -18,8 +18,8 @@
1818
1919
20class RemoveTask(ContainerBaseTask):20class RemoveTask(ContainerBaseTask):
21 def __init__(self, package_name, container_id, config, lock, monitor, client, callback):21 def __init__(self, package_name, container_id, config, lock, monitor, client):
22 super().__init__(lock=lock, container_id=container_id, config=config, monitor=monitor, client=client, callback=callback)22 super().__init__(lock=lock, container_id=container_id, config=config, monitor=monitor, client=client)
23 self._package = package_name23 self._package = package_name
2424
25 def matches(self, package, klass):25 def matches(self, package, klass):
@@ -32,8 +32,9 @@
32 def _run(self):32 def _run(self):
33 utils.get_logger().debug("Removing package '%s'" % self._package)33 utils.get_logger().debug("Removing package '%s'" % self._package)
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, no_dialog=True):
36 self._config.delete_package(self._container, self._package)36 self._config.delete_package(self._container, self._package)
37 utils.refresh_libertine_scope()
37 self._finished()38 self._finished()
38 else:39 else:
39 self._config.update_package_install_status(self._container, self._package, 'installed')40 self._config.update_package_install_status(self._container, self._package, 'installed')
4041
=== modified file 'python/libertine/service/tasks/search_task.py'
--- python/libertine/service/tasks/search_task.py 2017-03-07 18:38:05 +0000
+++ python/libertine/service/tasks/search_task.py 2017-04-07 16:34:30 +0000
@@ -13,15 +13,21 @@
13# along with this program. If not, see <http://www.gnu.org/licenses/>.13# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
1515
16from .base_task import BaseTask16from .base_task import ContainerBaseTask
17from libertine import utils17from libertine import utils
1818
1919
20class SearchTask(BaseTask):20class SearchTask(ContainerBaseTask):
21 def __init__(self, container_id, cache, query, monitor, callback):21 def __init__(self, container_id, cache, query, config, monitor, client):
22 super().__init__(lock=None, container_id=container_id, config=None, monitor=monitor, callback=callback)22 super().__init__(lock=None, container_id=container_id, config=config, monitor=monitor, client=client)
23 self._cache = cache23 self._cache = cache
24 self._query = query24 self._query = query
2525
26 def _run(self):26 def _run(self):
27 self._data(str(self._cache.search(self._query)))27 if self._cache:
28 self._data(str(self._cache.search(self._query)))
29 else:
30 container = LibertineContainer(self._container, self._config, self._client)
31 if container.search_package_cache(self._query) is not 0:
32 self._error("Search for '{}' in container '{}' exited with non-zero status"
33 .format(self._container, self._query))
2834
=== modified file 'python/libertine/service/tasks/update_task.py'
--- python/libertine/service/tasks/update_task.py 2017-03-09 16:02:22 +0000
+++ python/libertine/service/tasks/update_task.py 2017-04-07 16:34:30 +0000
@@ -14,21 +14,34 @@
1414
1515
16from .base_task import ContainerBaseTask16from .base_task import ContainerBaseTask
17from libertine import LibertineContainer, utils17from libertine import LibertineContainer, utils, HostInfo
1818
1919
20class UpdateTask(ContainerBaseTask):20class UpdateTask(ContainerBaseTask):
21 def __init__(self, container_id, config, lock, monitor, client, callback):21 def __init__(self, container_id, config, lock, monitor, client):
22 super().__init__(lock=lock, container_id=container_id, config=config,22 super().__init__(lock=lock, container_id=container_id, config=config,
23 monitor=monitor, client=client, callback=callback)23 monitor=monitor, client=client)
24
25 def _get_updated_locale(self):
26 host_locale = HostInfo.HostInfo().get_host_locale()
27
28 if host_locale == self._config.get_container_locale(self._container):
29 return None
30
31 return host_locale
2432
25 def _run(self):33 def _run(self):
26 utils.get_logger().debug("Updating container '%s'" % self._container)34 utils.get_logger().debug("Updating container '%s'" % self._container)
27 container = LibertineContainer(self._container, self._config, self._client)35 container = LibertineContainer(self._container, self._config, self._client)
28 self._config.update_container_install_status(self._container, "updating")36 self._config.update_container_install_status(self._container, "updating")
29 if not container.update_libertine_container():37
38 new_locale = self._get_updated_locale()
39 if not container.update_libertine_container(new_locale):
30 self._error("Failed to update container '%s'" % self._container)40 self._error("Failed to update container '%s'" % self._container)
3141
42 if new_locale:
43 self._config.update_container_locale(self._container, new_locale)
44
32 self._config.update_container_install_status(self._container, "ready")45 self._config.update_container_install_status(self._container, "ready")
3346
34 def _before(self):47 def _before(self):
3548
=== modified file 'tests/integration/CMakeLists.txt'
--- tests/integration/CMakeLists.txt 2017-03-27 20:06:39 +0000
+++ tests/integration/CMakeLists.txt 2017-04-07 16:34:30 +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 "LIBERTINE_DEBUG=2;PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};XDG_DATA_HOME=/tmp")4 "LIBERTINED_TESTING=1;LIBERTINE_DEBUG=2;PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};")
55
6add_executable(6add_executable(
7 test_liblibertine7 test_liblibertine
@@ -21,4 +21,4 @@
2121
22set_tests_properties(test_liblibertine22set_tests_properties(test_liblibertine
23 PROPERTIES ENVIRONMENT23 PROPERTIES ENVIRONMENT
24 "PYTHONPATH=${CMAKE_SOURCE_DIR}/python;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};XDG_DATA_HOME=${CMAKE_CURRENT_SOURCE_DIR}/data;XDG_CACHE_HOME=${CMAKE_CURRENT_SOURCE_DIR}/data")24 "LIBERTINE_DEBUG=2;LIBERTINED_TESTING=1;PYTHONPATH=${CMAKE_SOURCE_DIR}/python;PATH=${CMAKE_SOURCE_DIR}/tools:$ENV{PATH};XDG_DATA_HOME=${CMAKE_CURRENT_SOURCE_DIR}/data;XDG_CACHE_HOME=${CMAKE_CURRENT_SOURCE_DIR}/data")
2525
=== modified file 'tests/integration/test_libertine_service.py'
--- tests/integration/test_libertine_service.py 2017-04-04 17:36:41 +0000
+++ tests/integration/test_libertine_service.py 2017-04-07 16:34:30 +0000
@@ -76,6 +76,7 @@
76 self.path = None76 self.path = None
7777
78 self._libertined = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_OBJECT)78 self._libertined = self._bus.get_object(constants.SERVICE_NAME, constants.OPERATIONS_OBJECT)
79 self.path = None
7980
80 self.signals.append(self._bus.add_signal_receiver(path=constants.OPERATIONS_MONITOR_OBJECT, handler_function=self._finished_handler,81 self.signals.append(self._bus.add_signal_receiver(path=constants.OPERATIONS_MONITOR_OBJECT, handler_function=self._finished_handler,
81 dbus_interface=constants.OPERATIONS_MONITOR_INTERFACE, signal_name='finished'))82 dbus_interface=constants.OPERATIONS_MONITOR_INTERFACE, signal_name='finished'))
8283
=== modified file 'tests/unit/service/CMakeLists.txt'
--- tests/unit/service/CMakeLists.txt 2017-03-07 20:48:11 +0000
+++ tests/unit/service/CMakeLists.txt 2017-04-07 16:34:30 +0000
@@ -2,7 +2,7 @@
2 add_test(${test_name} /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.py)2 add_test(${test_name} /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/${test_name}.py)
3 set_tests_properties(${test_name}3 set_tests_properties(${test_name}
4 PROPERTIES ENVIRONMENT4 PROPERTIES ENVIRONMENT
5 "GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;LIBERTINE_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}")5 "LIBERTINED_TESTING=1;GI_TYPELIB_PATH=${CMAKE_BINARY_DIR}/liblibertine;LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/liblibertine:${LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}:${CMAKE_SOURCE_DIR}/python;LIBERTINE_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}")
6endfunction(create_service_unit_test)6endfunction(create_service_unit_test)
77
8create_service_unit_test(test_container)8create_service_unit_test(test_container)
99
=== modified file 'tests/unit/service/tasks/test_app_info_task.py'
--- tests/unit/service/tasks/test_app_info_task.py 2017-03-07 19:41:49 +0000
+++ tests/unit/service/tasks/test_app_info_task.py 2017-04-07 16:34:30 +0000
@@ -33,7 +33,6 @@
3333
34 self.cache.app_info.return_value = {}34 self.cache.app_info.return_value = {}
35 task = tasks.AppInfoTask('palpatine', self.cache, 'lightside', [1, 2], self.config, self.monitor, callback)35 task = tasks.AppInfoTask('palpatine', self.cache, 'lightside', [1, 2], self.config, self.monitor, callback)
36 task._instant_callback = True
37 task.start().join()36 task.start().join()
3837
39 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Could not find app info for \'lightside\' in container \'palpatine\'')38 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Could not find app info for \'lightside\' in container \'palpatine\'')
@@ -50,7 +49,6 @@
50 self.cache.app_info.return_value = {'package': 'darkside-common'}49 self.cache.app_info.return_value = {'package': 'darkside-common'}
51 self.config.get_package_install_status.return_value = 'installed'50 self.config.get_package_install_status.return_value = 'installed'
52 task = tasks.AppInfoTask('palpatine', self.cache, 'darkside', [1, 2, 3], self.config, self.monitor, callback)51 task = tasks.AppInfoTask('palpatine', self.cache, 'darkside', [1, 2, 3], self.config, self.monitor, callback)
53 task._instant_callback = True
54 task.start().join()52 task.start().join()
5553
56 self.monitor.data.assert_called_once_with(self.monitor.new_operation.return_value, str({'package': 'darkside-common', 'status': 'installed', 'task_ids': [1, 2, 3]}))54 self.monitor.data.assert_called_once_with(self.monitor.new_operation.return_value, str({'package': 'darkside-common', 'status': 'installed', 'task_ids': [1, 2, 3]}))
5755
=== modified file 'tests/unit/service/tasks/test_container_info_task.py'
--- tests/unit/service/tasks/test_container_info_task.py 2017-03-07 19:41:49 +0000
+++ tests/unit/service/tasks/test_container_info_task.py 2017-04-07 16:34:30 +0000
@@ -37,7 +37,6 @@
37 self.config.get_container_install_status.return_value = 'ready'37 self.config.get_container_install_status.return_value = 'ready'
38 self.config.get_container_name.return_value = 'Palpatine'38 self.config.get_container_name.return_value = 'Palpatine'
39 task = tasks.ContainerInfoTask('palpatine', [1, 2, 3], self.config, self.monitor, callback)39 task = tasks.ContainerInfoTask('palpatine', [1, 2, 3], self.config, self.monitor, callback)
40 task._instant_callback = True
41 task.start().join()40 task.start().join()
4241
43 self.monitor.data.assert_called_once_with(self.monitor.new_operation.return_value, unittest.mock.ANY)42 self.monitor.data.assert_called_once_with(self.monitor.new_operation.return_value, unittest.mock.ANY)
4443
=== modified file 'tests/unit/service/tasks/test_create_task.py'
--- tests/unit/service/tasks/test_create_task.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/tasks/test_create_task.py 2017-04-07 16:34:30 +0000
@@ -37,7 +37,6 @@
37 self.monitor.done.return_value = False37 self.monitor.done.return_value = False
38 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,38 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,
39 self.config, self.lock, self.monitor, self.client, self.callback)39 self.config, self.lock, self.monitor, self.client, self.callback)
40 task._instant_callback = True
4140
42 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:41 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
43 MockHostInfo.return_value.is_distro_valid.return_value = True42 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -60,7 +59,6 @@
60 self.monitor.done.return_value = False59 self.monitor.done.return_value = False
61 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', False,60 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', False,
62 self.config, self.lock, self.monitor, self.client, self.callback)61 self.config, self.lock, self.monitor, self.client, self.callback)
63 task._instant_callback = True
6462
65 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:63 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
66 MockHostInfo.return_value.is_distro_valid.return_value = True64 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -81,7 +79,6 @@
81 self.config.container_exists.return_value = False79 self.config.container_exists.return_value = False
82 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,80 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,
83 self.config, self.lock, self.monitor, self.client, self.callback)81 self.config, self.lock, self.monitor, self.client, self.callback)
84 task._instant_callback = True
8582
86 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:83 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
87 MockHostInfo.return_value.is_distro_valid.return_value = True84 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -103,7 +100,6 @@
103 self.config.container_exists.return_value = True100 self.config.container_exists.return_value = True
104 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,101 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,
105 self.config, self.lock, self.monitor, self.client, self.callback)102 self.config, self.lock, self.monitor, self.client, self.callback)
106 task._instant_callback = True
107 task.start().join()103 task.start().join()
108104
109 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Container \'palpatine\' already exists')105 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Container \'palpatine\' already exists')
@@ -115,7 +111,6 @@
115 MockHostInfo.return_value.is_distro_valid.return_value = False111 MockHostInfo.return_value.is_distro_valid.return_value = False
116 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'vesty', 'lxc', False,112 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'vesty', 'lxc', False,
117 self.config, self.lock, self.monitor, self.client, self.callback)113 self.config, self.lock, self.monitor, self.client, self.callback)
118 task._instant_callback = True
119 task.start().join()114 task.start().join()
120115
121 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Invalid distro \'vesty\'.')116 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Invalid distro \'vesty\'.')
@@ -128,7 +123,6 @@
128 MockHostInfo.return_value.has_lxc_support.return_value = False123 MockHostInfo.return_value.has_lxc_support.return_value = False
129 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,124 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False,
130 self.config, self.lock, self.monitor, self.client, self.callback)125 self.config, self.lock, self.monitor, self.client, self.callback)
131 task._instant_callback = True
132 task.start().join()126 task.start().join()
133127
134 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, \128 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, \
@@ -140,7 +134,6 @@
140 self.monitor.done.return_value = False134 self.monitor.done.return_value = False
141 task = tasks.CreateTask('palpatine', None, 'zesty', 'chroot', False, self.config,135 task = tasks.CreateTask('palpatine', None, 'zesty', 'chroot', False, self.config,
142 self.lock, self.monitor, self.client, self.callback)136 self.lock, self.monitor, self.client, self.callback)
143 task._instant_callback = True
144137
145 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:138 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
146 MockHostInfo.return_value.is_distro_valid.return_value = True139 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -163,7 +156,6 @@
163 self.monitor.done.return_value = False156 self.monitor.done.return_value = False
164 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', True,157 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', True,
165 self.config, self.lock, self.monitor, self.client, self.callback)158 self.config, self.lock, self.monitor, self.client, self.callback)
166 task._instant_callback = True
167159
168 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:160 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
169 MockHostInfo.return_value.is_distro_valid.return_value = True161 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -186,7 +178,6 @@
186 self.monitor.done.return_value = False178 self.monitor.done.return_value = False
187 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', None, False,179 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', None, False,
188 self.config, self.lock, self.monitor, self.client, self.callback)180 self.config, self.lock, self.monitor, self.client, self.callback)
189 task._instant_callback = True
190181
191 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:182 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
192 MockHostInfo.return_value.is_distro_valid.return_value = True183 MockHostInfo.return_value.is_distro_valid.return_value = True
@@ -209,7 +200,6 @@
209 self.monitor.done.return_value = False200 self.monitor.done.return_value = False
210 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', None, 'lxc', False,201 task = tasks.CreateTask('palpatine', 'Emperor Palpatine', None, 'lxc', False,
211 self.config, self.lock, self.monitor, self.client, self.callback)202 self.config, self.lock, self.monitor, self.client, self.callback)
212 task._instant_callback = True
213203
214 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:204 with unittest.mock.patch('libertine.service.tasks.create_task.HostInfo') as MockHostInfo:
215 MockHostInfo.return_value.has_lxc_support.return_value = True205 MockHostInfo.return_value.has_lxc_support.return_value = True
216206
=== modified file 'tests/unit/service/tasks/test_destroy_task.py'
--- tests/unit/service/tasks/test_destroy_task.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/tasks/test_destroy_task.py 2017-04-07 16:34:30 +0000
@@ -36,7 +36,6 @@
36 self.config._get_value_by_key.return_value = ''36 self.config._get_value_by_key.return_value = ''
37 self.monitor.done.return_value = False37 self.monitor.done.return_value = False
38 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)38 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
39 task._instant_callback = True
4039
41 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:40 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:
42 MockContainer.return_value.destroy_libertine_container.return_value = True41 MockContainer.return_value.destroy_libertine_container.return_value = True
@@ -48,7 +47,6 @@
48 def test_sends_error_on_failed_destroy(self):47 def test_sends_error_on_failed_destroy(self):
49 self.config._get_value_by_key.return_value = 'ready'48 self.config._get_value_by_key.return_value = 'ready'
50 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)49 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
51 task._instant_callback = True
5250
53 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:51 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:
54 MockContainer.return_value.destroy_libertine_container.return_value = False52 MockContainer.return_value.destroy_libertine_container.return_value = False
@@ -66,7 +64,6 @@
66 self.config._get_value_by_key.return_value = 'ready'64 self.config._get_value_by_key.return_value = 'ready'
67 self.monitor.done.return_value = False65 self.monitor.done.return_value = False
68 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)66 task = tasks.DestroyTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
69 task._instant_callback = True
7067
71 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:68 with unittest.mock.patch('libertine.service.tasks.destroy_task.LibertineContainer') as MockContainer:
72 MockContainer.return_value.destroy_libertine_container.return_value = True69 MockContainer.return_value.destroy_libertine_container.return_value = True
7370
=== modified file 'tests/unit/service/tasks/test_install_task.py'
--- tests/unit/service/tasks/test_install_task.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/tasks/test_install_task.py 2017-04-07 16:34:30 +0000
@@ -35,7 +35,6 @@
35 def test_sends_error_on_existing_package(self):35 def test_sends_error_on_existing_package(self):
36 self.config.package_exists.return_value = True36 self.config.package_exists.return_value = True
37 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)37 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
38 task._instant_callback = True
39 task.start().join()38 task.start().join()
4039
41 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Package \'darkside-common\' already exists, skipping install')40 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Package \'darkside-common\' already exists, skipping install')
@@ -44,7 +43,6 @@
44 def test_sends_error_on_failed_install(self):43 def test_sends_error_on_failed_install(self):
45 self.config.package_exists.return_value = False44 self.config.package_exists.return_value = False
46 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)45 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
47 task._instant_callback = True
4846
49 with unittest.mock.patch('libertine.service.tasks.install_task.LibertineContainer') as MockContainer:47 with unittest.mock.patch('libertine.service.tasks.install_task.LibertineContainer') as MockContainer:
50 MockContainer.return_value.install_package.return_value = False48 MockContainer.return_value.install_package.return_value = False
@@ -59,7 +57,6 @@
59 self.config.package_exists.return_value = False57 self.config.package_exists.return_value = False
60 self.monitor.done.return_value = False58 self.monitor.done.return_value = False
61 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)59 task = tasks.InstallTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
62 task._instant_callback = True
6360
64 with unittest.mock.patch('libertine.service.tasks.install_task.LibertineContainer') as MockContainer:61 with unittest.mock.patch('libertine.service.tasks.install_task.LibertineContainer') as MockContainer:
65 MockContainer.return_value.install_package.return_value = True62 MockContainer.return_value.install_package.return_value = True
6663
=== modified file 'tests/unit/service/tasks/test_list_app_ids_task.py'
--- tests/unit/service/tasks/test_list_app_ids_task.py 2017-03-07 19:41:49 +0000
+++ tests/unit/service/tasks/test_list_app_ids_task.py 2017-04-07 16:34:30 +0000
@@ -34,7 +34,6 @@
34 def test_sends_error_on_non_existent_container(self):34 def test_sends_error_on_non_existent_container(self):
35 self.config.container_exists.return_value = False35 self.config.container_exists.return_value = False
36 task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback)36 task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback)
37 task._instant_callback = True
3837
39 with unittest.mock.patch('libertine.service.tasks.list_app_ids_task.LibertineContainer') as MockContainer:38 with unittest.mock.patch('libertine.service.tasks.list_app_ids_task.LibertineContainer') as MockContainer:
40 task.start().join()39 task.start().join()
@@ -46,7 +45,6 @@
46 self.config.container_exists.return_value = True45 self.config.container_exists.return_value = True
47 self.monitor.done.return_value = False46 self.monitor.done.return_value = False
48 task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback)47 task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback)
49 task._instant_callback = True
5048
51 with unittest.mock.patch('libertine.service.tasks.list_app_ids_task.LibertineContainer') as MockContainer:49 with unittest.mock.patch('libertine.service.tasks.list_app_ids_task.LibertineContainer') as MockContainer:
52 MockContainer.return_value.list_app_ids.return_value = '["palpatine_gedit_0.0","palpatine_xterm_0.0"]'50 MockContainer.return_value.list_app_ids.return_value = '["palpatine_gedit_0.0","palpatine_xterm_0.0"]'
5351
=== modified file 'tests/unit/service/tasks/test_list_task.py'
--- tests/unit/service/tasks/test_list_task.py 2017-03-07 19:41:49 +0000
+++ tests/unit/service/tasks/test_list_task.py 2017-04-07 16:34:30 +0000
@@ -35,7 +35,6 @@
35 self.monitor.done.return_value = False35 self.monitor.done.return_value = False
3636
37 task = tasks.ListTask(self.config, self.monitor, callback)37 task = tasks.ListTask(self.config, self.monitor, callback)
38 task._instant_callback = True
3938
40 self.config.get_containers.return_value = ['palatine', 'vader', 'maul']39 self.config.get_containers.return_value = ['palatine', 'vader', 'maul']
41 task.start().join()40 task.start().join()
4241
=== modified file 'tests/unit/service/tasks/test_remove_task.py'
--- tests/unit/service/tasks/test_remove_task.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/tasks/test_remove_task.py 2017-04-07 16:34:30 +0000
@@ -35,7 +35,6 @@
35 def test_sends_error_on_non_installed_package(self):35 def test_sends_error_on_non_installed_package(self):
36 self.config.get_package_install_status.return_value = 'installing'36 self.config.get_package_install_status.return_value = 'installing'
37 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)37 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
38 task._instant_callback = True
39 task.start().join()38 task.start().join()
4039
41 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Package \'darkside-common\' not installed, skipping remove')40 self.monitor.error.assert_called_once_with(self.monitor.new_operation.return_value, 'Package \'darkside-common\' not installed, skipping remove')
@@ -44,7 +43,6 @@
44 def test_sends_error_on_failed_install(self):43 def test_sends_error_on_failed_install(self):
45 self.config.get_package_install_status.return_value = 'installed'44 self.config.get_package_install_status.return_value = 'installed'
46 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)45 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
47 task._instant_callback = True
4846
49 with unittest.mock.patch('libertine.service.tasks.remove_task.LibertineContainer') as MockContainer:47 with unittest.mock.patch('libertine.service.tasks.remove_task.LibertineContainer') as MockContainer:
50 MockContainer.return_value.remove_package.return_value = False48 MockContainer.return_value.remove_package.return_value = False
@@ -61,7 +59,6 @@
61 self.config.get_package_install_status.return_value = 'installed'59 self.config.get_package_install_status.return_value = 'installed'
62 self.monitor.done.return_value = False60 self.monitor.done.return_value = False
63 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)61 task = tasks.RemoveTask('darkside-common', 'palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
64 task._instant_callback = True
6562
66 with unittest.mock.patch('libertine.service.tasks.remove_task.LibertineContainer') as MockContainer:63 with unittest.mock.patch('libertine.service.tasks.remove_task.LibertineContainer') as MockContainer:
67 MockContainer.return_value.remove_package.return_value = True64 MockContainer.return_value.remove_package.return_value = True
6865
=== modified file 'tests/unit/service/tasks/test_search_task.py'
--- tests/unit/service/tasks/test_search_task.py 2017-03-07 19:41:49 +0000
+++ tests/unit/service/tasks/test_search_task.py 2017-04-07 16:34:30 +0000
@@ -33,7 +33,6 @@
33 def test_successfully_lists_apps(self):33 def test_successfully_lists_apps(self):
34 self.monitor.done.return_value = False34 self.monitor.done.return_value = False
35 task = tasks.SearchTask('palpatine', self.cache, 'jarjar', self.monitor, self.callback)35 task = tasks.SearchTask('palpatine', self.cache, 'jarjar', self.monitor, self.callback)
36 task._instant_callback = True
3736
38 self.cache.search.return_value = ['jarjar', 'sidius']37 self.cache.search.return_value = ['jarjar', 'sidius']
39 task.start().join()38 task.start().join()
4039
=== modified file 'tests/unit/service/tasks/test_update_task.py'
--- tests/unit/service/tasks/test_update_task.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/tasks/test_update_task.py 2017-04-07 16:34:30 +0000
@@ -35,7 +35,6 @@
35 def test_sends_error_on_non_existent_container(self):35 def test_sends_error_on_non_existent_container(self):
36 self.config.container_exists.return_value = False36 self.config.container_exists.return_value = False
37 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)37 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
38 task._instant_callback = True
3938
40 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:39 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:
41 task.start().join()40 task.start().join()
@@ -47,7 +46,6 @@
47 def test_sends_error_on_failed_update(self):46 def test_sends_error_on_failed_update(self):
48 self.config.container_exists.return_value = True47 self.config.container_exists.return_value = True
49 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)48 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
50 task._instant_callback = True
5149
52 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:50 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:
53 MockContainer.return_value.update_libertine_container.return_value = False51 MockContainer.return_value.update_libertine_container.return_value = False
@@ -65,7 +63,6 @@
65 self.config.container_exists.return_value = True63 self.config.container_exists.return_value = True
66 self.monitor.done.return_value = False64 self.monitor.done.return_value = False
67 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)65 task = tasks.UpdateTask('palpatine', self.config, self.lock, self.monitor, self.client, self.callback)
68 task._instant_callback = True
6966
70 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:67 with unittest.mock.patch('libertine.service.tasks.update_task.LibertineContainer') as MockContainer:
71 MockContainer.return_value.update_libertine_container.return_value = True68 MockContainer.return_value.update_libertine_container.return_value = True
7269
=== modified file 'tests/unit/service/test_container.py'
--- tests/unit/service/test_container.py 2017-03-16 19:59:08 +0000
+++ tests/unit/service/test_container.py 2017-04-07 16:34:30 +0000
@@ -30,7 +30,7 @@
30 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)30 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
31 with unittest.mock.patch('libertine.service.container.SearchTask') as MockSearchTask:31 with unittest.mock.patch('libertine.service.container.SearchTask') as MockSearchTask:
32 c.search('darkseid')32 c.search('darkseid')
33 MockSearchTask.assert_called_once_with('palpatine', cache, 'darkseid', self._monitor, unittest.mock.ANY)33 MockSearchTask.assert_called_once_with('palpatine', cache, 'darkseid', self._config, self._monitor, unittest.mock.ANY)
34 MockSearchTask.return_value.start.assert_called_once_with()34 MockSearchTask.return_value.start.assert_called_once_with()
3535
36 def test_app_info_creates_app_info_task(self):36 def test_app_info_creates_app_info_task(self):
@@ -49,7 +49,7 @@
49 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:49 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
50 MockInstallTask.return_value.package = 'darkside'50 MockInstallTask.return_value.package = 'darkside'
51 MockInstallTask.return_value.matches.return_value = False51 MockInstallTask.return_value.matches.return_value = False
52 install_task_id = c.install('darkside')52 install_task_id = c.install('darkside', False)
53 with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:53 with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:
54 MockRemoveTask.return_value.package = 'darkside'54 MockRemoveTask.return_value.package = 'darkside'
55 remove_task_id = c.remove('darkside')55 remove_task_id = c.remove('darkside')
@@ -62,18 +62,18 @@
62 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:62 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
63 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)63 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
64 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:64 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
65 c.install('force')65 c.install('force', False)
66 MockInstallTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)66 MockInstallTask.assert_called_once_with('force', 'palpatine', False, self._config, unittest.mock.ANY, self._monitor, self._client)
67 MockInstallTask.return_value.start.assert_called_once_with()67 MockInstallTask.return_value.start.assert_called_once_with()
6868
69 def test_install_only_calls_once_when_unfinished(self):69 def test_install_only_calls_once_when_unfinished(self):
70 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:70 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
71 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)71 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
72 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:72 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
73 c.install('darkside')73 c.install('darkside', False)
74 c.install('darkside')74 c.install('darkside', False)
75 c.install('darkside')75 c.install('darkside', False)
76 MockInstallTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)76 MockInstallTask.assert_called_once_with('darkside', 'palpatine', False, self._config, unittest.mock.ANY, self._monitor, self._client)
77 MockInstallTask.return_value.start.assert_called_once_with()77 MockInstallTask.return_value.start.assert_called_once_with()
7878
79 def test_remove_creates_remove_task(self):79 def test_remove_creates_remove_task(self):
@@ -81,7 +81,7 @@
81 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)81 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
82 with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:82 with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask:
83 c.remove('force')83 c.remove('force')
84 MockRemoveTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)84 MockRemoveTask.assert_called_once_with('force', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
85 MockRemoveTask.return_value.start.assert_called_once_with()85 MockRemoveTask.return_value.start.assert_called_once_with()
8686
87 def test_remove_only_calls_once_when_unfinished(self):87 def test_remove_only_calls_once_when_unfinished(self):
@@ -91,7 +91,7 @@
91 c.remove('darkside')91 c.remove('darkside')
92 c.remove('darkside')92 c.remove('darkside')
93 c.remove('darkside')93 c.remove('darkside')
94 MockRemoveTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)94 MockRemoveTask.assert_called_once_with('darkside', 'palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
95 MockRemoveTask.return_value.start.assert_called_once_with()95 MockRemoveTask.return_value.start.assert_called_once_with()
9696
97 def test_create_creates_create_task(self):97 def test_create_creates_create_task(self):
@@ -100,7 +100,7 @@
100 with unittest.mock.patch('libertine.service.container.CreateTask') as MockCreateTask:100 with unittest.mock.patch('libertine.service.container.CreateTask') as MockCreateTask:
101 c.create('Emperor Palpatine', 'zesty', 'lxd', False)101 c.create('Emperor Palpatine', 'zesty', 'lxd', False)
102 MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,102 MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,
103 self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)103 self._config, unittest.mock.ANY, self._monitor, self._client)
104 MockCreateTask.return_value.start.assert_called_once_with()104 MockCreateTask.return_value.start.assert_called_once_with()
105105
106 def test_create_only_calls_once_when_unfinished(self):106 def test_create_only_calls_once_when_unfinished(self):
@@ -111,25 +111,25 @@
111 c.create('Emperor Palpatine', 'zesty', 'lxd', False)111 c.create('Emperor Palpatine', 'zesty', 'lxd', False)
112 c.create('Emperor Palpatine', 'zesty', 'lxd', False)112 c.create('Emperor Palpatine', 'zesty', 'lxd', False)
113 MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,113 MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False,
114 self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)114 self._config, unittest.mock.ANY, self._monitor, self._client)
115 MockCreateTask.return_value.start.assert_called_once_with()115 MockCreateTask.return_value.start.assert_called_once_with()
116116
117 def test_destroy_creates_destroy_task(self):117 def test_destroy_creates_destroy_task(self):
118 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:118 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
119 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)119 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
120 with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:120 with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:
121 c.destroy()121 c.destroy(False)
122 MockDestroyTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)122 MockDestroyTask.assert_called_once_with('palpatine', self._config, False, unittest.mock.ANY, self._monitor, self._client)
123 MockDestroyTask.return_value.start.assert_called_once_with()123 MockDestroyTask.return_value.start.assert_called_once_with()
124124
125 def test_destroy_only_calls_once_when_unfinished(self):125 def test_destroy_only_calls_once_when_unfinished(self):
126 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:126 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
127 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)127 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
128 with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:128 with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask:
129 c.destroy()129 c.destroy(False)
130 c.destroy()130 c.destroy(False)
131 c.destroy()131 c.destroy(False)
132 MockDestroyTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)132 MockDestroyTask.assert_called_once_with('palpatine', self._config, False, unittest.mock.ANY, self._monitor, self._client)
133 MockDestroyTask.return_value.start.assert_called_once_with()133 MockDestroyTask.return_value.start.assert_called_once_with()
134134
135 def test_update_creates_update_task(self):135 def test_update_creates_update_task(self):
@@ -137,7 +137,7 @@
137 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)137 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
138 with unittest.mock.patch('libertine.service.container.UpdateTask') as MockUpdateTask:138 with unittest.mock.patch('libertine.service.container.UpdateTask') as MockUpdateTask:
139 c.update()139 c.update()
140 MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)140 MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
141 MockUpdateTask.return_value.start.assert_called_once_with()141 MockUpdateTask.return_value.start.assert_called_once_with()
142142
143 def test_update_only_calls_once_when_unfinished(self):143 def test_update_only_calls_once_when_unfinished(self):
@@ -147,7 +147,7 @@
147 c.update()147 c.update()
148 c.update()148 c.update()
149 c.update()149 c.update()
150 MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY)150 MockUpdateTask.assert_called_once_with('palpatine', self._config, unittest.mock.ANY, self._monitor, self._client)
151 MockUpdateTask.return_value.start.assert_called_once_with()151 MockUpdateTask.return_value.start.assert_called_once_with()
152152
153 def test_list_app_ids_creates_list_app_ids_task(self):153 def test_list_app_ids_creates_list_app_ids_task(self):
@@ -155,21 +155,21 @@
155 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)155 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
156 with unittest.mock.patch('libertine.service.container.ListAppIdsTask') as MockListAppIdsTask:156 with unittest.mock.patch('libertine.service.container.ListAppIdsTask') as MockListAppIdsTask:
157 c.list_app_ids()157 c.list_app_ids()
158 MockListAppIdsTask.assert_called_once_with('palpatine', self._config, self._monitor, self._client, unittest.mock.ANY)158 MockListAppIdsTask.assert_called_once_with('palpatine', self._config, self._monitor, self._client)
159 MockListAppIdsTask.return_value.start.assert_called_once_with()159 MockListAppIdsTask.return_value.start.assert_called_once_with()
160160
161 def test_removes_task_during_callback(self):161 def test_removes_task_during_cleanup(self):
162 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:162 with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache:
163 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)163 c = container.Container('palpatine', self._config, self._monitor, self._client, lambda task: task)
164 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:164 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
165 MockInstallTask.return_value.package = 'force'165 MockInstallTask.return_value.package = 'force'
166 c.install('force')166 c.install('force', False)
167 self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure initial mocks were called167 self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure initial mocks were called
168 c.install('force')168 c.install('force', False)
169 self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure no more mocks were called169 self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure no more mocks were called
170 name, args, kwargs = MockInstallTask.mock_calls[0]170 MockInstallTask.return_value.should_delete = True
171 args[len(args)-1](MockInstallTask.return_value.start.return_value)171 c._cleanup()
172 c.install('force')172 c.install('force', False)
173 self.assertEqual(2, len(MockInstallTask.return_value.start.mock_calls)) # ensure mocks were called again173 self.assertEqual(2, len(MockInstallTask.return_value.start.mock_calls)) # ensure mocks were called again
174174
175 def test_completing_all_tasks_fires_callback(self):175 def test_completing_all_tasks_fires_callback(self):
@@ -179,9 +179,9 @@
179 self._container_id = container.id179 self._container_id = container.id
180 c = container.Container('palpatine', self._config, self._monitor, self._client, callback)180 c = container.Container('palpatine', self._config, self._monitor, self._client, callback)
181 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:181 with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask:
182 c.install('force')182 c.install('force', False)
183 name, args, kwargs = MockInstallTask.mock_calls[0]183 MockInstallTask.return_value.should_delete = True
184 args[len(args)-1](MockInstallTask.return_value)184 c._cleanup()
185 self.assertEqual('palpatine', self._container_id)185 self.assertEqual('palpatine', self._container_id)
186186
187187
188188
=== modified file 'tests/unit/service/test_task_dispatcher.py'
--- tests/unit/service/test_task_dispatcher.py 2017-03-09 16:02:22 +0000
+++ tests/unit/service/test_task_dispatcher.py 2017-04-07 16:34:30 +0000
@@ -46,8 +46,8 @@
46 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:46 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:
47 c = MockContainer.return_value47 c = MockContainer.return_value
48 c.install.return_value = 12348 c.install.return_value = 123
49 self.assertEqual(123, self._dispatcher.install('palpatine', 'darkside'))49 self.assertEqual(123, self._dispatcher.install('palpatine', 'darkside', False))
50 c.install.assert_called_once_with('darkside')50 c.install.assert_called_once_with('darkside', False)
5151
52 def test_remove_calls_remove_on_container(self):52 def test_remove_calls_remove_on_container(self):
53 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:53 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:
@@ -67,8 +67,8 @@
67 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:67 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:
68 c = MockContainer.return_value68 c = MockContainer.return_value
69 c.destroy.return_value = 12369 c.destroy.return_value = 123
70 self.assertEqual(123, self._dispatcher.destroy('palpatine'))70 self.assertEqual(123, self._dispatcher.destroy('palpatine', False))
71 c.destroy.assert_called_once_with()71 c.destroy.assert_called_once_with(False)
7272
73 def test_update_calls_update_on_container(self):73 def test_update_calls_update_on_container(self):
74 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:74 with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer:
@@ -112,7 +112,7 @@
112 task = MockContainerInfoTask.return_value112 task = MockContainerInfoTask.return_value
113 task.id = 123113 task.id = 123
114 self.assertEqual(123, self._dispatcher.container_info('palpatine'))114 self.assertEqual(123, self._dispatcher.container_info('palpatine'))
115 MockContainerInfoTask.assert_called_once_with('palpatine', [], unittest.mock.ANY, self._connection, unittest.mock.ANY)115 MockContainerInfoTask.assert_called_once_with('palpatine', [], unittest.mock.ANY, self._connection)
116 task.start.assert_called_once_with()116 task.start.assert_called_once_with()
117117
118 def test_container_info_forwards_container_task_ids(self):118 def test_container_info_forwards_container_task_ids(self):
@@ -124,7 +124,7 @@
124 c.id = 'palpatine'124 c.id = 'palpatine'
125 self._dispatcher.list_app_ids('palpatine') # creates container125 self._dispatcher.list_app_ids('palpatine') # creates container
126 self._dispatcher.container_info('palpatine')126 self._dispatcher.container_info('palpatine')
127 MockContainerInfoTask.assert_called_once_with('palpatine', [1, 2, 3], unittest.mock.ANY, self._connection, unittest.mock.ANY)127 MockContainerInfoTask.assert_called_once_with('palpatine', [1, 2, 3], unittest.mock.ANY, self._connection)
128 task.start.assert_called_once_with()128 task.start.assert_called_once_with()
129129
130 def test_list_creates_list_task(self):130 def test_list_creates_list_task(self):
@@ -132,16 +132,17 @@
132 task = MockListTask.return_value132 task = MockListTask.return_value
133 task.id = 123133 task.id = 123
134 self.assertEqual(123, self._dispatcher.list())134 self.assertEqual(123, self._dispatcher.list())
135 MockListTask.assert_called_once_with(unittest.mock.ANY, self._connection, unittest.mock.ANY)135 MockListTask.assert_called_once_with(unittest.mock.ANY, self._connection)
136 task.start.assert_called_once_with()136 task.start.assert_called_once_with()
137137
138 def test_containerless_tasks_are_cleaned_up(self):138 def test_containerless_tasks_are_cleaned_up(self):
139 with unittest.mock.patch('libertine.service.task_dispatcher.ListTask') as MockListTask:139 with unittest.mock.patch('libertine.service.task_dispatcher.ListTask') as MockListTask:
140 self._dispatcher.list()140 self._dispatcher.list()
141 MockListTask.assert_called_once_with(unittest.mock.ANY, self._connection, unittest.mock.ANY)141 MockListTask.assert_called_once_with(unittest.mock.ANY, self._connection)
142 name, args, kwargs = MockListTask.mock_calls[0]142 name, args, kwargs = MockListTask.mock_calls[0]
143 self.assertEqual(1, len(self._dispatcher._tasks))143 self.assertEqual(1, len(self._dispatcher._tasks))
144 args[len(args)-1](MockListTask.return_value)144 MockListTask.return_value.should_delete = True
145 self._dispatcher._cleanup()
145 self.assertEqual(0, len(self._dispatcher._tasks))146 self.assertEqual(0, len(self._dispatcher._tasks))
146147
147148
148149
=== modified file 'tools/libertined'
--- tools/libertined 2017-04-06 14:37:00 +0000
+++ tools/libertined 2017-04-07 16:34:30 +0000
@@ -20,7 +20,6 @@
20import dbus20import dbus
21import os21import os
22import signal22import signal
23import sys
2423
25from dbus.mainloop.glib import DBusGMainLoop24from dbus.mainloop.glib import DBusGMainLoop
26from gi.repository import GLib25from gi.repository import GLib

Subscribers

People subscribed via source and target branches