Merge lp:~larryprice/libertine/libertined-output into lp:libertine
- libertined-output
- Merge into devel
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 |
Related bugs: |
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.
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:464
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:465
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:466
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:467
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
PASSED: Continuous integration, rev:468
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:469
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:471
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:471
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:471
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:471
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:472
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Libertine CI Bot (libertine-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:473
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 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
1 | === modified file 'python/libertine/Libertine.py' | |||
2 | --- python/libertine/Libertine.py 2017-03-23 19:23:20 +0000 | |||
3 | +++ python/libertine/Libertine.py 2017-04-07 16:34:30 +0000 | |||
4 | @@ -258,12 +258,14 @@ | |||
5 | 258 | 258 | ||
6 | 259 | return ret | 259 | return ret |
7 | 260 | 260 | ||
9 | 261 | def remove_package(self, package_name): | 261 | def remove_package(self, package_name, no_dialog=False): |
10 | 262 | """ | 262 | """ |
11 | 263 | Removes a package from the container. | 263 | Removes a package from the container. |
12 | 264 | 264 | ||
13 | 265 | :param package_name: The name of the package to be removed. | 265 | :param package_name: The name of the package to be removed. |
14 | 266 | """ | 266 | """ |
15 | 267 | if no_dialog: | ||
16 | 268 | os.environ['DEBIAN_FRONTEND'] = 'teletype' | ||
17 | 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: |
18 | 268 | return False | 270 | return False |
19 | 269 | return self.run_in_container(_apt_command_prefix() + "autoremove --purge") == 0 | 271 | return self.run_in_container(_apt_command_prefix() + "autoremove --purge") == 0 |
20 | @@ -478,9 +480,6 @@ | |||
21 | 478 | """ | 480 | """ |
22 | 479 | try: | 481 | try: |
23 | 480 | with ContainerRunning(self.container): | 482 | with ContainerRunning(self.container): |
24 | 481 | if no_dialog: | ||
25 | 482 | os.environ['DEBIAN_FRONTEND'] = 'teletype' | ||
26 | 483 | |||
27 | 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") |
28 | 485 | retval = self.container.remove_package(package_name) | 484 | retval = self.container.remove_package(package_name) |
29 | 486 | 485 | ||
30 | 487 | 486 | ||
31 | === modified file 'python/libertine/LxdContainer.py' | |||
32 | --- python/libertine/LxdContainer.py 2017-03-23 19:23:20 +0000 | |||
33 | +++ python/libertine/LxdContainer.py 2017-04-07 16:34:30 +0000 | |||
34 | @@ -112,7 +112,8 @@ | |||
35 | 112 | def lxd_container(client, container_id): | 112 | def lxd_container(client, container_id): |
36 | 113 | try: | 113 | try: |
37 | 114 | return client.containers.get(container_id) | 114 | return client.containers.get(container_id) |
39 | 115 | except pylxd.exceptions.LXDAPIException: | 115 | except pylxd.exceptions.LXDAPIException as e: |
40 | 116 | utils.get_logger().error(str(e)) | ||
41 | 116 | return None | 117 | return None |
42 | 117 | 118 | ||
43 | 118 | 119 | ||
44 | @@ -458,8 +459,8 @@ | |||
45 | 458 | _add_local_files_for_ual(self._container) | 459 | _add_local_files_for_ual(self._container) |
46 | 459 | return ret | 460 | return ret |
47 | 460 | 461 | ||
50 | 461 | def remove_package(self, package_name): | 462 | def remove_package(self, package_name, no_dialog=False): |
51 | 462 | ret = super().remove_package(package_name) | 463 | ret = super().remove_package(package_name, no_dialog) |
52 | 463 | _remove_local_files_for_ual(self._container) | 464 | _remove_local_files_for_ual(self._container) |
53 | 464 | return ret | 465 | return ret |
54 | 465 | 466 | ||
55 | 466 | 467 | ||
56 | === modified file 'python/libertine/service/apt.py' | |||
57 | --- python/libertine/service/apt.py 2017-01-24 18:00:57 +0000 | |||
58 | +++ python/libertine/service/apt.py 2017-04-07 16:34:30 +0000 | |||
59 | @@ -54,7 +54,6 @@ | |||
60 | 54 | app_data["summary"] = app.versions[0].summary | 54 | app_data["summary"] = app.versions[0].summary |
61 | 55 | app_data["website"] = app.versions[0].homepage | 55 | app_data["website"] = app.versions[0].homepage |
62 | 56 | app_data["description"] = app.versions[0].description | 56 | app_data["description"] = app.versions[0].description |
63 | 57 | app_data["package"] = app.name | ||
64 | 58 | 57 | ||
65 | 59 | return app_data | 58 | return app_data |
66 | 60 | 59 | ||
67 | 61 | 60 | ||
68 | === modified file 'python/libertine/service/container.py' | |||
69 | --- python/libertine/service/container.py 2017-03-23 19:23:20 +0000 | |||
70 | +++ python/libertine/service/container.py 2017-04-07 16:34:30 +0000 | |||
71 | @@ -12,24 +12,23 @@ | |||
72 | 12 | # You should have received a copy of the GNU General Public License | 12 | # You should have received a copy of the GNU General Public License |
73 | 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/>. |
74 | 14 | 14 | ||
75 | 15 | |||
76 | 16 | from libertine import utils | ||
77 | 17 | from libertine.service.task_dispatcher_base import TaskDispatcherBase | ||
78 | 15 | from libertine.service.tasks import * | 18 | from libertine.service.tasks import * |
81 | 16 | from libertine import utils | 19 | from multiprocessing import Lock |
80 | 17 | from threading import Lock | ||
82 | 18 | 20 | ||
83 | 19 | if not utils.is_snap_environment(): | 21 | if not utils.is_snap_environment(): |
84 | 20 | from libertine.service import apt | 22 | from libertine.service import apt |
85 | 21 | 23 | ||
86 | 22 | 24 | ||
88 | 23 | class Container(object): | 25 | class Container(TaskDispatcherBase): |
89 | 24 | def __init__(self, container_id, config, monitor, client, callback): | 26 | def __init__(self, container_id, config, monitor, client, callback): |
90 | 27 | super().__init__(monitor, client) | ||
91 | 25 | self._id = container_id | 28 | self._id = container_id |
92 | 26 | self._config = config | 29 | self._config = config |
93 | 27 | self._monitor = monitor | ||
94 | 28 | self._client = client | ||
95 | 29 | self._callback = callback | 30 | self._callback = callback |
96 | 30 | |||
97 | 31 | self._lock = Lock() | 31 | self._lock = Lock() |
98 | 32 | self._tasks = [] | ||
99 | 33 | 32 | ||
100 | 34 | if utils.is_snap_environment(): | 33 | if utils.is_snap_environment(): |
101 | 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")) |
102 | @@ -37,13 +36,9 @@ | |||
103 | 37 | else: | 36 | else: |
104 | 38 | self._cache = apt.AptCache(self.id) | 37 | self._cache = apt.AptCache(self.id) |
105 | 39 | 38 | ||
113 | 40 | def _cleanup_task(self, task): | 39 | def _cleanup(self): |
114 | 41 | utils.get_logger().debug("cleaning up tasks for container '%s'" % self.id) | 40 | super()._cleanup() |
115 | 42 | 41 | if not self._tasks: | |
109 | 43 | if task in self._tasks: | ||
110 | 44 | self._tasks.remove(task) | ||
111 | 45 | |||
112 | 46 | if len(self._tasks) == 0: | ||
116 | 47 | self._callback(self) | 42 | self._callback(self) |
117 | 48 | 43 | ||
118 | 49 | @property | 44 | @property |
119 | @@ -54,7 +49,7 @@ | |||
120 | 54 | def tasks(self): | 49 | def tasks(self): |
121 | 55 | return [task.id for task in self._tasks if task.running] | 50 | return [task.id for task in self._tasks if task.running] |
122 | 56 | 51 | ||
124 | 57 | def install(self, package_name): | 52 | def install(self, package_name, update_cache): |
125 | 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)) |
126 | 59 | 54 | ||
127 | 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] |
128 | @@ -62,10 +57,8 @@ | |||
129 | 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)) |
130 | 63 | return tasks[0].id | 58 | return tasks[0].id |
131 | 64 | 59 | ||
136 | 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, |
137 | 66 | self._tasks.append(task) | 61 | self._lock, self._monitor, self._client)) |
134 | 67 | task.start() | ||
135 | 68 | return task.id | ||
138 | 69 | 62 | ||
139 | 70 | def remove(self, package_name): | 63 | def remove(self, package_name): |
140 | 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)) |
141 | @@ -75,10 +68,7 @@ | |||
142 | 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)) |
143 | 76 | return tasks[0].id | 69 | return tasks[0].id |
144 | 77 | 70 | ||
149 | 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)) |
146 | 79 | self._tasks.append(task) | ||
147 | 80 | task.start() | ||
148 | 81 | return task.id | ||
150 | 82 | 72 | ||
151 | 83 | def create(self, container_name, distro, container_type, enable_multiarch): | 73 | def create(self, container_name, distro, container_type, enable_multiarch): |
152 | 84 | utils.get_logger().debug("Create container with ID '%s'" % self.id) | 74 | utils.get_logger().debug("Create container with ID '%s'" % self.id) |
153 | @@ -88,13 +78,10 @@ | |||
154 | 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) |
155 | 89 | return tasks[0].id | 79 | return tasks[0].id |
156 | 90 | 80 | ||
162 | 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, |
163 | 92 | self._config, self._lock, self._monitor, self._client, self._cleanup_task) | 82 | self._config, self._lock, self._monitor, self._client)) |
159 | 93 | self._tasks.append(task) | ||
160 | 94 | task.start() | ||
161 | 95 | return task.id | ||
164 | 96 | 83 | ||
166 | 97 | def destroy(self): | 84 | def destroy(self, force): |
167 | 98 | utils.get_logger().debug("Destroy container with ID '%s'" % self.id) | 85 | utils.get_logger().debug("Destroy container with ID '%s'" % self.id) |
168 | 99 | 86 | ||
169 | 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] |
170 | @@ -102,10 +89,7 @@ | |||
171 | 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) |
172 | 103 | return tasks[0].id | 90 | return tasks[0].id |
173 | 104 | 91 | ||
178 | 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)) |
175 | 106 | self._tasks.append(task) | ||
176 | 107 | task.start() | ||
177 | 108 | return task.id | ||
179 | 109 | 93 | ||
180 | 110 | def update(self): | 94 | def update(self): |
181 | 111 | utils.get_logger().debug("Update container with ID '%s'" % self.id) | 95 | utils.get_logger().debug("Update container with ID '%s'" % self.id) |
182 | @@ -115,21 +99,14 @@ | |||
183 | 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) |
184 | 116 | return tasks[0].id | 100 | return tasks[0].id |
185 | 117 | 101 | ||
190 | 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)) |
187 | 119 | self._tasks.append(task) | ||
188 | 120 | task.start() | ||
189 | 121 | return task.id | ||
191 | 122 | 103 | ||
192 | 123 | # Tasks which don't require starting/stopping the container | 104 | # Tasks which don't require starting/stopping the container |
193 | 124 | 105 | ||
194 | 125 | def list_app_ids(self): | 106 | def list_app_ids(self): |
195 | 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) |
196 | 127 | 108 | ||
202 | 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)) |
198 | 129 | |||
199 | 130 | self._tasks.append(task) | ||
200 | 131 | task.start() | ||
201 | 132 | return task.id | ||
203 | 133 | 110 | ||
204 | 134 | def search(self, query): | 111 | def search(self, query): |
205 | 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)) |
206 | @@ -137,11 +114,7 @@ | |||
207 | 137 | if utils.is_snap_environment(): | 114 | if utils.is_snap_environment(): |
208 | 138 | raise Exception("This operation is not currently supported within the snap") | 115 | raise Exception("This operation is not currently supported within the snap") |
209 | 139 | 116 | ||
215 | 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)) |
211 | 141 | self._tasks.append(task) | ||
212 | 142 | task.start() | ||
213 | 143 | |||
214 | 144 | return task.id | ||
216 | 145 | 118 | ||
217 | 146 | def app_info(self, package_name): | 119 | def app_info(self, package_name): |
218 | 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)) |
219 | @@ -150,8 +123,5 @@ | |||
220 | 150 | raise Exception("This operation is not currently supported within the snap") | 123 | raise Exception("This operation is not currently supported within the snap") |
221 | 151 | 124 | ||
222 | 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] |
228 | 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, |
229 | 154 | 127 | self._config, self._monitor, self._client)) | |
225 | 155 | self._tasks.append(task) | ||
226 | 156 | task.start() | ||
227 | 157 | return task.id | ||
230 | 158 | 128 | ||
231 | === modified file 'python/libertine/service/download.py' | |||
232 | --- python/libertine/service/download.py 2017-03-07 18:38:05 +0000 | |||
233 | +++ python/libertine/service/download.py 2017-04-07 16:34:30 +0000 | |||
234 | @@ -14,7 +14,7 @@ | |||
235 | 14 | 14 | ||
236 | 15 | 15 | ||
237 | 16 | import dbus.service | 16 | import dbus.service |
239 | 17 | import threading | 17 | import multiprocessing |
240 | 18 | 18 | ||
241 | 19 | from . import constants | 19 | from . import constants |
242 | 20 | from libertine import utils | 20 | from libertine import utils |
243 | @@ -23,39 +23,35 @@ | |||
244 | 23 | 23 | ||
245 | 24 | class Download(dbus.service.Object): | 24 | class Download(dbus.service.Object): |
246 | 25 | def __init__(self, connection, id): | 25 | def __init__(self, connection, id): |
250 | 26 | self._finished = False | 26 | self._finished = multiprocessing.Event() |
251 | 27 | self._result = '' | 27 | self._result = multiprocessing.SimpleQueue() |
252 | 28 | self._error = '' | 28 | self._error = multiprocessing.SimpleQueue() |
253 | 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)) |
254 | 30 | 30 | ||
255 | 31 | # Disabled until something requires the Download interface | ||
256 | 32 | # self.emit_processing() | ||
257 | 33 | |||
258 | 34 | # This is currently how services using the Ubuntu SDK to show progress | ||
259 | 35 | # determine whether or not an operation is running. | ||
260 | 36 | def emit_processing(self): | ||
261 | 37 | if not self.done: | ||
262 | 38 | self.processing(self.id) | ||
263 | 39 | threading.Timer(0.5, self.emit_processing).start() | ||
264 | 40 | |||
265 | 41 | @property | 31 | @property |
266 | 42 | def id(self): | 32 | def id(self): |
267 | 43 | return self._object_path | 33 | return self._object_path |
268 | 44 | 34 | ||
269 | 45 | @property | 35 | @property |
270 | 46 | def done(self): | 36 | def done(self): |
272 | 47 | return self._finished | 37 | return self._finished.is_set() |
273 | 48 | 38 | ||
274 | 49 | @property | 39 | @property |
275 | 50 | def result(self): | 40 | def result(self): |
277 | 51 | return self._result.strip() | 41 | if self._result.empty(): |
278 | 42 | return '' | ||
279 | 43 | |||
280 | 44 | return self._result.get() | ||
281 | 52 | 45 | ||
282 | 53 | @property | 46 | @property |
283 | 54 | def last_error(self): | 47 | def last_error(self): |
285 | 55 | return self._error | 48 | if self._error.empty(): |
286 | 49 | return '' | ||
287 | 50 | |||
288 | 51 | return self._error.get() | ||
289 | 56 | 52 | ||
290 | 57 | def data(self, message): | 53 | def data(self, message): |
292 | 58 | self._result += message + '\n' | 54 | self._result.put(message) |
293 | 59 | 55 | ||
294 | 60 | # Signals to satisfy the download interface | 56 | # Signals to satisfy the download interface |
295 | 61 | 57 | ||
296 | @@ -66,7 +62,7 @@ | |||
297 | 66 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o') | 62 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='o') |
298 | 67 | def finished(self, path): | 63 | def finished(self, path): |
299 | 68 | utils.get_logger().debug("emit finished('%s')" % path) | 64 | utils.get_logger().debug("emit finished('%s')" % path) |
301 | 69 | self._finished = True | 65 | self._finished.set() |
302 | 70 | 66 | ||
303 | 71 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE) | 67 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE) |
304 | 72 | def progress(self, received, total): | 68 | def progress(self, received, total): |
305 | @@ -75,5 +71,5 @@ | |||
306 | 75 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='s') | 71 | @dbus.service.signal(constants.DOWNLOAD_INTERFACE, signature='s') |
307 | 76 | def error(self, message): | 72 | def error(self, message): |
308 | 77 | utils.get_logger().error("emit error(%s)" % message) | 73 | utils.get_logger().error("emit error(%s)" % message) |
311 | 78 | self._error = message | 74 | self._error.put(message) |
312 | 79 | self._finished = True | 75 | self._finished.set() |
313 | 80 | 76 | ||
314 | === modified file 'python/libertine/service/operations.py' | |||
315 | --- python/libertine/service/operations.py 2017-03-09 14:40:58 +0000 | |||
316 | +++ python/libertine/service/operations.py 2017-04-07 16:34:30 +0000 | |||
317 | @@ -72,11 +72,11 @@ | |||
318 | 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) |
319 | 73 | 73 | ||
320 | 74 | @dbus.service.method(constants.OPERATIONS_INTERFACE, | 74 | @dbus.service.method(constants.OPERATIONS_INTERFACE, |
322 | 75 | in_signature='s', | 75 | in_signature='sb', |
323 | 76 | out_signature='o') | 76 | out_signature='o') |
327 | 77 | def destroy(self, container_id): | 77 | def destroy(self, container_id, force=False): |
328 | 78 | utils.get_logger().debug("destroy('{}')".format(container_id)) | 78 | utils.get_logger().debug("destroy('{}', {})".format(container_id, force)) |
329 | 79 | return self._dispatcher.destroy(container_id) | 79 | return self._dispatcher.destroy(container_id, force) |
330 | 80 | 80 | ||
331 | 81 | @dbus.service.method(constants.OPERATIONS_INTERFACE, | 81 | @dbus.service.method(constants.OPERATIONS_INTERFACE, |
332 | 82 | in_signature='s', | 82 | in_signature='s', |
333 | @@ -86,11 +86,11 @@ | |||
334 | 86 | return self._dispatcher.update(container_id) | 86 | return self._dispatcher.update(container_id) |
335 | 87 | 87 | ||
336 | 88 | @dbus.service.method(constants.OPERATIONS_INTERFACE, | 88 | @dbus.service.method(constants.OPERATIONS_INTERFACE, |
338 | 89 | in_signature='ss', | 89 | in_signature='ssb', |
339 | 90 | out_signature='o') | 90 | out_signature='o') |
343 | 91 | def install(self, container_id, package_name): | 91 | def install(self, container_id, package_name, update_cache=False): |
344 | 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)) |
345 | 93 | return self._dispatcher.install(container_id, package_name) | 93 | return self._dispatcher.install(container_id, package_name, update_cache) |
346 | 94 | 94 | ||
347 | 95 | @dbus.service.method(constants.OPERATIONS_INTERFACE, | 95 | @dbus.service.method(constants.OPERATIONS_INTERFACE, |
348 | 96 | in_signature='ss', | 96 | in_signature='ss', |
349 | 97 | 97 | ||
350 | === modified file 'python/libertine/service/operations_monitor.py' | |||
351 | --- python/libertine/service/operations_monitor.py 2017-03-27 20:06:39 +0000 | |||
352 | +++ python/libertine/service/operations_monitor.py 2017-04-07 16:34:30 +0000 | |||
353 | @@ -68,6 +68,10 @@ | |||
354 | 68 | if op: | 68 | if op: |
355 | 69 | op.data(message) | 69 | op.data(message) |
356 | 70 | 70 | ||
357 | 71 | @dbus.service.signal(constants.OPERATIONS_MONITOR_INTERFACE, signature='os') | ||
358 | 72 | def output(self, path, message): | ||
359 | 73 | utils.get_logger().debug(message) | ||
360 | 74 | |||
361 | 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') |
362 | 72 | def running(self, path): | 76 | def running(self, path): |
363 | 73 | op = self._operation(path) | 77 | op = self._operation(path) |
364 | 74 | 78 | ||
365 | === added file 'python/libertine/service/output_redirector.py' | |||
366 | --- python/libertine/service/output_redirector.py 1970-01-01 00:00:00 +0000 | |||
367 | +++ python/libertine/service/output_redirector.py 2017-04-07 16:34:30 +0000 | |||
368 | @@ -0,0 +1,67 @@ | |||
369 | 1 | # Copyright 2017 Canonical Ltd. | ||
370 | 2 | # | ||
371 | 3 | # This program is free software: you can redistribute it and/or modify | ||
372 | 4 | # it under the terms of the GNU General Public License as published by | ||
373 | 5 | # the Free Software Foundation; version 3 of the License. | ||
374 | 6 | # | ||
375 | 7 | # This program is distributed in the hope that it will be useful, | ||
376 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
377 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
378 | 10 | # GNU General Public License for more details. | ||
379 | 11 | # | ||
380 | 12 | # You should have received a copy of the GNU General Public License | ||
381 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
382 | 14 | |||
383 | 15 | |||
384 | 16 | import os | ||
385 | 17 | import sys | ||
386 | 18 | |||
387 | 19 | from libertine import utils | ||
388 | 20 | |||
389 | 21 | |||
390 | 22 | class OutputRedirector(object): | ||
391 | 23 | def __init__(self, ident, cleanup=True): | ||
392 | 24 | self.cleanup = cleanup | ||
393 | 25 | |||
394 | 26 | if utils.is_snap_environment(): | ||
395 | 27 | self.cache_path = '%s/.cache/libertined' % os.environ['SNAP_USER_COMMON'] | ||
396 | 28 | else: | ||
397 | 29 | self.cache_path = os.path.join(os.getenv(('XDG_DATA_HOME'), os.getenv('HOME')), '.cache/libertined') | ||
398 | 30 | |||
399 | 31 | self.path = '{}/{}.log'.format(self.cache_path, ident) | ||
400 | 32 | self._output_file = None | ||
401 | 33 | self._copied_stdout = None | ||
402 | 34 | self._copied_stderr = None | ||
403 | 35 | |||
404 | 36 | def _fileno(self, file_or_fd): | ||
405 | 37 | return getattr(file_or_fd, 'fileno', lambda: file_or_fd)() | ||
406 | 38 | |||
407 | 39 | def _do_redirect(self, stream): | ||
408 | 40 | fd = self._fileno(stream) | ||
409 | 41 | copied_stream = os.fdopen(os.dup(fd), 'wb') | ||
410 | 42 | stream.flush() | ||
411 | 43 | os.dup2(self._fileno(self._output_file), fd) | ||
412 | 44 | return copied_stream, fd | ||
413 | 45 | |||
414 | 46 | def _undo_redirect(self, stream, stream_fd, copied_stream): | ||
415 | 47 | stream.flush() | ||
416 | 48 | os.dup2(copied_stream.fileno(), stream_fd) | ||
417 | 49 | copied_stream.close() | ||
418 | 50 | |||
419 | 51 | def __enter__(self): | ||
420 | 52 | os.makedirs(self.cache_path, exist_ok=True) | ||
421 | 53 | self._output_file = open(self.path, 'w') | ||
422 | 54 | self._copied_stdout, self.stdout_fd = self._do_redirect(sys.stdout) | ||
423 | 55 | self._copied_stderr, self.stderr_fd = self._do_redirect(sys.stderr) | ||
424 | 56 | |||
425 | 57 | return self | ||
426 | 58 | |||
427 | 59 | def __exit__(self, type, value, tb): | ||
428 | 60 | if self._copied_stdout and self.stdout_fd: | ||
429 | 61 | self._undo_redirect(sys.stdout, self.stdout_fd, self._copied_stdout) | ||
430 | 62 | if self._copied_stderr and self.stderr_fd: | ||
431 | 63 | self._undo_redirect(sys.stderr, self.stderr_fd, self._copied_stderr) | ||
432 | 64 | if self._output_file: | ||
433 | 65 | self._output_file.close() | ||
434 | 66 | if self.cleanup and os.path.exists(self.path): | ||
435 | 67 | os.remove(self.path) | ||
436 | 0 | 68 | ||
437 | === modified file 'python/libertine/service/task_dispatcher.py' | |||
438 | --- python/libertine/service/task_dispatcher.py 2017-03-27 20:06:39 +0000 | |||
439 | +++ python/libertine/service/task_dispatcher.py 2017-04-07 16:34:30 +0000 | |||
440 | @@ -14,25 +14,20 @@ | |||
441 | 14 | 14 | ||
442 | 15 | 15 | ||
443 | 16 | import libertine.ContainersConfig | 16 | import libertine.ContainersConfig |
444 | 17 | |||
445 | 18 | from libertine import utils | ||
446 | 17 | from libertine.service.container import Container | 19 | from libertine.service.container import Container |
447 | 20 | from libertine.service.task_dispatcher_base import TaskDispatcherBase | ||
448 | 18 | from libertine.service.tasks import * | 21 | from libertine.service.tasks import * |
453 | 19 | from libertine import utils | 22 | from multiprocessing import Lock |
454 | 20 | 23 | ||
455 | 21 | 24 | ||
456 | 22 | class TaskDispatcher(object): | 25 | class TaskDispatcher(TaskDispatcherBase): |
457 | 23 | def __init__(self, monitor, client): | 26 | def __init__(self, monitor, client): |
460 | 24 | self._monitor = monitor | 27 | super().__init__(monitor, client) |
459 | 25 | self._client = client | ||
461 | 26 | self._config = libertine.ContainersConfig.ContainersConfig() | 28 | self._config = libertine.ContainersConfig.ContainersConfig() |
462 | 27 | self._containerless_tasks = [] | ||
463 | 28 | self._tasks = [] | ||
464 | 29 | self._containers = [] | 29 | self._containers = [] |
465 | 30 | 30 | ||
466 | 31 | def _cleanup_task(self, task): | ||
467 | 32 | utils.get_logger().debug("cleaning up containerless task '%s'" % task.id) | ||
468 | 33 | if task in self._tasks: | ||
469 | 34 | self._tasks.remove(task) | ||
470 | 35 | |||
471 | 36 | def _cleanup_container(self, container): | 31 | def _cleanup_container(self, container): |
472 | 37 | utils.get_logger().debug("cleaning up container '%s'" % container.id) | 32 | utils.get_logger().debug("cleaning up container '%s'" % container.id) |
473 | 38 | if container in self._containers: | 33 | if container in self._containers: |
474 | @@ -66,9 +61,9 @@ | |||
475 | 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)) |
476 | 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) |
477 | 68 | 63 | ||
479 | 69 | def install(self, container_id, package_name): | 64 | def install(self, container_id, package_name, update_cache): |
480 | 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)) |
482 | 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) |
483 | 72 | 67 | ||
484 | 73 | def remove(self, container_id, package_name): | 68 | def remove(self, container_id, package_name): |
485 | 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)) |
486 | @@ -78,9 +73,9 @@ | |||
487 | 78 | utils.get_logger().debug("dispatching create of container '%s'" % container_id) | 73 | utils.get_logger().debug("dispatching create of container '%s'" % container_id) |
488 | 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) |
489 | 80 | 75 | ||
491 | 81 | def destroy(self, container_id): | 76 | def destroy(self, container_id, force): |
492 | 82 | utils.get_logger().debug("dispatching destroy container '%s'" % container_id) | 77 | utils.get_logger().debug("dispatching destroy container '%s'" % container_id) |
494 | 83 | return self._find_or_create_container(container_id).destroy() | 78 | return self._find_or_create_container(container_id).destroy(force) |
495 | 84 | 79 | ||
496 | 85 | def update(self, container_id): | 80 | def update(self, container_id): |
497 | 86 | utils.get_logger().debug("dispatching update container '%s'" % container_id) | 81 | utils.get_logger().debug("dispatching update container '%s'" % container_id) |
498 | @@ -99,17 +94,10 @@ | |||
499 | 99 | container = self._find_container(container_id) | 94 | container = self._find_container(container_id) |
500 | 100 | if container is not None: | 95 | if container is not None: |
501 | 101 | related_task_ids = container.tasks | 96 | related_task_ids = container.tasks |
502 | 102 | task = ContainerInfoTask(container_id, related_task_ids, self._config, self._monitor, self._cleanup_task) | ||
503 | 103 | self._tasks.append(task) | ||
504 | 104 | task.start() | ||
505 | 105 | 97 | ||
507 | 106 | return task.id | 98 | return self._add_task(ContainerInfoTask(container_id, related_task_ids, self._config, self._monitor)) |
508 | 107 | 99 | ||
509 | 108 | def list(self): | 100 | def list(self): |
510 | 109 | utils.get_logger().debug("dispatching list all containers") | 101 | utils.get_logger().debug("dispatching list all containers") |
511 | 110 | 102 | ||
517 | 111 | task = ListTask(self._config, self._monitor, self._cleanup_task) | 103 | return self._add_task(ListTask(self._config, self._monitor)) |
513 | 112 | self._tasks.append(task) | ||
514 | 113 | task.start() | ||
515 | 114 | |||
516 | 115 | return task.id | ||
518 | 116 | 104 | ||
519 | === added file 'python/libertine/service/task_dispatcher_base.py' | |||
520 | --- python/libertine/service/task_dispatcher_base.py 1970-01-01 00:00:00 +0000 | |||
521 | +++ python/libertine/service/task_dispatcher_base.py 2017-04-07 16:34:30 +0000 | |||
522 | @@ -0,0 +1,49 @@ | |||
523 | 1 | # Copyright 2017 Canonical Ltd. | ||
524 | 2 | # | ||
525 | 3 | # This program is free software: you can redistribute it and/or modify | ||
526 | 4 | # it under the terms of the GNU General Public License as published by | ||
527 | 5 | # the Free Software Foundation; version 3 of the License. | ||
528 | 6 | # | ||
529 | 7 | # This program is distributed in the hope that it will be useful, | ||
530 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
531 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
532 | 10 | # GNU General Public License for more details. | ||
533 | 11 | # | ||
534 | 12 | # You should have received a copy of the GNU General Public License | ||
535 | 13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
536 | 14 | |||
537 | 15 | |||
538 | 16 | import multiprocessing | ||
539 | 17 | import os | ||
540 | 18 | |||
541 | 19 | from libertine import utils | ||
542 | 20 | from threading import Timer | ||
543 | 21 | |||
544 | 22 | |||
545 | 23 | class TaskDispatcherBase(object): | ||
546 | 24 | def __init__(self, monitor, client): | ||
547 | 25 | self._monitor = monitor | ||
548 | 26 | self._client = client | ||
549 | 27 | self._tasks = [] | ||
550 | 28 | |||
551 | 29 | self._cleanup_cycle = 1 | ||
552 | 30 | if os.getenv("LIBERTINED_TESTING", False): | ||
553 | 31 | self._cleanup_cycle = 0.1 | ||
554 | 32 | |||
555 | 33 | def _cleanup(self): | ||
556 | 34 | for task in [task for task in self._tasks if task.should_delete]: | ||
557 | 35 | utils.get_logger().debug("Cleaning up task '{}'".format(task.id)) | ||
558 | 36 | task.thread.join() | ||
559 | 37 | self._monitor.remove_from_connection(task.id) | ||
560 | 38 | self._tasks.remove(task) | ||
561 | 39 | |||
562 | 40 | if len(self._tasks) > 0: | ||
563 | 41 | Timer(self._cleanup_cycle, self._cleanup).start() | ||
564 | 42 | |||
565 | 43 | def _add_task(self, task): | ||
566 | 44 | self._tasks.append(task) | ||
567 | 45 | task.start() | ||
568 | 46 | if len(self._tasks) == 1: | ||
569 | 47 | Timer(self._cleanup_cycle, self._cleanup).start() | ||
570 | 48 | |||
571 | 49 | return task.id | ||
572 | 0 | 50 | ||
573 | === modified file 'python/libertine/service/tasks/app_info_task.py' | |||
574 | --- python/libertine/service/tasks/app_info_task.py 2017-03-07 20:56:42 +0000 | |||
575 | +++ python/libertine/service/tasks/app_info_task.py 2017-04-07 16:34:30 +0000 | |||
576 | @@ -13,22 +13,24 @@ | |||
577 | 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/>. |
578 | 14 | 14 | ||
579 | 15 | 15 | ||
581 | 16 | from .base_task import BaseTask | 16 | from .base_task import ContainerBaseTask |
582 | 17 | from libertine import utils | 17 | from libertine import utils |
583 | 18 | 18 | ||
584 | 19 | 19 | ||
588 | 20 | class AppInfoTask(BaseTask): | 20 | class AppInfoTask(ContainerBaseTask): |
589 | 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): |
590 | 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) |
591 | 23 | self._cache = cache | 23 | self._cache = cache |
592 | 24 | self._app_id = app_id | 24 | self._app_id = app_id |
593 | 25 | self._tasks = tasks | 25 | self._tasks = tasks |
594 | 26 | 26 | ||
595 | 27 | def _run(self): | 27 | def _run(self): |
600 | 28 | app = self._cache.app_info(self._app_id) | 28 | app = {} |
601 | 29 | if app == {}: | 29 | if self._cache: |
602 | 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) |
603 | 31 | return | 31 | if app == {}: |
604 | 32 | self._error("Could not find app info for '%s' in container '%s'" % (self._app_id, self._container)) | ||
605 | 33 | return | ||
606 | 32 | 34 | ||
607 | 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 '' |
608 | 34 | app['task_ids'] = self._tasks | 36 | app['task_ids'] = self._tasks |
609 | 35 | 37 | ||
610 | === modified file 'python/libertine/service/tasks/base_task.py' | |||
611 | --- python/libertine/service/tasks/base_task.py 2017-03-27 20:06:39 +0000 | |||
612 | +++ python/libertine/service/tasks/base_task.py 2017-04-07 16:34:30 +0000 | |||
613 | @@ -13,9 +13,13 @@ | |||
614 | 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/>. |
615 | 14 | 14 | ||
616 | 15 | 15 | ||
618 | 16 | import threading | 16 | import multiprocessing |
619 | 17 | import os | ||
620 | 18 | import time | ||
621 | 17 | 19 | ||
622 | 18 | from abc import ABCMeta, abstractmethod | 20 | from abc import ABCMeta, abstractmethod |
623 | 21 | from libertine import utils | ||
624 | 22 | from libertine.service import output_redirector | ||
625 | 19 | 23 | ||
626 | 20 | 24 | ||
627 | 21 | class BaseTask(metaclass=ABCMeta): | 25 | class BaseTask(metaclass=ABCMeta): |
628 | @@ -25,14 +29,14 @@ | |||
629 | 25 | in a separate thread. Override _before to implement pre-execution actions | 29 | in a separate thread. Override _before to implement pre-execution actions |
630 | 26 | without locking; if _before returns False, _run will not be executed. | 30 | without locking; if _before returns False, _run will not be executed. |
631 | 27 | """ | 31 | """ |
633 | 28 | def __init__(self, lock, container_id, config, monitor, callback): | 32 | def __init__(self, lock, container_id, config, monitor): |
634 | 29 | self._lock = lock | 33 | self._lock = lock |
635 | 30 | self._container = container_id | 34 | self._container = container_id |
636 | 31 | self._config = config | 35 | self._config = config |
638 | 32 | self._callback = callback | 36 | self._finished_at = multiprocessing.SimpleQueue() |
639 | 33 | self._monitor = monitor | 37 | self._monitor = monitor |
640 | 34 | self._operation_id = None | 38 | self._operation_id = None |
642 | 35 | self._instant_callback = False # for testing | 39 | self._delete_at = None |
643 | 36 | 40 | ||
644 | 37 | def matches(self, container, klass): | 41 | def matches(self, container, klass): |
645 | 38 | return self._container == container and self.__class__ == klass | 42 | return self._container == container and self.__class__ == klass |
646 | @@ -53,38 +57,62 @@ | |||
647 | 53 | def running(self): | 57 | def running(self): |
648 | 54 | return not self._monitor.done(self._operation_id) | 58 | return not self._monitor.done(self._operation_id) |
649 | 55 | 59 | ||
655 | 56 | def _delayed_callback(self): | 60 | @property |
656 | 57 | if self._instant_callback: | 61 | def should_delete(self): |
657 | 58 | self._callback(self) | 62 | if not self._finished_at.empty(): |
658 | 59 | else: | 63 | self._delete_at = self._finished_at.get() |
659 | 60 | threading.Timer(10, lambda: (self._monitor.remove_from_connection(self._operation_id), self._callback(self))).start() | 64 | if not os.getenv("LIBERTINED_TESTING"): |
660 | 65 | self._delete_at += 5 | ||
661 | 66 | |||
662 | 67 | if self._delete_at: | ||
663 | 68 | return self._delete_at < time.time() | ||
664 | 69 | |||
665 | 70 | return False | ||
666 | 71 | |||
667 | 72 | def _finish(self): | ||
668 | 73 | self._finished_at.put(time.time()) | ||
669 | 61 | 74 | ||
670 | 62 | def start(self): | 75 | def start(self): |
671 | 63 | self._operation_id = self._monitor.new_operation() | 76 | self._operation_id = self._monitor.new_operation() |
675 | 64 | thread = threading.Thread(target=self.run) | 77 | self.thread = multiprocessing.Process(target=self.run) |
676 | 65 | thread.start() | 78 | self.thread.start() |
677 | 66 | return thread | 79 | return self.thread |
678 | 80 | |||
679 | 81 | def watch_file(self, finished, path): | ||
680 | 82 | with open(path, 'rb') as thefile: | ||
681 | 83 | thefile.seek(0, 2) | ||
682 | 84 | while not finished.is_set(): | ||
683 | 85 | finished.wait(0.1) | ||
684 | 86 | line = thefile.readline().decode('utf-8').rstrip() | ||
685 | 87 | while line: | ||
686 | 88 | self._monitor.output(self._operation_id, message) | ||
687 | 89 | line = thefile.readline().decode('utf-8').rstrip() | ||
688 | 67 | 90 | ||
689 | 68 | def run(self): | 91 | def run(self): |
690 | 69 | self._refresh_database() | 92 | self._refresh_database() |
691 | 70 | 93 | ||
692 | 71 | if not self._before(): | 94 | if not self._before(): |
693 | 72 | self._monitor.finished(self._operation_id) | 95 | self._monitor.finished(self._operation_id) |
695 | 73 | self._delayed_callback() | 96 | self._finish() |
696 | 74 | return | 97 | return |
697 | 75 | 98 | ||
701 | 76 | if self._lock is not None: | 99 | with output_redirector.OutputRedirector(self._operation_id.split("/")[-1]) as redirector: |
702 | 77 | with self._lock: | 100 | end_watch = multiprocessing.Event() |
703 | 78 | self._refresh_database(False) | 101 | multiprocessing.Process(target=self.watch_file, args=(end_watch, redirector.path)).start() |
704 | 102 | if self._lock is not None: | ||
705 | 103 | with self._lock: | ||
706 | 104 | self._refresh_database(False) | ||
707 | 105 | self._run() | ||
708 | 106 | else: | ||
709 | 107 | self._refresh_database() | ||
710 | 79 | self._run() | 108 | self._run() |
714 | 80 | else: | 109 | |
715 | 81 | self._refresh_database() | 110 | end_watch.set() |
713 | 82 | self._run() | ||
716 | 83 | 111 | ||
717 | 84 | if self.running: | 112 | if self.running: |
719 | 85 | self._finished() | 113 | self._monitor.finished(self._operation_id) |
720 | 86 | 114 | ||
722 | 87 | self._delayed_callback() | 115 | self._finish() |
723 | 88 | 116 | ||
724 | 89 | def _refresh_database(self, require_lock=True): | 117 | def _refresh_database(self, require_lock=True): |
725 | 90 | if self._config: | 118 | if self._config: |
726 | @@ -112,6 +140,6 @@ | |||
727 | 112 | 140 | ||
728 | 113 | 141 | ||
729 | 114 | class ContainerBaseTask(BaseTask): | 142 | class ContainerBaseTask(BaseTask): |
732 | 115 | def __init__(self, lock, container_id, config, monitor, client, callback): | 143 | def __init__(self, lock, container_id, config, monitor, client): |
733 | 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) |
734 | 117 | self._client = client | 145 | self._client = client |
735 | 118 | 146 | ||
736 | === modified file 'python/libertine/service/tasks/container_info_task.py' | |||
737 | --- python/libertine/service/tasks/container_info_task.py 2017-03-06 19:50:12 +0000 | |||
738 | +++ python/libertine/service/tasks/container_info_task.py 2017-04-07 16:34:30 +0000 | |||
739 | @@ -20,8 +20,8 @@ | |||
740 | 20 | 20 | ||
741 | 21 | 21 | ||
742 | 22 | class ContainerInfoTask(BaseTask): | 22 | class ContainerInfoTask(BaseTask): |
745 | 23 | def __init__(self, container_id, tasks, config, monitor, callback): | 23 | def __init__(self, container_id, tasks, config, monitor): |
746 | 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) |
747 | 25 | self._tasks = tasks | 25 | self._tasks = tasks |
748 | 26 | 26 | ||
749 | 27 | def _run(self): | 27 | def _run(self): |
750 | 28 | 28 | ||
751 | === modified file 'python/libertine/service/tasks/create_task.py' | |||
752 | --- python/libertine/service/tasks/create_task.py 2017-03-27 20:06:39 +0000 | |||
753 | +++ python/libertine/service/tasks/create_task.py 2017-04-07 16:34:30 +0000 | |||
754 | @@ -13,6 +13,8 @@ | |||
755 | 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/>. |
756 | 14 | 14 | ||
757 | 15 | 15 | ||
758 | 16 | import re | ||
759 | 17 | |||
760 | 16 | from .base_task import ContainerBaseTask | 18 | from .base_task import ContainerBaseTask |
761 | 17 | from libertine import LibertineContainer, utils | 19 | from libertine import LibertineContainer, utils |
762 | 18 | from libertine.HostInfo import HostInfo | 20 | from libertine.HostInfo import HostInfo |
763 | @@ -20,9 +22,9 @@ | |||
764 | 20 | 22 | ||
765 | 21 | class CreateTask(ContainerBaseTask): | 23 | class CreateTask(ContainerBaseTask): |
766 | 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, |
768 | 23 | config, lock, monitor, client, callback): | 25 | config, lock, monitor, client): |
769 | 24 | super().__init__(lock=lock, container_id=container_id, config=config, | 26 | super().__init__(lock=lock, container_id=container_id, config=config, |
771 | 25 | monitor=monitor, client=client, callback=callback) | 27 | monitor=monitor, client=client) |
772 | 26 | self._name = container_name | 28 | self._name = container_name |
773 | 27 | self._distro = distro | 29 | self._distro = distro |
774 | 28 | self._type = container_type | 30 | self._type = container_type |
775 | @@ -39,6 +41,7 @@ | |||
776 | 39 | self._error("Creating container '%s' failed" % self._container) | 41 | self._error("Creating container '%s' failed" % self._container) |
777 | 40 | else: | 42 | else: |
778 | 41 | self._config.update_container_install_status(self._container, "ready") | 43 | self._config.update_container_install_status(self._container, "ready") |
779 | 44 | utils.refresh_libertine_scope() | ||
780 | 42 | self._finished() | 45 | self._finished() |
781 | 43 | except RuntimeError as e: | 46 | except RuntimeError as e: |
782 | 44 | self._config.delete_container(self._container) | 47 | self._config.delete_container(self._container) |
783 | @@ -50,6 +53,10 @@ | |||
784 | 50 | self._error("Container '%s' already exists" % self._container) | 53 | self._error("Container '%s' already exists" % self._container) |
785 | 51 | return False | 54 | return False |
786 | 52 | 55 | ||
787 | 56 | if re.match("^[a-z0-9][a-z0-9+.-]+$", self._container) is None: | ||
788 | 57 | self._error("Container id '%s' invalid. ID must be of form ([a-z0-9][a-z0-9+.-]+)." % self._container) | ||
789 | 58 | return False | ||
790 | 59 | |||
791 | 53 | info = HostInfo() | 60 | info = HostInfo() |
792 | 54 | if not self._distro: | 61 | if not self._distro: |
793 | 55 | self._distro = info.get_host_distro_release() | 62 | self._distro = info.get_host_distro_release() |
794 | @@ -72,6 +79,10 @@ | |||
795 | 72 | 79 | ||
796 | 73 | if self._multiarch: | 80 | if self._multiarch: |
797 | 74 | self._config.update_container_multiarch_support(self._container, 'enabled') | 81 | self._config.update_container_multiarch_support(self._container, 'enabled') |
798 | 82 | else: | ||
799 | 83 | self._config.update_container_multiarch_support(self._container, 'disabled') | ||
800 | 84 | |||
801 | 85 | self._config.update_container_locale(self._container, info.get_host_locale()) | ||
802 | 75 | 86 | ||
803 | 76 | self._config.update_container_install_status(self._container, 'installing') | 87 | self._config.update_container_install_status(self._container, 'installing') |
804 | 77 | return True | 88 | return True |
805 | 78 | 89 | ||
806 | === modified file 'python/libertine/service/tasks/destroy_task.py' | |||
807 | --- python/libertine/service/tasks/destroy_task.py 2017-03-27 20:06:39 +0000 | |||
808 | +++ python/libertine/service/tasks/destroy_task.py 2017-04-07 16:34:30 +0000 | |||
809 | @@ -18,27 +18,28 @@ | |||
810 | 18 | 18 | ||
811 | 19 | 19 | ||
812 | 20 | class DestroyTask(ContainerBaseTask): | 20 | class DestroyTask(ContainerBaseTask): |
814 | 21 | def __init__(self, container_id, config, lock, monitor, client, callback): | 21 | def __init__(self, container_id, config, force, lock, monitor, client): |
815 | 22 | super().__init__(lock=lock, container_id=container_id, config=config, | 22 | super().__init__(lock=lock, container_id=container_id, config=config, |
817 | 23 | monitor=monitor, client=client, callback=callback) | 23 | monitor=monitor, client=client) |
818 | 24 | self._force = force | ||
819 | 24 | 25 | ||
820 | 25 | def _run(self): | 26 | def _run(self): |
821 | 26 | utils.get_logger().debug("Destroying container '%s'" % self._container) | 27 | utils.get_logger().debug("Destroying container '%s'" % self._container) |
822 | 27 | 28 | ||
823 | 28 | container = LibertineContainer(self._container, self._config, self._client) | 29 | container = LibertineContainer(self._container, self._config, self._client) |
825 | 29 | if not container.destroy_libertine_container(): | 30 | if not container.destroy_libertine_container(self._force): |
826 | 30 | self._error("Destroying container '%s' failed" % self._container) | 31 | self._error("Destroying container '%s' failed" % self._container) |
828 | 31 | self._config.update_container_install_status(self._container, "ready") | 32 | self._config.update_container_install_status(self._container, self._fallback) |
829 | 32 | return | 33 | return |
830 | 33 | 34 | ||
831 | 35 | self._config.update_container_install_status(self._container, "removed") | ||
832 | 34 | self._config.delete_container(self._container) | 36 | self._config.delete_container(self._container) |
833 | 35 | self._finished() | 37 | self._finished() |
834 | 36 | 38 | ||
835 | 39 | utils.refresh_libertine_scope() | ||
836 | 40 | |||
837 | 37 | def _before(self): | 41 | def _before(self): |
843 | 38 | utils.get_logger().debug("CreateTask::_before") | 42 | utils.get_logger().debug("DestroyTask::_before") |
844 | 39 | if self._config._get_value_by_key(self._container, 'installStatus') != 'ready': | 43 | self._fallback = self._config.get_container_install_status(self._container) |
840 | 40 | self._error("Container '%s' does not exist" % self._container) | ||
841 | 41 | return False | ||
842 | 42 | |||
845 | 43 | self._config.update_container_install_status(self._container, 'removing') | 44 | self._config.update_container_install_status(self._container, 'removing') |
846 | 44 | return True | 45 | return True |
847 | 45 | 46 | ||
848 | === modified file 'python/libertine/service/tasks/install_task.py' | |||
849 | --- python/libertine/service/tasks/install_task.py 2017-03-27 20:06:39 +0000 | |||
850 | +++ python/libertine/service/tasks/install_task.py 2017-04-07 16:34:30 +0000 | |||
851 | @@ -13,15 +13,19 @@ | |||
852 | 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/>. |
853 | 14 | 14 | ||
854 | 15 | 15 | ||
855 | 16 | import os | ||
856 | 17 | |||
857 | 16 | from .base_task import ContainerBaseTask | 18 | from .base_task import ContainerBaseTask |
858 | 17 | from libertine import LibertineContainer, utils | 19 | from libertine import LibertineContainer, utils |
859 | 18 | 20 | ||
860 | 19 | 21 | ||
861 | 20 | class InstallTask(ContainerBaseTask): | 22 | class InstallTask(ContainerBaseTask): |
863 | 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): |
864 | 22 | super().__init__(lock=lock, container_id=container_id, config=config, | 24 | super().__init__(lock=lock, container_id=container_id, config=config, |
866 | 23 | monitor=monitor, client=client, callback=callback) | 25 | monitor=monitor, client=client) |
867 | 24 | self._package = package_name | 26 | self._package = package_name |
868 | 27 | self._package_name = package_name | ||
869 | 28 | self._update_cache = update_cache | ||
870 | 25 | 29 | ||
871 | 26 | def matches(self, package, klass): | 30 | def matches(self, package, klass): |
872 | 27 | return self._package == package and self.__class__ == klass | 31 | return self._package == package and self.__class__ == klass |
873 | @@ -33,19 +37,30 @@ | |||
874 | 33 | def _run(self): | 37 | def _run(self): |
875 | 34 | utils.get_logger().debug("Installing package '%s'" % self._package) | 38 | utils.get_logger().debug("Installing package '%s'" % self._package) |
876 | 35 | container = LibertineContainer(self._container, self._config, self._client) | 39 | container = LibertineContainer(self._container, self._config, self._client) |
879 | 36 | if container.install_package(self._package): | 40 | if container.install_package(self._package, update_cache=self._update_cache, no_dialog=True): |
880 | 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") |
881 | 42 | utils.refresh_libertine_scope() | ||
882 | 38 | self._finished() | 43 | self._finished() |
883 | 39 | else: | 44 | else: |
885 | 40 | self._config.delete_package(self._container, self._package) | 45 | self._config.delete_package(self._container, self._package_name) |
886 | 41 | self._error("Package installation failed for '%s'" % self._package) | 46 | self._error("Package installation failed for '%s'" % self._package) |
887 | 42 | 47 | ||
888 | 43 | def _before(self): | 48 | def _before(self): |
889 | 44 | utils.get_logger().debug("InstallTask::_before") | 49 | utils.get_logger().debug("InstallTask::_before") |
893 | 45 | if self._config.package_exists(self._container, self._package): | 50 | is_debian_package = self._package.endswith('.deb') |
894 | 46 | self._error("Package '%s' already exists, skipping install" % self._package) | 51 | if is_debian_package: |
895 | 47 | return False | 52 | if os.path.exists(self._package): |
896 | 53 | self._package_name = utils.get_deb_package_name(self._package) | ||
897 | 54 | else: | ||
898 | 55 | libertine.utils.get_logger().error("'%s' does not exist." % self._package) | ||
899 | 56 | return False | ||
900 | 57 | |||
901 | 58 | if self._config.package_exists(self._container, self._package_name): | ||
902 | 59 | if not is_debian_package: | ||
903 | 60 | self._error("Package '%s' is already installed" % self._package_name) | ||
904 | 61 | return False | ||
905 | 48 | else: | 62 | else: |
909 | 49 | self._config.add_new_package(self._container, self._package) | 63 | self._config.add_new_package(self._container, self._package_name) |
910 | 50 | self._config.update_package_install_status(self._container, self._package, "installing") | 64 | |
911 | 51 | return True | 65 | self._config.update_package_install_status(self._container, self._package_name, "installing") |
912 | 66 | return True | ||
913 | 52 | 67 | ||
914 | === modified file 'python/libertine/service/tasks/list_app_ids_task.py' | |||
915 | --- python/libertine/service/tasks/list_app_ids_task.py 2017-03-16 19:59:08 +0000 | |||
916 | +++ python/libertine/service/tasks/list_app_ids_task.py 2017-04-07 16:34:30 +0000 | |||
917 | @@ -20,8 +20,8 @@ | |||
918 | 20 | 20 | ||
919 | 21 | 21 | ||
920 | 22 | class ListAppIdsTask(ContainerBaseTask): | 22 | class ListAppIdsTask(ContainerBaseTask): |
923 | 23 | def __init__(self, container_id, config, monitor, client, callback): | 23 | def __init__(self, container_id, config, monitor, client): |
924 | 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) |
925 | 25 | 25 | ||
926 | 26 | def _run(self): | 26 | def _run(self): |
927 | 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) |
928 | 28 | 28 | ||
929 | === modified file 'python/libertine/service/tasks/list_task.py' | |||
930 | --- python/libertine/service/tasks/list_task.py 2017-03-27 20:06:39 +0000 | |||
931 | +++ python/libertine/service/tasks/list_task.py 2017-04-07 16:34:30 +0000 | |||
932 | @@ -20,8 +20,8 @@ | |||
933 | 20 | 20 | ||
934 | 21 | 21 | ||
935 | 22 | class ListTask(BaseTask): | 22 | class ListTask(BaseTask): |
938 | 23 | def __init__(self, config, monitor, callback): | 23 | def __init__(self, config, monitor): |
939 | 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) |
940 | 25 | 25 | ||
941 | 26 | def _run(self): | 26 | def _run(self): |
942 | 27 | self._data(json.dumps(self._config.get_containers())) | 27 | self._data(json.dumps(self._config.get_containers())) |
943 | 28 | 28 | ||
944 | === modified file 'python/libertine/service/tasks/remove_task.py' | |||
945 | --- python/libertine/service/tasks/remove_task.py 2017-03-27 20:06:39 +0000 | |||
946 | +++ python/libertine/service/tasks/remove_task.py 2017-04-07 16:34:30 +0000 | |||
947 | @@ -18,8 +18,8 @@ | |||
948 | 18 | 18 | ||
949 | 19 | 19 | ||
950 | 20 | class RemoveTask(ContainerBaseTask): | 20 | class RemoveTask(ContainerBaseTask): |
953 | 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): |
954 | 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) |
955 | 23 | self._package = package_name | 23 | self._package = package_name |
956 | 24 | 24 | ||
957 | 25 | def matches(self, package, klass): | 25 | def matches(self, package, klass): |
958 | @@ -32,8 +32,9 @@ | |||
959 | 32 | def _run(self): | 32 | def _run(self): |
960 | 33 | utils.get_logger().debug("Removing package '%s'" % self._package) | 33 | utils.get_logger().debug("Removing package '%s'" % self._package) |
961 | 34 | container = LibertineContainer(self._container, self._config, self._client) | 34 | container = LibertineContainer(self._container, self._config, self._client) |
963 | 35 | if container.remove_package(self._package): | 35 | if container.remove_package(self._package, no_dialog=True): |
964 | 36 | self._config.delete_package(self._container, self._package) | 36 | self._config.delete_package(self._container, self._package) |
965 | 37 | utils.refresh_libertine_scope() | ||
966 | 37 | self._finished() | 38 | self._finished() |
967 | 38 | else: | 39 | else: |
968 | 39 | self._config.update_package_install_status(self._container, self._package, 'installed') | 40 | self._config.update_package_install_status(self._container, self._package, 'installed') |
969 | 40 | 41 | ||
970 | === modified file 'python/libertine/service/tasks/search_task.py' | |||
971 | --- python/libertine/service/tasks/search_task.py 2017-03-07 18:38:05 +0000 | |||
972 | +++ python/libertine/service/tasks/search_task.py 2017-04-07 16:34:30 +0000 | |||
973 | @@ -13,15 +13,21 @@ | |||
974 | 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/>. |
975 | 14 | 14 | ||
976 | 15 | 15 | ||
978 | 16 | from .base_task import BaseTask | 16 | from .base_task import ContainerBaseTask |
979 | 17 | from libertine import utils | 17 | from libertine import utils |
980 | 18 | 18 | ||
981 | 19 | 19 | ||
985 | 20 | class SearchTask(BaseTask): | 20 | class SearchTask(ContainerBaseTask): |
986 | 21 | def __init__(self, container_id, cache, query, monitor, callback): | 21 | def __init__(self, container_id, cache, query, config, monitor, client): |
987 | 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) |
988 | 23 | self._cache = cache | 23 | self._cache = cache |
989 | 24 | self._query = query | 24 | self._query = query |
990 | 25 | 25 | ||
991 | 26 | def _run(self): | 26 | def _run(self): |
993 | 27 | self._data(str(self._cache.search(self._query))) | 27 | if self._cache: |
994 | 28 | self._data(str(self._cache.search(self._query))) | ||
995 | 29 | else: | ||
996 | 30 | container = LibertineContainer(self._container, self._config, self._client) | ||
997 | 31 | if container.search_package_cache(self._query) is not 0: | ||
998 | 32 | self._error("Search for '{}' in container '{}' exited with non-zero status" | ||
999 | 33 | .format(self._container, self._query)) | ||
1000 | 28 | 34 | ||
1001 | === modified file 'python/libertine/service/tasks/update_task.py' | |||
1002 | --- python/libertine/service/tasks/update_task.py 2017-03-09 16:02:22 +0000 | |||
1003 | +++ python/libertine/service/tasks/update_task.py 2017-04-07 16:34:30 +0000 | |||
1004 | @@ -14,21 +14,34 @@ | |||
1005 | 14 | 14 | ||
1006 | 15 | 15 | ||
1007 | 16 | from .base_task import ContainerBaseTask | 16 | from .base_task import ContainerBaseTask |
1009 | 17 | from libertine import LibertineContainer, utils | 17 | from libertine import LibertineContainer, utils, HostInfo |
1010 | 18 | 18 | ||
1011 | 19 | 19 | ||
1012 | 20 | class UpdateTask(ContainerBaseTask): | 20 | class UpdateTask(ContainerBaseTask): |
1014 | 21 | def __init__(self, container_id, config, lock, monitor, client, callback): | 21 | def __init__(self, container_id, config, lock, monitor, client): |
1015 | 22 | super().__init__(lock=lock, container_id=container_id, config=config, | 22 | super().__init__(lock=lock, container_id=container_id, config=config, |
1017 | 23 | monitor=monitor, client=client, callback=callback) | 23 | monitor=monitor, client=client) |
1018 | 24 | |||
1019 | 25 | def _get_updated_locale(self): | ||
1020 | 26 | host_locale = HostInfo.HostInfo().get_host_locale() | ||
1021 | 27 | |||
1022 | 28 | if host_locale == self._config.get_container_locale(self._container): | ||
1023 | 29 | return None | ||
1024 | 30 | |||
1025 | 31 | return host_locale | ||
1026 | 24 | 32 | ||
1027 | 25 | def _run(self): | 33 | def _run(self): |
1028 | 26 | utils.get_logger().debug("Updating container '%s'" % self._container) | 34 | utils.get_logger().debug("Updating container '%s'" % self._container) |
1029 | 27 | container = LibertineContainer(self._container, self._config, self._client) | 35 | container = LibertineContainer(self._container, self._config, self._client) |
1030 | 28 | self._config.update_container_install_status(self._container, "updating") | 36 | self._config.update_container_install_status(self._container, "updating") |
1032 | 29 | if not container.update_libertine_container(): | 37 | |
1033 | 38 | new_locale = self._get_updated_locale() | ||
1034 | 39 | if not container.update_libertine_container(new_locale): | ||
1035 | 30 | self._error("Failed to update container '%s'" % self._container) | 40 | self._error("Failed to update container '%s'" % self._container) |
1036 | 31 | 41 | ||
1037 | 42 | if new_locale: | ||
1038 | 43 | self._config.update_container_locale(self._container, new_locale) | ||
1039 | 44 | |||
1040 | 32 | self._config.update_container_install_status(self._container, "ready") | 45 | self._config.update_container_install_status(self._container, "ready") |
1041 | 33 | 46 | ||
1042 | 34 | def _before(self): | 47 | def _before(self): |
1043 | 35 | 48 | ||
1044 | === modified file 'tests/integration/CMakeLists.txt' | |||
1045 | --- tests/integration/CMakeLists.txt 2017-03-27 20:06:39 +0000 | |||
1046 | +++ tests/integration/CMakeLists.txt 2017-04-07 16:34:30 +0000 | |||
1047 | @@ -1,7 +1,7 @@ | |||
1048 | 1 | add_test(test_libertine_service dbus-run-session -- /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/test_libertine_service.py) | 1 | add_test(test_libertine_service dbus-run-session -- /usr/bin/python3 ${CMAKE_CURRENT_SOURCE_DIR}/test_libertine_service.py) |
1049 | 2 | set_tests_properties(test_libertine_service | 2 | set_tests_properties(test_libertine_service |
1050 | 3 | PROPERTIES ENVIRONMENT | 3 | PROPERTIES ENVIRONMENT |
1052 | 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};") |
1053 | 5 | 5 | ||
1054 | 6 | add_executable( | 6 | add_executable( |
1055 | 7 | test_liblibertine | 7 | test_liblibertine |
1056 | @@ -21,4 +21,4 @@ | |||
1057 | 21 | 21 | ||
1058 | 22 | set_tests_properties(test_liblibertine | 22 | set_tests_properties(test_liblibertine |
1059 | 23 | PROPERTIES ENVIRONMENT | 23 | PROPERTIES ENVIRONMENT |
1061 | 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") |
1062 | 25 | 25 | ||
1063 | === modified file 'tests/integration/test_libertine_service.py' | |||
1064 | --- tests/integration/test_libertine_service.py 2017-04-04 17:36:41 +0000 | |||
1065 | +++ tests/integration/test_libertine_service.py 2017-04-07 16:34:30 +0000 | |||
1066 | @@ -76,6 +76,7 @@ | |||
1067 | 76 | self.path = None | 76 | self.path = None |
1068 | 77 | 77 | ||
1069 | 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) |
1070 | 79 | self.path = None | ||
1071 | 79 | 80 | ||
1072 | 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, |
1073 | 81 | dbus_interface=constants.OPERATIONS_MONITOR_INTERFACE, signal_name='finished')) | 82 | dbus_interface=constants.OPERATIONS_MONITOR_INTERFACE, signal_name='finished')) |
1074 | 82 | 83 | ||
1075 | === modified file 'tests/unit/service/CMakeLists.txt' | |||
1076 | --- tests/unit/service/CMakeLists.txt 2017-03-07 20:48:11 +0000 | |||
1077 | +++ tests/unit/service/CMakeLists.txt 2017-04-07 16:34:30 +0000 | |||
1078 | @@ -2,7 +2,7 @@ | |||
1079 | 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) |
1080 | 3 | set_tests_properties(${test_name} | 3 | set_tests_properties(${test_name} |
1081 | 4 | PROPERTIES ENVIRONMENT | 4 | PROPERTIES ENVIRONMENT |
1083 | 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}") |
1084 | 6 | endfunction(create_service_unit_test) | 6 | endfunction(create_service_unit_test) |
1085 | 7 | 7 | ||
1086 | 8 | create_service_unit_test(test_container) | 8 | create_service_unit_test(test_container) |
1087 | 9 | 9 | ||
1088 | === modified file 'tests/unit/service/tasks/test_app_info_task.py' | |||
1089 | --- tests/unit/service/tasks/test_app_info_task.py 2017-03-07 19:41:49 +0000 | |||
1090 | +++ tests/unit/service/tasks/test_app_info_task.py 2017-04-07 16:34:30 +0000 | |||
1091 | @@ -33,7 +33,6 @@ | |||
1092 | 33 | 33 | ||
1093 | 34 | self.cache.app_info.return_value = {} | 34 | self.cache.app_info.return_value = {} |
1094 | 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) |
1095 | 36 | task._instant_callback = True | ||
1096 | 37 | task.start().join() | 36 | task.start().join() |
1097 | 38 | 37 | ||
1098 | 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\'') |
1099 | @@ -50,7 +49,6 @@ | |||
1100 | 50 | self.cache.app_info.return_value = {'package': 'darkside-common'} | 49 | self.cache.app_info.return_value = {'package': 'darkside-common'} |
1101 | 51 | self.config.get_package_install_status.return_value = 'installed' | 50 | self.config.get_package_install_status.return_value = 'installed' |
1102 | 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) |
1103 | 53 | task._instant_callback = True | ||
1104 | 54 | task.start().join() | 52 | task.start().join() |
1105 | 55 | 53 | ||
1106 | 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]})) |
1107 | 57 | 55 | ||
1108 | === modified file 'tests/unit/service/tasks/test_container_info_task.py' | |||
1109 | --- tests/unit/service/tasks/test_container_info_task.py 2017-03-07 19:41:49 +0000 | |||
1110 | +++ tests/unit/service/tasks/test_container_info_task.py 2017-04-07 16:34:30 +0000 | |||
1111 | @@ -37,7 +37,6 @@ | |||
1112 | 37 | self.config.get_container_install_status.return_value = 'ready' | 37 | self.config.get_container_install_status.return_value = 'ready' |
1113 | 38 | self.config.get_container_name.return_value = 'Palpatine' | 38 | self.config.get_container_name.return_value = 'Palpatine' |
1114 | 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) |
1115 | 40 | task._instant_callback = True | ||
1116 | 41 | task.start().join() | 40 | task.start().join() |
1117 | 42 | 41 | ||
1118 | 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) |
1119 | 44 | 43 | ||
1120 | === modified file 'tests/unit/service/tasks/test_create_task.py' | |||
1121 | --- tests/unit/service/tasks/test_create_task.py 2017-03-09 16:02:22 +0000 | |||
1122 | +++ tests/unit/service/tasks/test_create_task.py 2017-04-07 16:34:30 +0000 | |||
1123 | @@ -37,7 +37,6 @@ | |||
1124 | 37 | self.monitor.done.return_value = False | 37 | self.monitor.done.return_value = False |
1125 | 38 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, | 38 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, |
1126 | 39 | self.config, self.lock, self.monitor, self.client, self.callback) | 39 | self.config, self.lock, self.monitor, self.client, self.callback) |
1127 | 40 | task._instant_callback = True | ||
1128 | 41 | 40 | ||
1129 | 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: |
1130 | 43 | MockHostInfo.return_value.is_distro_valid.return_value = True | 42 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1131 | @@ -60,7 +59,6 @@ | |||
1132 | 60 | self.monitor.done.return_value = False | 59 | self.monitor.done.return_value = False |
1133 | 61 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', False, | 60 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', False, |
1134 | 62 | self.config, self.lock, self.monitor, self.client, self.callback) | 61 | self.config, self.lock, self.monitor, self.client, self.callback) |
1135 | 63 | task._instant_callback = True | ||
1136 | 64 | 62 | ||
1137 | 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: |
1138 | 66 | MockHostInfo.return_value.is_distro_valid.return_value = True | 64 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1139 | @@ -81,7 +79,6 @@ | |||
1140 | 81 | self.config.container_exists.return_value = False | 79 | self.config.container_exists.return_value = False |
1141 | 82 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, | 80 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, |
1142 | 83 | self.config, self.lock, self.monitor, self.client, self.callback) | 81 | self.config, self.lock, self.monitor, self.client, self.callback) |
1143 | 84 | task._instant_callback = True | ||
1144 | 85 | 82 | ||
1145 | 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: |
1146 | 87 | MockHostInfo.return_value.is_distro_valid.return_value = True | 84 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1147 | @@ -103,7 +100,6 @@ | |||
1148 | 103 | self.config.container_exists.return_value = True | 100 | self.config.container_exists.return_value = True |
1149 | 104 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, | 101 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, |
1150 | 105 | self.config, self.lock, self.monitor, self.client, self.callback) | 102 | self.config, self.lock, self.monitor, self.client, self.callback) |
1151 | 106 | task._instant_callback = True | ||
1152 | 107 | task.start().join() | 103 | task.start().join() |
1153 | 108 | 104 | ||
1154 | 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') |
1155 | @@ -115,7 +111,6 @@ | |||
1156 | 115 | MockHostInfo.return_value.is_distro_valid.return_value = False | 111 | MockHostInfo.return_value.is_distro_valid.return_value = False |
1157 | 116 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'vesty', 'lxc', False, | 112 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'vesty', 'lxc', False, |
1158 | 117 | self.config, self.lock, self.monitor, self.client, self.callback) | 113 | self.config, self.lock, self.monitor, self.client, self.callback) |
1159 | 118 | task._instant_callback = True | ||
1160 | 119 | task.start().join() | 114 | task.start().join() |
1161 | 120 | 115 | ||
1162 | 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\'.') |
1163 | @@ -128,7 +123,6 @@ | |||
1164 | 128 | MockHostInfo.return_value.has_lxc_support.return_value = False | 123 | MockHostInfo.return_value.has_lxc_support.return_value = False |
1165 | 129 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, | 124 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'lxc', False, |
1166 | 130 | self.config, self.lock, self.monitor, self.client, self.callback) | 125 | self.config, self.lock, self.monitor, self.client, self.callback) |
1167 | 131 | task._instant_callback = True | ||
1168 | 132 | task.start().join() | 126 | task.start().join() |
1169 | 133 | 127 | ||
1170 | 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, \ |
1171 | @@ -140,7 +134,6 @@ | |||
1172 | 140 | self.monitor.done.return_value = False | 134 | self.monitor.done.return_value = False |
1173 | 141 | task = tasks.CreateTask('palpatine', None, 'zesty', 'chroot', False, self.config, | 135 | task = tasks.CreateTask('palpatine', None, 'zesty', 'chroot', False, self.config, |
1174 | 142 | self.lock, self.monitor, self.client, self.callback) | 136 | self.lock, self.monitor, self.client, self.callback) |
1175 | 143 | task._instant_callback = True | ||
1176 | 144 | 137 | ||
1177 | 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: |
1178 | 146 | MockHostInfo.return_value.is_distro_valid.return_value = True | 139 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1179 | @@ -163,7 +156,6 @@ | |||
1180 | 163 | self.monitor.done.return_value = False | 156 | self.monitor.done.return_value = False |
1181 | 164 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', True, | 157 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', 'chroot', True, |
1182 | 165 | self.config, self.lock, self.monitor, self.client, self.callback) | 158 | self.config, self.lock, self.monitor, self.client, self.callback) |
1183 | 166 | task._instant_callback = True | ||
1184 | 167 | 159 | ||
1185 | 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: |
1186 | 169 | MockHostInfo.return_value.is_distro_valid.return_value = True | 161 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1187 | @@ -186,7 +178,6 @@ | |||
1188 | 186 | self.monitor.done.return_value = False | 178 | self.monitor.done.return_value = False |
1189 | 187 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', None, False, | 179 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', 'zesty', None, False, |
1190 | 188 | self.config, self.lock, self.monitor, self.client, self.callback) | 180 | self.config, self.lock, self.monitor, self.client, self.callback) |
1191 | 189 | task._instant_callback = True | ||
1192 | 190 | 181 | ||
1193 | 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: |
1194 | 192 | MockHostInfo.return_value.is_distro_valid.return_value = True | 183 | MockHostInfo.return_value.is_distro_valid.return_value = True |
1195 | @@ -209,7 +200,6 @@ | |||
1196 | 209 | self.monitor.done.return_value = False | 200 | self.monitor.done.return_value = False |
1197 | 210 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', None, 'lxc', False, | 201 | task = tasks.CreateTask('palpatine', 'Emperor Palpatine', None, 'lxc', False, |
1198 | 211 | self.config, self.lock, self.monitor, self.client, self.callback) | 202 | self.config, self.lock, self.monitor, self.client, self.callback) |
1199 | 212 | task._instant_callback = True | ||
1200 | 213 | 203 | ||
1201 | 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: |
1202 | 215 | MockHostInfo.return_value.has_lxc_support.return_value = True | 205 | MockHostInfo.return_value.has_lxc_support.return_value = True |
1203 | 216 | 206 | ||
1204 | === modified file 'tests/unit/service/tasks/test_destroy_task.py' | |||
1205 | --- tests/unit/service/tasks/test_destroy_task.py 2017-03-09 16:02:22 +0000 | |||
1206 | +++ tests/unit/service/tasks/test_destroy_task.py 2017-04-07 16:34:30 +0000 | |||
1207 | @@ -36,7 +36,6 @@ | |||
1208 | 36 | self.config._get_value_by_key.return_value = '' | 36 | self.config._get_value_by_key.return_value = '' |
1209 | 37 | self.monitor.done.return_value = False | 37 | self.monitor.done.return_value = False |
1210 | 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) |
1211 | 39 | task._instant_callback = True | ||
1212 | 40 | 39 | ||
1213 | 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: |
1214 | 42 | MockContainer.return_value.destroy_libertine_container.return_value = True | 41 | MockContainer.return_value.destroy_libertine_container.return_value = True |
1215 | @@ -48,7 +47,6 @@ | |||
1216 | 48 | def test_sends_error_on_failed_destroy(self): | 47 | def test_sends_error_on_failed_destroy(self): |
1217 | 49 | self.config._get_value_by_key.return_value = 'ready' | 48 | self.config._get_value_by_key.return_value = 'ready' |
1218 | 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) |
1219 | 51 | task._instant_callback = True | ||
1220 | 52 | 50 | ||
1221 | 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: |
1222 | 54 | MockContainer.return_value.destroy_libertine_container.return_value = False | 52 | MockContainer.return_value.destroy_libertine_container.return_value = False |
1223 | @@ -66,7 +64,6 @@ | |||
1224 | 66 | self.config._get_value_by_key.return_value = 'ready' | 64 | self.config._get_value_by_key.return_value = 'ready' |
1225 | 67 | self.monitor.done.return_value = False | 65 | self.monitor.done.return_value = False |
1226 | 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) |
1227 | 69 | task._instant_callback = True | ||
1228 | 70 | 67 | ||
1229 | 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: |
1230 | 72 | MockContainer.return_value.destroy_libertine_container.return_value = True | 69 | MockContainer.return_value.destroy_libertine_container.return_value = True |
1231 | 73 | 70 | ||
1232 | === modified file 'tests/unit/service/tasks/test_install_task.py' | |||
1233 | --- tests/unit/service/tasks/test_install_task.py 2017-03-09 16:02:22 +0000 | |||
1234 | +++ tests/unit/service/tasks/test_install_task.py 2017-04-07 16:34:30 +0000 | |||
1235 | @@ -35,7 +35,6 @@ | |||
1236 | 35 | def test_sends_error_on_existing_package(self): | 35 | def test_sends_error_on_existing_package(self): |
1237 | 36 | self.config.package_exists.return_value = True | 36 | self.config.package_exists.return_value = True |
1238 | 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) |
1239 | 38 | task._instant_callback = True | ||
1240 | 39 | task.start().join() | 38 | task.start().join() |
1241 | 40 | 39 | ||
1242 | 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') |
1243 | @@ -44,7 +43,6 @@ | |||
1244 | 44 | def test_sends_error_on_failed_install(self): | 43 | def test_sends_error_on_failed_install(self): |
1245 | 45 | self.config.package_exists.return_value = False | 44 | self.config.package_exists.return_value = False |
1246 | 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) |
1247 | 47 | task._instant_callback = True | ||
1248 | 48 | 46 | ||
1249 | 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: |
1250 | 50 | MockContainer.return_value.install_package.return_value = False | 48 | MockContainer.return_value.install_package.return_value = False |
1251 | @@ -59,7 +57,6 @@ | |||
1252 | 59 | self.config.package_exists.return_value = False | 57 | self.config.package_exists.return_value = False |
1253 | 60 | self.monitor.done.return_value = False | 58 | self.monitor.done.return_value = False |
1254 | 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) |
1255 | 62 | task._instant_callback = True | ||
1256 | 63 | 60 | ||
1257 | 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: |
1258 | 65 | MockContainer.return_value.install_package.return_value = True | 62 | MockContainer.return_value.install_package.return_value = True |
1259 | 66 | 63 | ||
1260 | === modified file 'tests/unit/service/tasks/test_list_app_ids_task.py' | |||
1261 | --- tests/unit/service/tasks/test_list_app_ids_task.py 2017-03-07 19:41:49 +0000 | |||
1262 | +++ tests/unit/service/tasks/test_list_app_ids_task.py 2017-04-07 16:34:30 +0000 | |||
1263 | @@ -34,7 +34,6 @@ | |||
1264 | 34 | def test_sends_error_on_non_existent_container(self): | 34 | def test_sends_error_on_non_existent_container(self): |
1265 | 35 | self.config.container_exists.return_value = False | 35 | self.config.container_exists.return_value = False |
1266 | 36 | task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback) | 36 | task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback) |
1267 | 37 | task._instant_callback = True | ||
1268 | 38 | 37 | ||
1269 | 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: |
1270 | 40 | task.start().join() | 39 | task.start().join() |
1271 | @@ -46,7 +45,6 @@ | |||
1272 | 46 | self.config.container_exists.return_value = True | 45 | self.config.container_exists.return_value = True |
1273 | 47 | self.monitor.done.return_value = False | 46 | self.monitor.done.return_value = False |
1274 | 48 | task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback) | 47 | task = tasks.ListAppIdsTask('palpatine', self.config, self.monitor, self.callback) |
1275 | 49 | task._instant_callback = True | ||
1276 | 50 | 48 | ||
1277 | 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: |
1278 | 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"]' |
1279 | 53 | 51 | ||
1280 | === modified file 'tests/unit/service/tasks/test_list_task.py' | |||
1281 | --- tests/unit/service/tasks/test_list_task.py 2017-03-07 19:41:49 +0000 | |||
1282 | +++ tests/unit/service/tasks/test_list_task.py 2017-04-07 16:34:30 +0000 | |||
1283 | @@ -35,7 +35,6 @@ | |||
1284 | 35 | self.monitor.done.return_value = False | 35 | self.monitor.done.return_value = False |
1285 | 36 | 36 | ||
1286 | 37 | task = tasks.ListTask(self.config, self.monitor, callback) | 37 | task = tasks.ListTask(self.config, self.monitor, callback) |
1287 | 38 | task._instant_callback = True | ||
1288 | 39 | 38 | ||
1289 | 40 | self.config.get_containers.return_value = ['palatine', 'vader', 'maul'] | 39 | self.config.get_containers.return_value = ['palatine', 'vader', 'maul'] |
1290 | 41 | task.start().join() | 40 | task.start().join() |
1291 | 42 | 41 | ||
1292 | === modified file 'tests/unit/service/tasks/test_remove_task.py' | |||
1293 | --- tests/unit/service/tasks/test_remove_task.py 2017-03-09 16:02:22 +0000 | |||
1294 | +++ tests/unit/service/tasks/test_remove_task.py 2017-04-07 16:34:30 +0000 | |||
1295 | @@ -35,7 +35,6 @@ | |||
1296 | 35 | def test_sends_error_on_non_installed_package(self): | 35 | def test_sends_error_on_non_installed_package(self): |
1297 | 36 | self.config.get_package_install_status.return_value = 'installing' | 36 | self.config.get_package_install_status.return_value = 'installing' |
1298 | 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) |
1299 | 38 | task._instant_callback = True | ||
1300 | 39 | task.start().join() | 38 | task.start().join() |
1301 | 40 | 39 | ||
1302 | 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') |
1303 | @@ -44,7 +43,6 @@ | |||
1304 | 44 | def test_sends_error_on_failed_install(self): | 43 | def test_sends_error_on_failed_install(self): |
1305 | 45 | self.config.get_package_install_status.return_value = 'installed' | 44 | self.config.get_package_install_status.return_value = 'installed' |
1306 | 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) |
1307 | 47 | task._instant_callback = True | ||
1308 | 48 | 46 | ||
1309 | 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: |
1310 | 50 | MockContainer.return_value.remove_package.return_value = False | 48 | MockContainer.return_value.remove_package.return_value = False |
1311 | @@ -61,7 +59,6 @@ | |||
1312 | 61 | self.config.get_package_install_status.return_value = 'installed' | 59 | self.config.get_package_install_status.return_value = 'installed' |
1313 | 62 | self.monitor.done.return_value = False | 60 | self.monitor.done.return_value = False |
1314 | 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) |
1315 | 64 | task._instant_callback = True | ||
1316 | 65 | 62 | ||
1317 | 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: |
1318 | 67 | MockContainer.return_value.remove_package.return_value = True | 64 | MockContainer.return_value.remove_package.return_value = True |
1319 | 68 | 65 | ||
1320 | === modified file 'tests/unit/service/tasks/test_search_task.py' | |||
1321 | --- tests/unit/service/tasks/test_search_task.py 2017-03-07 19:41:49 +0000 | |||
1322 | +++ tests/unit/service/tasks/test_search_task.py 2017-04-07 16:34:30 +0000 | |||
1323 | @@ -33,7 +33,6 @@ | |||
1324 | 33 | def test_successfully_lists_apps(self): | 33 | def test_successfully_lists_apps(self): |
1325 | 34 | self.monitor.done.return_value = False | 34 | self.monitor.done.return_value = False |
1326 | 35 | task = tasks.SearchTask('palpatine', self.cache, 'jarjar', self.monitor, self.callback) | 35 | task = tasks.SearchTask('palpatine', self.cache, 'jarjar', self.monitor, self.callback) |
1327 | 36 | task._instant_callback = True | ||
1328 | 37 | 36 | ||
1329 | 38 | self.cache.search.return_value = ['jarjar', 'sidius'] | 37 | self.cache.search.return_value = ['jarjar', 'sidius'] |
1330 | 39 | task.start().join() | 38 | task.start().join() |
1331 | 40 | 39 | ||
1332 | === modified file 'tests/unit/service/tasks/test_update_task.py' | |||
1333 | --- tests/unit/service/tasks/test_update_task.py 2017-03-09 16:02:22 +0000 | |||
1334 | +++ tests/unit/service/tasks/test_update_task.py 2017-04-07 16:34:30 +0000 | |||
1335 | @@ -35,7 +35,6 @@ | |||
1336 | 35 | def test_sends_error_on_non_existent_container(self): | 35 | def test_sends_error_on_non_existent_container(self): |
1337 | 36 | self.config.container_exists.return_value = False | 36 | self.config.container_exists.return_value = False |
1338 | 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) |
1339 | 38 | task._instant_callback = True | ||
1340 | 39 | 38 | ||
1341 | 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: |
1342 | 41 | task.start().join() | 40 | task.start().join() |
1343 | @@ -47,7 +46,6 @@ | |||
1344 | 47 | def test_sends_error_on_failed_update(self): | 46 | def test_sends_error_on_failed_update(self): |
1345 | 48 | self.config.container_exists.return_value = True | 47 | self.config.container_exists.return_value = True |
1346 | 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) |
1347 | 50 | task._instant_callback = True | ||
1348 | 51 | 49 | ||
1349 | 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: |
1350 | 53 | MockContainer.return_value.update_libertine_container.return_value = False | 51 | MockContainer.return_value.update_libertine_container.return_value = False |
1351 | @@ -65,7 +63,6 @@ | |||
1352 | 65 | self.config.container_exists.return_value = True | 63 | self.config.container_exists.return_value = True |
1353 | 66 | self.monitor.done.return_value = False | 64 | self.monitor.done.return_value = False |
1354 | 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) |
1355 | 68 | task._instant_callback = True | ||
1356 | 69 | 66 | ||
1357 | 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: |
1358 | 71 | MockContainer.return_value.update_libertine_container.return_value = True | 68 | MockContainer.return_value.update_libertine_container.return_value = True |
1359 | 72 | 69 | ||
1360 | === modified file 'tests/unit/service/test_container.py' | |||
1361 | --- tests/unit/service/test_container.py 2017-03-16 19:59:08 +0000 | |||
1362 | +++ tests/unit/service/test_container.py 2017-04-07 16:34:30 +0000 | |||
1363 | @@ -30,7 +30,7 @@ | |||
1364 | 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) |
1365 | 31 | with unittest.mock.patch('libertine.service.container.SearchTask') as MockSearchTask: | 31 | with unittest.mock.patch('libertine.service.container.SearchTask') as MockSearchTask: |
1366 | 32 | c.search('darkseid') | 32 | c.search('darkseid') |
1368 | 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) |
1369 | 34 | MockSearchTask.return_value.start.assert_called_once_with() | 34 | MockSearchTask.return_value.start.assert_called_once_with() |
1370 | 35 | 35 | ||
1371 | 36 | def test_app_info_creates_app_info_task(self): | 36 | def test_app_info_creates_app_info_task(self): |
1372 | @@ -49,7 +49,7 @@ | |||
1373 | 49 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: | 49 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: |
1374 | 50 | MockInstallTask.return_value.package = 'darkside' | 50 | MockInstallTask.return_value.package = 'darkside' |
1375 | 51 | MockInstallTask.return_value.matches.return_value = False | 51 | MockInstallTask.return_value.matches.return_value = False |
1377 | 52 | install_task_id = c.install('darkside') | 52 | install_task_id = c.install('darkside', False) |
1378 | 53 | with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask: | 53 | with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask: |
1379 | 54 | MockRemoveTask.return_value.package = 'darkside' | 54 | MockRemoveTask.return_value.package = 'darkside' |
1380 | 55 | remove_task_id = c.remove('darkside') | 55 | remove_task_id = c.remove('darkside') |
1381 | @@ -62,18 +62,18 @@ | |||
1382 | 62 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: | 62 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: |
1383 | 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) |
1384 | 64 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: | 64 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: |
1387 | 65 | c.install('force') | 65 | c.install('force', False) |
1388 | 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) |
1389 | 67 | MockInstallTask.return_value.start.assert_called_once_with() | 67 | MockInstallTask.return_value.start.assert_called_once_with() |
1390 | 68 | 68 | ||
1391 | 69 | def test_install_only_calls_once_when_unfinished(self): | 69 | def test_install_only_calls_once_when_unfinished(self): |
1392 | 70 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: | 70 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: |
1393 | 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) |
1394 | 72 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: | 72 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: |
1399 | 73 | c.install('darkside') | 73 | c.install('darkside', False) |
1400 | 74 | c.install('darkside') | 74 | c.install('darkside', False) |
1401 | 75 | c.install('darkside') | 75 | c.install('darkside', False) |
1402 | 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) |
1403 | 77 | MockInstallTask.return_value.start.assert_called_once_with() | 77 | MockInstallTask.return_value.start.assert_called_once_with() |
1404 | 78 | 78 | ||
1405 | 79 | def test_remove_creates_remove_task(self): | 79 | def test_remove_creates_remove_task(self): |
1406 | @@ -81,7 +81,7 @@ | |||
1407 | 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) |
1408 | 82 | with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask: | 82 | with unittest.mock.patch('libertine.service.container.RemoveTask') as MockRemoveTask: |
1409 | 83 | c.remove('force') | 83 | c.remove('force') |
1411 | 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) |
1412 | 85 | MockRemoveTask.return_value.start.assert_called_once_with() | 85 | MockRemoveTask.return_value.start.assert_called_once_with() |
1413 | 86 | 86 | ||
1414 | 87 | def test_remove_only_calls_once_when_unfinished(self): | 87 | def test_remove_only_calls_once_when_unfinished(self): |
1415 | @@ -91,7 +91,7 @@ | |||
1416 | 91 | c.remove('darkside') | 91 | c.remove('darkside') |
1417 | 92 | c.remove('darkside') | 92 | c.remove('darkside') |
1418 | 93 | c.remove('darkside') | 93 | c.remove('darkside') |
1420 | 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) |
1421 | 95 | MockRemoveTask.return_value.start.assert_called_once_with() | 95 | MockRemoveTask.return_value.start.assert_called_once_with() |
1422 | 96 | 96 | ||
1423 | 97 | def test_create_creates_create_task(self): | 97 | def test_create_creates_create_task(self): |
1424 | @@ -100,7 +100,7 @@ | |||
1425 | 100 | with unittest.mock.patch('libertine.service.container.CreateTask') as MockCreateTask: | 100 | with unittest.mock.patch('libertine.service.container.CreateTask') as MockCreateTask: |
1426 | 101 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) | 101 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) |
1427 | 102 | MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False, | 102 | MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False, |
1429 | 103 | self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY) | 103 | self._config, unittest.mock.ANY, self._monitor, self._client) |
1430 | 104 | MockCreateTask.return_value.start.assert_called_once_with() | 104 | MockCreateTask.return_value.start.assert_called_once_with() |
1431 | 105 | 105 | ||
1432 | 106 | def test_create_only_calls_once_when_unfinished(self): | 106 | def test_create_only_calls_once_when_unfinished(self): |
1433 | @@ -111,25 +111,25 @@ | |||
1434 | 111 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) | 111 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) |
1435 | 112 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) | 112 | c.create('Emperor Palpatine', 'zesty', 'lxd', False) |
1436 | 113 | MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False, | 113 | MockCreateTask.assert_called_once_with('palpatine', 'Emperor Palpatine', 'zesty', 'lxd', False, |
1438 | 114 | self._config, unittest.mock.ANY, self._monitor, self._client, unittest.mock.ANY) | 114 | self._config, unittest.mock.ANY, self._monitor, self._client) |
1439 | 115 | MockCreateTask.return_value.start.assert_called_once_with() | 115 | MockCreateTask.return_value.start.assert_called_once_with() |
1440 | 116 | 116 | ||
1441 | 117 | def test_destroy_creates_destroy_task(self): | 117 | def test_destroy_creates_destroy_task(self): |
1442 | 118 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: | 118 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: |
1443 | 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) |
1444 | 120 | with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask: | 120 | with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask: |
1447 | 121 | c.destroy() | 121 | c.destroy(False) |
1448 | 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) |
1449 | 123 | MockDestroyTask.return_value.start.assert_called_once_with() | 123 | MockDestroyTask.return_value.start.assert_called_once_with() |
1450 | 124 | 124 | ||
1451 | 125 | def test_destroy_only_calls_once_when_unfinished(self): | 125 | def test_destroy_only_calls_once_when_unfinished(self): |
1452 | 126 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: | 126 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: |
1453 | 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) |
1454 | 128 | with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask: | 128 | with unittest.mock.patch('libertine.service.container.DestroyTask') as MockDestroyTask: |
1459 | 129 | c.destroy() | 129 | c.destroy(False) |
1460 | 130 | c.destroy() | 130 | c.destroy(False) |
1461 | 131 | c.destroy() | 131 | c.destroy(False) |
1462 | 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) |
1463 | 133 | MockDestroyTask.return_value.start.assert_called_once_with() | 133 | MockDestroyTask.return_value.start.assert_called_once_with() |
1464 | 134 | 134 | ||
1465 | 135 | def test_update_creates_update_task(self): | 135 | def test_update_creates_update_task(self): |
1466 | @@ -137,7 +137,7 @@ | |||
1467 | 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) |
1468 | 138 | with unittest.mock.patch('libertine.service.container.UpdateTask') as MockUpdateTask: | 138 | with unittest.mock.patch('libertine.service.container.UpdateTask') as MockUpdateTask: |
1469 | 139 | c.update() | 139 | c.update() |
1471 | 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) |
1472 | 141 | MockUpdateTask.return_value.start.assert_called_once_with() | 141 | MockUpdateTask.return_value.start.assert_called_once_with() |
1473 | 142 | 142 | ||
1474 | 143 | def test_update_only_calls_once_when_unfinished(self): | 143 | def test_update_only_calls_once_when_unfinished(self): |
1475 | @@ -147,7 +147,7 @@ | |||
1476 | 147 | c.update() | 147 | c.update() |
1477 | 148 | c.update() | 148 | c.update() |
1478 | 149 | c.update() | 149 | c.update() |
1480 | 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) |
1481 | 151 | MockUpdateTask.return_value.start.assert_called_once_with() | 151 | MockUpdateTask.return_value.start.assert_called_once_with() |
1482 | 152 | 152 | ||
1483 | 153 | def test_list_app_ids_creates_list_app_ids_task(self): | 153 | def test_list_app_ids_creates_list_app_ids_task(self): |
1484 | @@ -155,21 +155,21 @@ | |||
1485 | 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) |
1486 | 156 | with unittest.mock.patch('libertine.service.container.ListAppIdsTask') as MockListAppIdsTask: | 156 | with unittest.mock.patch('libertine.service.container.ListAppIdsTask') as MockListAppIdsTask: |
1487 | 157 | c.list_app_ids() | 157 | c.list_app_ids() |
1489 | 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) |
1490 | 159 | MockListAppIdsTask.return_value.start.assert_called_once_with() | 159 | MockListAppIdsTask.return_value.start.assert_called_once_with() |
1491 | 160 | 160 | ||
1493 | 161 | def test_removes_task_during_callback(self): | 161 | def test_removes_task_during_cleanup(self): |
1494 | 162 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: | 162 | with unittest.mock.patch('libertine.service.container.apt.AptCache') as MockCache: |
1495 | 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) |
1496 | 164 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: | 164 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: |
1497 | 165 | MockInstallTask.return_value.package = 'force' | 165 | MockInstallTask.return_value.package = 'force' |
1499 | 166 | c.install('force') | 166 | c.install('force', False) |
1500 | 167 | self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure initial mocks were called | 167 | self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure initial mocks were called |
1502 | 168 | c.install('force') | 168 | c.install('force', False) |
1503 | 169 | self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure no more mocks were called | 169 | self.assertEqual(1, len(MockInstallTask.return_value.start.mock_calls)) # ensure no more mocks were called |
1507 | 170 | name, args, kwargs = MockInstallTask.mock_calls[0] | 170 | MockInstallTask.return_value.should_delete = True |
1508 | 171 | args[len(args)-1](MockInstallTask.return_value.start.return_value) | 171 | c._cleanup() |
1509 | 172 | c.install('force') | 172 | c.install('force', False) |
1510 | 173 | self.assertEqual(2, len(MockInstallTask.return_value.start.mock_calls)) # ensure mocks were called again | 173 | self.assertEqual(2, len(MockInstallTask.return_value.start.mock_calls)) # ensure mocks were called again |
1511 | 174 | 174 | ||
1512 | 175 | def test_completing_all_tasks_fires_callback(self): | 175 | def test_completing_all_tasks_fires_callback(self): |
1513 | @@ -179,9 +179,9 @@ | |||
1514 | 179 | self._container_id = container.id | 179 | self._container_id = container.id |
1515 | 180 | c = container.Container('palpatine', self._config, self._monitor, self._client, callback) | 180 | c = container.Container('palpatine', self._config, self._monitor, self._client, callback) |
1516 | 181 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: | 181 | with unittest.mock.patch('libertine.service.container.InstallTask') as MockInstallTask: |
1520 | 182 | c.install('force') | 182 | c.install('force', False) |
1521 | 183 | name, args, kwargs = MockInstallTask.mock_calls[0] | 183 | MockInstallTask.return_value.should_delete = True |
1522 | 184 | args[len(args)-1](MockInstallTask.return_value) | 184 | c._cleanup() |
1523 | 185 | self.assertEqual('palpatine', self._container_id) | 185 | self.assertEqual('palpatine', self._container_id) |
1524 | 186 | 186 | ||
1525 | 187 | 187 | ||
1526 | 188 | 188 | ||
1527 | === modified file 'tests/unit/service/test_task_dispatcher.py' | |||
1528 | --- tests/unit/service/test_task_dispatcher.py 2017-03-09 16:02:22 +0000 | |||
1529 | +++ tests/unit/service/test_task_dispatcher.py 2017-04-07 16:34:30 +0000 | |||
1530 | @@ -46,8 +46,8 @@ | |||
1531 | 46 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: | 46 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: |
1532 | 47 | c = MockContainer.return_value | 47 | c = MockContainer.return_value |
1533 | 48 | c.install.return_value = 123 | 48 | c.install.return_value = 123 |
1536 | 49 | self.assertEqual(123, self._dispatcher.install('palpatine', 'darkside')) | 49 | self.assertEqual(123, self._dispatcher.install('palpatine', 'darkside', False)) |
1537 | 50 | c.install.assert_called_once_with('darkside') | 50 | c.install.assert_called_once_with('darkside', False) |
1538 | 51 | 51 | ||
1539 | 52 | def test_remove_calls_remove_on_container(self): | 52 | def test_remove_calls_remove_on_container(self): |
1540 | 53 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: | 53 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: |
1541 | @@ -67,8 +67,8 @@ | |||
1542 | 67 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: | 67 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: |
1543 | 68 | c = MockContainer.return_value | 68 | c = MockContainer.return_value |
1544 | 69 | c.destroy.return_value = 123 | 69 | c.destroy.return_value = 123 |
1547 | 70 | self.assertEqual(123, self._dispatcher.destroy('palpatine')) | 70 | self.assertEqual(123, self._dispatcher.destroy('palpatine', False)) |
1548 | 71 | c.destroy.assert_called_once_with() | 71 | c.destroy.assert_called_once_with(False) |
1549 | 72 | 72 | ||
1550 | 73 | def test_update_calls_update_on_container(self): | 73 | def test_update_calls_update_on_container(self): |
1551 | 74 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: | 74 | with unittest.mock.patch('libertine.service.task_dispatcher.Container') as MockContainer: |
1552 | @@ -112,7 +112,7 @@ | |||
1553 | 112 | task = MockContainerInfoTask.return_value | 112 | task = MockContainerInfoTask.return_value |
1554 | 113 | task.id = 123 | 113 | task.id = 123 |
1555 | 114 | self.assertEqual(123, self._dispatcher.container_info('palpatine')) | 114 | self.assertEqual(123, self._dispatcher.container_info('palpatine')) |
1557 | 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) |
1558 | 116 | task.start.assert_called_once_with() | 116 | task.start.assert_called_once_with() |
1559 | 117 | 117 | ||
1560 | 118 | def test_container_info_forwards_container_task_ids(self): | 118 | def test_container_info_forwards_container_task_ids(self): |
1561 | @@ -124,7 +124,7 @@ | |||
1562 | 124 | c.id = 'palpatine' | 124 | c.id = 'palpatine' |
1563 | 125 | self._dispatcher.list_app_ids('palpatine') # creates container | 125 | self._dispatcher.list_app_ids('palpatine') # creates container |
1564 | 126 | self._dispatcher.container_info('palpatine') | 126 | self._dispatcher.container_info('palpatine') |
1566 | 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) |
1567 | 128 | task.start.assert_called_once_with() | 128 | task.start.assert_called_once_with() |
1568 | 129 | 129 | ||
1569 | 130 | def test_list_creates_list_task(self): | 130 | def test_list_creates_list_task(self): |
1570 | @@ -132,16 +132,17 @@ | |||
1571 | 132 | task = MockListTask.return_value | 132 | task = MockListTask.return_value |
1572 | 133 | task.id = 123 | 133 | task.id = 123 |
1573 | 134 | self.assertEqual(123, self._dispatcher.list()) | 134 | self.assertEqual(123, self._dispatcher.list()) |
1575 | 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) |
1576 | 136 | task.start.assert_called_once_with() | 136 | task.start.assert_called_once_with() |
1577 | 137 | 137 | ||
1578 | 138 | def test_containerless_tasks_are_cleaned_up(self): | 138 | def test_containerless_tasks_are_cleaned_up(self): |
1579 | 139 | with unittest.mock.patch('libertine.service.task_dispatcher.ListTask') as MockListTask: | 139 | with unittest.mock.patch('libertine.service.task_dispatcher.ListTask') as MockListTask: |
1580 | 140 | self._dispatcher.list() | 140 | self._dispatcher.list() |
1582 | 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) |
1583 | 142 | name, args, kwargs = MockListTask.mock_calls[0] | 142 | name, args, kwargs = MockListTask.mock_calls[0] |
1584 | 143 | self.assertEqual(1, len(self._dispatcher._tasks)) | 143 | self.assertEqual(1, len(self._dispatcher._tasks)) |
1586 | 144 | args[len(args)-1](MockListTask.return_value) | 144 | MockListTask.return_value.should_delete = True |
1587 | 145 | self._dispatcher._cleanup() | ||
1588 | 145 | self.assertEqual(0, len(self._dispatcher._tasks)) | 146 | self.assertEqual(0, len(self._dispatcher._tasks)) |
1589 | 146 | 147 | ||
1590 | 147 | 148 | ||
1591 | 148 | 149 | ||
1592 | === modified file 'tools/libertined' | |||
1593 | --- tools/libertined 2017-04-06 14:37:00 +0000 | |||
1594 | +++ tools/libertined 2017-04-07 16:34:30 +0000 | |||
1595 | @@ -20,7 +20,6 @@ | |||
1596 | 20 | import dbus | 20 | import dbus |
1597 | 21 | import os | 21 | import os |
1598 | 22 | import signal | 22 | import signal |
1599 | 23 | import sys | ||
1600 | 24 | 23 | ||
1601 | 25 | from dbus.mainloop.glib import DBusGMainLoop | 24 | from dbus.mainloop.glib import DBusGMainLoop |
1602 | 26 | from gi.repository import GLib | 25 | from gi.repository import GLib |
FAILED: Continuous integration, rev:463 /jenkins. canonical. com/libertine/ job/lp- libertine- ci/481/ /jenkins. canonical. com/libertine/ job/build/ 874/console /jenkins. canonical. com/libertine/ job/build- 0-fetch/ 884 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= xenial+ overlay/ 876/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= zesty/876/ console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= xenial+ overlay/ 876/console /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= zesty/876/ console
https:/
Executed test runs:
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/libertine/ job/lp- libertine- ci/481/ rebuild
https:/