Merge lp:~townsend/libertine/more-refactoring into lp:libertine
- more-refactoring
- Merge into devel
Status: | Merged |
---|---|
Approved by: | Larry Price |
Approved revision: | 262 |
Merged at revision: | 260 |
Proposed branch: | lp:~townsend/libertine/more-refactoring |
Merge into: | lp:libertine |
Diff against target: |
580 lines (+130/-203) 9 files modified
debian/python3-libertine.install (+2/-0) python/libertine/ChrootContainer.py (+26/-72) python/libertine/ContainersConfig.py (+10/-0) python/libertine/HostInfo.py (+71/-0) python/libertine/Libertine.py (+8/-38) python/libertine/LxcContainer.py (+3/-8) python/libertine/utils.py (+1/-29) tools/libertine-container-manager (+8/-53) tools/libertine-launch (+1/-3) |
To merge this branch: | bzr merge lp:~townsend/libertine/more-refactoring |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Larry Price | Approve | ||
Libertine CI Bot | continuous-integration | Approve | |
Review via email: mp+298465@code.launchpad.net |
Commit message
Refactor host information into a new HostInfo class.
Use ContainersConfig class for any places that access the ContainersConfi
Some other small cleanup.
Description of the change
Libertine CI Bot (libertine-ci-bot) wrote : | # |
Larry Price (larryprice) wrote : | # |
just the 1 inline
- 260. By Christopher Townsend
-
A bit more refactioring and fixes.
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:260
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: 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:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
- 261. By Christopher Townsend
-
Remove redundant container_id check as the LibertineContai
ner.launch_ application( ) mehtod already does that.
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:261
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: 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:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Larry Price (larryprice) wrote : | # |
i got a chroot creation failure when trying to do a simple create on yakkety. no errors in the output except for "Failed to create container".
- 262. By Christopher Townsend
-
Add missing word in comment.
Libertine CI Bot (libertine-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:262
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: 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:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild:
https:/
Larry Price (larryprice) wrote : | # |
issue with yakkety chroot occurs in archives
lgtm
Preview Diff
1 | === modified file 'debian/python3-libertine.install' | |||
2 | --- debian/python3-libertine.install 2015-12-15 15:46:58 +0000 | |||
3 | +++ debian/python3-libertine.install 2016-06-28 18:52:06 +0000 | |||
4 | @@ -1,4 +1,6 @@ | |||
5 | 1 | usr/lib/python*/*/libertine/AppDiscovery.py | 1 | usr/lib/python*/*/libertine/AppDiscovery.py |
6 | 2 | usr/lib/python*/*/libertine/Libertine.py | 2 | usr/lib/python*/*/libertine/Libertine.py |
7 | 3 | usr/lib/python*/*/libertine/ContainersConfig.py | ||
8 | 4 | usr/lib/python*/*/libertine/HostInfo.py | ||
9 | 3 | usr/lib/python*/*/libertine/utils.py | 5 | usr/lib/python*/*/libertine/utils.py |
10 | 4 | usr/lib/python*/*/libertine/__init__.py | 6 | usr/lib/python*/*/libertine/__init__.py |
11 | 5 | 7 | ||
12 | === modified file 'python/libertine/ChrootContainer.py' | |||
13 | --- python/libertine/ChrootContainer.py 2016-06-15 18:10:05 +0000 | |||
14 | +++ python/libertine/ChrootContainer.py 2016-06-28 18:52:06 +0000 | |||
15 | @@ -17,6 +17,7 @@ | |||
16 | 17 | import shlex | 17 | import shlex |
17 | 18 | import shutil | 18 | import shutil |
18 | 19 | import subprocess | 19 | import subprocess |
19 | 20 | |||
20 | 20 | from .Libertine import BaseContainer | 21 | from .Libertine import BaseContainer |
21 | 21 | from . import utils | 22 | from . import utils |
22 | 22 | 23 | ||
23 | @@ -53,10 +54,7 @@ | |||
24 | 53 | 54 | ||
25 | 54 | def run_in_container(self, command_string): | 55 | def run_in_container(self, command_string): |
26 | 55 | cmd_args = shlex.split(command_string) | 56 | cmd_args = shlex.split(command_string) |
31 | 56 | if self.get_container_distro(self.container_id) == "trusty": | 57 | command_prefix = "fakechroot fakeroot chroot " + self.root_path |
28 | 57 | command_prefix = self._build_privileged_proot_cmd() | ||
29 | 58 | else: | ||
30 | 59 | command_prefix = "fakechroot fakeroot chroot " + self.root_path | ||
32 | 60 | args = shlex.split(command_prefix + ' ' + command_string) | 58 | args = shlex.split(command_prefix + ' ' + command_string) |
33 | 61 | cmd = subprocess.Popen(args) | 59 | cmd = subprocess.Popen(args) |
34 | 62 | return cmd.wait() | 60 | return cmd.wait() |
35 | @@ -66,15 +64,9 @@ | |||
36 | 66 | shutil.rmtree(container_root) | 64 | shutil.rmtree(container_root) |
37 | 67 | 65 | ||
38 | 68 | def create_libertine_container(self, password=None, multiarch=False, verbosity=1): | 66 | def create_libertine_container(self, password=None, multiarch=False, verbosity=1): |
39 | 69 | installed_release = self.get_container_distro(self.container_id) | ||
40 | 70 | architecture = utils.get_host_architecture() | ||
41 | 71 | |||
42 | 72 | # Create the actual chroot | 67 | # Create the actual chroot |
48 | 73 | if installed_release == "trusty": | 68 | command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format( |
49 | 74 | command_line = "debootstrap --verbose " + installed_release + " " + self.root_path | 69 | self.installed_release, self.root_path) |
45 | 75 | else: | ||
46 | 76 | command_line = "fakechroot fakeroot debootstrap --verbose --variant=fakechroot {} {}".format( | ||
47 | 77 | installed_release, self.root_path) | ||
50 | 78 | args = shlex.split(command_line) | 70 | args = shlex.split(command_line) |
51 | 79 | cmd = subprocess.Popen(args) | 71 | cmd = subprocess.Popen(args) |
52 | 80 | cmd.wait() | 72 | cmd.wait() |
53 | @@ -84,25 +76,24 @@ | |||
54 | 84 | self.destroy_libertine_container() | 76 | self.destroy_libertine_container() |
55 | 85 | return False | 77 | return False |
56 | 86 | 78 | ||
62 | 87 | # Remove symlinks as they can ill-behaved recursive behavior in the chroot | 79 | # Remove symlinks as they can cause ill-behaved recursive behavior in the chroot |
63 | 88 | if installed_release != "trusty": | 80 | print("Fixing chroot symlinks...") |
64 | 89 | print("Fixing chroot symlinks...") | 81 | os.remove(os.path.join(self.root_path, 'dev')) |
65 | 90 | os.remove(os.path.join(self.root_path, 'dev')) | 82 | os.remove(os.path.join(self.root_path, 'proc')) |
61 | 91 | os.remove(os.path.join(self.root_path, 'proc')) | ||
66 | 92 | 83 | ||
77 | 93 | with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd: | 84 | with open(os.path.join(self.root_path, 'usr', 'sbin', 'policy-rc.d'), 'w+') as fd: |
78 | 94 | fd.write("#!/bin/sh\n\n") | 85 | fd.write("#!/bin/sh\n\n") |
79 | 95 | fd.write("while true; do\n") | 86 | fd.write("while true; do\n") |
80 | 96 | fd.write("case \"$1\" in\n") | 87 | fd.write("case \"$1\" in\n") |
81 | 97 | fd.write(" -*) shift ;;\n") | 88 | fd.write(" -*) shift ;;\n") |
82 | 98 | fd.write(" makedev) exit 0;;\n") | 89 | fd.write(" makedev) exit 0;;\n") |
83 | 99 | fd.write(" *) exit 101;;\n") | 90 | fd.write(" *) exit 101;;\n") |
84 | 100 | fd.write("esac\n") | 91 | fd.write("esac\n") |
85 | 101 | fd.write("done\n") | 92 | fd.write("done\n") |
86 | 102 | os.fchmod(fd.fileno(), 0o755) | 93 | os.fchmod(fd.fileno(), 0o755) |
87 | 103 | 94 | ||
88 | 104 | # Add universe, multiverse, and -updates to the chroot's sources.list | 95 | # Add universe, multiverse, and -updates to the chroot's sources.list |
90 | 105 | if (utils.get_host_architecture() == 'armhf'): | 96 | if (self.architecture == 'armhf'): |
91 | 106 | archive = "deb http://ports.ubuntu.com/ubuntu-ports " | 97 | archive = "deb http://ports.ubuntu.com/ubuntu-ports " |
92 | 107 | else: | 98 | else: |
93 | 108 | archive = "deb http://archive.ubuntu.com/ubuntu " | 99 | archive = "deb http://archive.ubuntu.com/ubuntu " |
94 | @@ -110,52 +101,15 @@ | |||
95 | 110 | if verbosity == 1: | 101 | if verbosity == 1: |
96 | 111 | print("Updating chroot's sources.list entries...") | 102 | print("Updating chroot's sources.list entries...") |
97 | 112 | with open(os.path.join(self.root_path, 'etc', 'apt', 'sources.list'), 'a') as fd: | 103 | with open(os.path.join(self.root_path, 'etc', 'apt', 'sources.list'), 'a') as fd: |
103 | 113 | fd.write(archive + installed_release + "-updates main\n") | 104 | fd.write(archive + self.installed_release + "-updates main\n") |
104 | 114 | fd.write(archive + installed_release + " universe\n") | 105 | fd.write(archive + self.installed_release + " universe\n") |
105 | 115 | fd.write(archive + installed_release + "-updates universe\n") | 106 | fd.write(archive + self.installed_release + "-updates universe\n") |
106 | 116 | fd.write(archive + installed_release + " multiverse\n") | 107 | fd.write(archive + self.installed_release + " multiverse\n") |
107 | 117 | fd.write(archive + installed_release + "-updates multiverse\n") | 108 | fd.write(archive + self.installed_release + "-updates multiverse\n") |
108 | 118 | 109 | ||
109 | 119 | utils.create_libertine_user_data_dir(self.container_id) | 110 | utils.create_libertine_user_data_dir(self.container_id) |
110 | 120 | 111 | ||
149 | 121 | if installed_release == "trusty": | 112 | if multiarch and self.architecture == 'amd64': |
112 | 122 | print("Additional configuration for Trusty chroot...") | ||
113 | 123 | |||
114 | 124 | cmd_line_prefix = self._build_privileged_proot_cmd() | ||
115 | 125 | |||
116 | 126 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /etc/init.d/systemd-logind" | ||
117 | 127 | args = shlex.split(command_line) | ||
118 | 128 | cmd = subprocess.Popen(args).wait() | ||
119 | 129 | |||
120 | 130 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/initctl" | ||
121 | 131 | args = shlex.split(command_line) | ||
122 | 132 | cmd = subprocess.Popen(args).wait() | ||
123 | 133 | |||
124 | 134 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /sbin/udevd" | ||
125 | 135 | args = shlex.split(command_line) | ||
126 | 136 | cmd = subprocess.Popen(args).wait() | ||
127 | 137 | |||
128 | 138 | command_line = cmd_line_prefix + " dpkg-divert --local --rename --add /usr/sbin/rsyslogd" | ||
129 | 139 | args = shlex.split(command_line) | ||
130 | 140 | cmd = subprocess.Popen(args).wait() | ||
131 | 141 | |||
132 | 142 | command_line = cmd_line_prefix + " ln -s /bin/true /etc/init.d/systemd-logind" | ||
133 | 143 | args = shlex.split(command_line) | ||
134 | 144 | cmd = subprocess.Popen(args).wait() | ||
135 | 145 | |||
136 | 146 | command_line = cmd_line_prefix + " ln -s /bin/true /sbin/initctl" | ||
137 | 147 | args = shlex.split(command_line) | ||
138 | 148 | cmd = subprocess.Popen(args).wait() | ||
139 | 149 | |||
140 | 150 | command_line = cmd_line_prefix + " ln -s /bin/true /sbin/udevd" | ||
141 | 151 | args = shlex.split(command_line) | ||
142 | 152 | cmd = subprocess.Popen(args).wait() | ||
143 | 153 | |||
144 | 154 | command_line = cmd_line_prefix + " ln -s /bin/true /usr/sbin/rsyslogd" | ||
145 | 155 | args = shlex.split(command_line) | ||
146 | 156 | cmd = subprocess.Popen(args).wait() | ||
147 | 157 | |||
148 | 158 | if multiarch and architecture == 'amd64': | ||
150 | 159 | if verbosity == 1: | 113 | if verbosity == 1: |
151 | 160 | print("Adding i386 multiarch support...") | 114 | print("Adding i386 multiarch support...") |
152 | 161 | self.run_in_container("dpkg --add-architecture i386") | 115 | self.run_in_container("dpkg --add-architecture i386") |
153 | @@ -170,7 +124,7 @@ | |||
154 | 170 | self.destroy_libertine_container() | 124 | self.destroy_libertine_container() |
155 | 171 | return False | 125 | return False |
156 | 172 | 126 | ||
158 | 173 | if installed_release == "vivid": | 127 | if self.installed_release == "vivid": |
159 | 174 | if verbosity == 1: | 128 | if verbosity == 1: |
160 | 175 | print("Installing the Vivid Stable Overlay PPA...") | 129 | print("Installing the Vivid Stable Overlay PPA...") |
161 | 176 | self.run_in_container("add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay -y") | 130 | self.run_in_container("add-apt-repository ppa:ci-train-ppa-service/stable-phone-overlay -y") |
162 | 177 | 131 | ||
163 | === modified file 'python/libertine/ContainersConfig.py' | |||
164 | --- python/libertine/ContainersConfig.py 2016-06-27 17:58:57 +0000 | |||
165 | +++ python/libertine/ContainersConfig.py 2016-06-28 18:52:06 +0000 | |||
166 | @@ -297,3 +297,13 @@ | |||
167 | 297 | def package_exists(self, container_id, package_name): | 297 | def package_exists(self, container_id, package_name): |
168 | 298 | return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName', | 298 | return self._test_array_object_key_value_exists(container_id, 'installedApps', 'packageName', |
169 | 299 | package_name) | 299 | package_name) |
170 | 300 | |||
171 | 301 | """ | ||
172 | 302 | Fetcher functions for various configuration information. | ||
173 | 303 | """ | ||
174 | 304 | def get_container_distro(self, container_id): | ||
175 | 305 | return self._get_value_by_key(container_id, 'distro') | ||
176 | 306 | |||
177 | 307 | def get_container_type(self, container_id): | ||
178 | 308 | return self._get_value_by_key(container_id, 'type') | ||
179 | 309 | |||
180 | 300 | 310 | ||
181 | === added file 'python/libertine/HostInfo.py' | |||
182 | --- python/libertine/HostInfo.py 1970-01-01 00:00:00 +0000 | |||
183 | +++ python/libertine/HostInfo.py 2016-06-28 18:52:06 +0000 | |||
184 | @@ -0,0 +1,71 @@ | |||
185 | 1 | # Copyright 2016 Canonical Ltd. | ||
186 | 2 | # | ||
187 | 3 | # This program is free software: you can redistribute it and/or modify it | ||
188 | 4 | # under the terms of the GNU General Public License version 3, as published | ||
189 | 5 | # by the Free Software Foundation. | ||
190 | 6 | # | ||
191 | 7 | # This program is distributed in the hope that it will be useful, but | ||
192 | 8 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
193 | 9 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
194 | 10 | # PURPOSE. See the GNU General Public License for more details. | ||
195 | 11 | # | ||
196 | 12 | # You should have received a copy of the GNU General Public License along | ||
197 | 13 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
198 | 14 | |||
199 | 15 | import lsb_release | ||
200 | 16 | import platform | ||
201 | 17 | import subprocess | ||
202 | 18 | |||
203 | 19 | from distro_info import UbuntuDistroInfo | ||
204 | 20 | |||
205 | 21 | |||
206 | 22 | class HostInfo(object): | ||
207 | 23 | |||
208 | 24 | def select_container_type_by_kernel(self): | ||
209 | 25 | kernel_release = platform.release().split('.') | ||
210 | 26 | |||
211 | 27 | if int(kernel_release[0]) >= 4: | ||
212 | 28 | return "lxc" | ||
213 | 29 | elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13: | ||
214 | 30 | return "lxc" | ||
215 | 31 | else: | ||
216 | 32 | return "chroot" | ||
217 | 33 | |||
218 | 34 | def get_host_distro_release(self): | ||
219 | 35 | distinfo = lsb_release.get_distro_information() | ||
220 | 36 | |||
221 | 37 | return distinfo.get('CODENAME', 'n/a') | ||
222 | 38 | |||
223 | 39 | def is_distro_valid(self, distro, force): | ||
224 | 40 | if force: | ||
225 | 41 | return UbuntuDistroInfo().valid(distro) | ||
226 | 42 | |||
227 | 43 | if distro == self.get_host_distro_release(): | ||
228 | 44 | return True | ||
229 | 45 | |||
230 | 46 | supported_distros = UbuntuDistroInfo().supported() | ||
231 | 47 | |||
232 | 48 | try: | ||
233 | 49 | supported_distros.index(distro) | ||
234 | 50 | except ValueError: | ||
235 | 51 | return False | ||
236 | 52 | |||
237 | 53 | return True | ||
238 | 54 | |||
239 | 55 | def get_distro_codename(self, distro): | ||
240 | 56 | ubuntu_distro_info = UbuntuDistroInfo() | ||
241 | 57 | |||
242 | 58 | for row in ubuntu_distro_info._rows: | ||
243 | 59 | if row['series'] == distro: | ||
244 | 60 | return row['codename'] | ||
245 | 61 | |||
246 | 62 | return None | ||
247 | 63 | |||
248 | 64 | def get_host_architecture(self): | ||
249 | 65 | dpkg = subprocess.Popen(['dpkg', '--print-architecture'], | ||
250 | 66 | stdout=subprocess.PIPE, | ||
251 | 67 | universal_newlines=True) | ||
252 | 68 | if dpkg.wait() != 0: | ||
253 | 69 | parser.error("Failed to determine the local architecture.") | ||
254 | 70 | |||
255 | 71 | return dpkg.stdout.read().strip() | ||
256 | 0 | 72 | ||
257 | === modified file 'python/libertine/Libertine.py' | |||
258 | --- python/libertine/Libertine.py 2016-06-14 20:05:24 +0000 | |||
259 | +++ python/libertine/Libertine.py 2016-06-28 18:52:06 +0000 | |||
260 | @@ -16,30 +16,12 @@ | |||
261 | 16 | from gi.repository import Libertine | 16 | from gi.repository import Libertine |
262 | 17 | import abc | 17 | import abc |
263 | 18 | import contextlib | 18 | import contextlib |
264 | 19 | import json | ||
265 | 20 | import libertine.utils | 19 | import libertine.utils |
266 | 21 | import os | 20 | import os |
267 | 22 | import shutil | 21 | import shutil |
268 | 23 | 22 | ||
288 | 24 | 23 | from libertine.ContainersConfig import ContainersConfig | |
289 | 25 | def get_container_type(container_id): | 24 | from libertine.HostInfo import HostInfo |
271 | 26 | """ | ||
272 | 27 | Retrieves the type of container for a given container ID. | ||
273 | 28 | :param container_id: The Container ID to search for. | ||
274 | 29 | """ | ||
275 | 30 | try: | ||
276 | 31 | with open(libertine.utils.get_libertine_database_file_path()) as fd: | ||
277 | 32 | container_list = json.load(fd) | ||
278 | 33 | |||
279 | 34 | for container in container_list["containerList"]: | ||
280 | 35 | if container["id"] == container_id: | ||
281 | 36 | return container["type"] | ||
282 | 37 | |||
283 | 38 | except FileNotFoundError: | ||
284 | 39 | pass | ||
285 | 40 | |||
286 | 41 | # Return lxc as the default container type | ||
287 | 42 | return "lxc" | ||
290 | 43 | 25 | ||
291 | 44 | 26 | ||
292 | 45 | def apt_args_for_verbosity_level(verbosity): | 27 | def apt_args_for_verbosity_level(verbosity): |
293 | @@ -207,21 +189,6 @@ | |||
294 | 207 | elif command == 'delete-archive': | 189 | elif command == 'delete-archive': |
295 | 208 | return self.run_in_container("add-apt-repository -y -r " + args[0]) | 190 | return self.run_in_container("add-apt-repository -y -r " + args[0]) |
296 | 209 | 191 | ||
297 | 210 | def get_container_distro(self, container_id): | ||
298 | 211 | """ | ||
299 | 212 | Retrieves the distro code name for a given container ID. | ||
300 | 213 | |||
301 | 214 | :param container_id: The Container ID to search for. | ||
302 | 215 | """ | ||
303 | 216 | with open(libertine.utils.get_libertine_database_file_path()) as fd: | ||
304 | 217 | container_list = json.load(fd) | ||
305 | 218 | |||
306 | 219 | for container in container_list["containerList"]: | ||
307 | 220 | if container["id"] == container_id: | ||
308 | 221 | return container["distro"] | ||
309 | 222 | |||
310 | 223 | return "" | ||
311 | 224 | |||
312 | 225 | @property | 192 | @property |
313 | 226 | def name(self): | 193 | def name(self): |
314 | 227 | """ | 194 | """ |
315 | @@ -281,9 +248,9 @@ | |||
316 | 281 | """ | 248 | """ |
317 | 282 | super().__init__() | 249 | super().__init__() |
318 | 283 | 250 | ||
320 | 284 | container_type = get_container_type(container_id) | 251 | container_type = ContainersConfig().get_container_type(container_id) |
321 | 285 | 252 | ||
323 | 286 | if container_type == "lxc": | 253 | if container_type == None or container_type == "lxc": |
324 | 287 | from libertine.LxcContainer import LibertineLXC | 254 | from libertine.LxcContainer import LibertineLXC |
325 | 288 | self.container = LibertineLXC(container_id) | 255 | self.container = LibertineLXC(container_id) |
326 | 289 | elif container_type == "chroot": | 256 | elif container_type == "chroot": |
327 | @@ -320,6 +287,9 @@ | |||
328 | 320 | """ | 287 | """ |
329 | 321 | Creates the container. | 288 | Creates the container. |
330 | 322 | """ | 289 | """ |
331 | 290 | self.container.architecture = HostInfo().get_host_architecture() | ||
332 | 291 | self.container.installed_release = ContainersConfig().get_container_distro(self.container_id) | ||
333 | 292 | |||
334 | 323 | return self.container.create_libertine_container(password, multiarch, verbosity) | 293 | return self.container.create_libertine_container(password, multiarch, verbosity) |
335 | 324 | 294 | ||
336 | 325 | def update_libertine_container(self, verbosity=1): | 295 | def update_libertine_container(self, verbosity=1): |
337 | @@ -380,7 +350,7 @@ | |||
338 | 380 | :param app_exec_line: the application exec line as passed in by | 350 | :param app_exec_line: the application exec line as passed in by |
339 | 381 | ubuntu-app-launch | 351 | ubuntu-app-launch |
340 | 382 | """ | 352 | """ |
342 | 383 | if libertine.utils.container_exists(self.container.container_id): | 353 | if ContainersConfig().container_exists(self.container.container_id): |
343 | 384 | self.container.launch_application(app_exec_line) | 354 | self.container.launch_application(app_exec_line) |
344 | 385 | else: | 355 | else: |
345 | 386 | raise RuntimeError("Container with id %s does not exist." % self.container.container_id) | 356 | raise RuntimeError("Container with id %s does not exist." % self.container.container_id) |
346 | 387 | 357 | ||
347 | === modified file 'python/libertine/LxcContainer.py' | |||
348 | --- python/libertine/LxcContainer.py 2016-06-24 18:04:31 +0000 | |||
349 | +++ python/libertine/LxcContainer.py 2016-06-28 18:52:06 +0000 | |||
350 | @@ -143,8 +143,6 @@ | |||
351 | 143 | if password is None: | 143 | if password is None: |
352 | 144 | return False | 144 | return False |
353 | 145 | 145 | ||
354 | 146 | installed_release = self.get_container_distro(self.container_id) | ||
355 | 147 | |||
356 | 148 | username = os.environ['USER'] | 146 | username = os.environ['USER'] |
357 | 149 | user_id = os.getuid() | 147 | user_id = os.getuid() |
358 | 150 | group_id = os.getgid() | 148 | group_id = os.getgid() |
359 | @@ -173,13 +171,10 @@ | |||
360 | 173 | 171 | ||
361 | 174 | utils.create_libertine_user_data_dir(self.container_id) | 172 | utils.create_libertine_user_data_dir(self.container_id) |
362 | 175 | 173 | ||
363 | 176 | # Figure out the host architecture | ||
364 | 177 | architecture = utils.get_host_architecture() | ||
365 | 178 | |||
366 | 179 | if not self.container.create("download", 0, | 174 | if not self.container.create("download", 0, |
367 | 180 | {"dist": "ubuntu", | 175 | {"dist": "ubuntu", |
370 | 181 | "release": installed_release, | 176 | "release": self.installed_release, |
371 | 182 | "arch": architecture}): | 177 | "arch": self.architecture}): |
372 | 183 | print("Failed to create container") | 178 | print("Failed to create container") |
373 | 184 | return False | 179 | return False |
374 | 185 | 180 | ||
375 | @@ -198,7 +193,7 @@ | |||
376 | 198 | self.run_in_container("useradd -u {} -p {} -G sudo {}".format( | 193 | self.run_in_container("useradd -u {} -p {} -G sudo {}".format( |
377 | 199 | str(user_id), crypt.crypt(password), str(username))) | 194 | str(user_id), crypt.crypt(password), str(username))) |
378 | 200 | 195 | ||
380 | 201 | if multiarch and architecture == 'amd64': | 196 | if multiarch and self.architecture == 'amd64': |
381 | 202 | if verbosity == 1: | 197 | if verbosity == 1: |
382 | 203 | print("Adding i386 multiarch support...") | 198 | print("Adding i386 multiarch support...") |
383 | 204 | self.run_in_container("dpkg --add-architecture i386") | 199 | self.run_in_container("dpkg --add-architecture i386") |
384 | 205 | 200 | ||
385 | === modified file 'python/libertine/utils.py' | |||
386 | --- python/libertine/utils.py 2016-06-23 13:27:26 +0000 | |||
387 | +++ python/libertine/utils.py 2016-06-28 18:52:06 +0000 | |||
388 | @@ -16,9 +16,7 @@ | |||
389 | 16 | # You should have received a copy of the GNU General Public License | 16 | # You should have received a copy of the GNU General Public License |
390 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
391 | 18 | 18 | ||
392 | 19 | import json | ||
393 | 20 | import os | 19 | import os |
394 | 21 | import psutil | ||
395 | 22 | import shlex | 20 | import shlex |
396 | 23 | import subprocess | 21 | import subprocess |
397 | 24 | import xdg.BaseDirectory as basedir | 22 | import xdg.BaseDirectory as basedir |
398 | @@ -28,22 +26,6 @@ | |||
399 | 28 | from gi.repository import Libertine | 26 | from gi.repository import Libertine |
400 | 29 | 27 | ||
401 | 30 | 28 | ||
402 | 31 | def container_exists(container_id): | ||
403 | 32 | container_config_file_path = get_libertine_database_file_path() | ||
404 | 33 | |||
405 | 34 | if (os.path.exists(container_config_file_path) and | ||
406 | 35 | os.path.getsize(container_config_file_path) != 0): | ||
407 | 36 | with open(get_libertine_database_file_path()) as fd: | ||
408 | 37 | container_list = json.load(fd) | ||
409 | 38 | |||
410 | 39 | if container_list: | ||
411 | 40 | for container in container_list['containerList']: | ||
412 | 41 | if container['id'] == container_id: | ||
413 | 42 | return True | ||
414 | 43 | |||
415 | 44 | return False | ||
416 | 45 | |||
417 | 46 | |||
418 | 47 | def get_libertine_container_rootfs_path(container_id): | 29 | def get_libertine_container_rootfs_path(container_id): |
419 | 48 | path = Libertine.container_path(container_id) | 30 | path = Libertine.container_path(container_id) |
420 | 49 | 31 | ||
421 | @@ -97,16 +79,6 @@ | |||
422 | 97 | return os.path.join(get_user_runtime_dir(), 'libertine') | 79 | return os.path.join(get_user_runtime_dir(), 'libertine') |
423 | 98 | 80 | ||
424 | 99 | 81 | ||
425 | 100 | def get_host_architecture(): | ||
426 | 101 | dpkg = subprocess.Popen(['dpkg', '--print-architecture'], | ||
427 | 102 | stdout=subprocess.PIPE, | ||
428 | 103 | universal_newlines=True) | ||
429 | 104 | if dpkg.wait() != 0: | ||
430 | 105 | parser.error("Failed to determine the local architecture.") | ||
431 | 106 | |||
432 | 107 | return dpkg.stdout.read().strip() | ||
433 | 108 | |||
434 | 109 | |||
435 | 110 | def get_common_xdg_directories(): | 82 | def get_common_xdg_directories(): |
436 | 111 | return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads'] | 83 | return ['Documents', 'Music', 'Pictures', 'Videos', 'Downloads'] |
437 | 112 | 84 | ||
438 | @@ -167,4 +139,4 @@ | |||
439 | 167 | gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" % | 139 | gdbus_cmd = ("gdbus emit --session --object-path %s --signal %s %s" % |
440 | 168 | (scopes_object_path, invalidate_signal, libertine_scope_id)) | 140 | (scopes_object_path, invalidate_signal, libertine_scope_id)) |
441 | 169 | 141 | ||
443 | 170 | subprocess.Popen(shlex.split(gdbus_cmd)) | 142 | subprocess.Popen(shlex.split(gdbus_cmd), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
444 | 171 | 143 | ||
445 | === modified file 'tools/libertine-container-manager' | |||
446 | --- tools/libertine-container-manager 2016-06-27 17:58:57 +0000 | |||
447 | +++ tools/libertine-container-manager 2016-06-28 18:52:06 +0000 | |||
448 | @@ -18,71 +18,26 @@ | |||
449 | 18 | 18 | ||
450 | 19 | import argparse | 19 | import argparse |
451 | 20 | import libertine.utils | 20 | import libertine.utils |
452 | 21 | import lsb_release | ||
453 | 22 | import getpass | 21 | import getpass |
454 | 23 | import os | 22 | import os |
455 | 24 | import platform | ||
456 | 25 | import sys | 23 | import sys |
457 | 26 | 24 | ||
458 | 27 | from apt.debfile import DebPackage | 25 | from apt.debfile import DebPackage |
459 | 28 | from distro_info import UbuntuDistroInfo | ||
460 | 29 | from libertine import LibertineContainer | 26 | from libertine import LibertineContainer |
461 | 30 | from libertine.ContainersConfig import ContainersConfig | 27 | from libertine.ContainersConfig import ContainersConfig |
506 | 31 | 28 | from libertine.HostInfo import HostInfo | |
463 | 32 | |||
464 | 33 | def select_container_type(): | ||
465 | 34 | kernel_release = platform.release().split('.') | ||
466 | 35 | |||
467 | 36 | if int(kernel_release[0]) >= 4: | ||
468 | 37 | return "lxc" | ||
469 | 38 | elif int(kernel_release[0]) == 3 and int(kernel_release[1]) >= 13: | ||
470 | 39 | return "lxc" | ||
471 | 40 | else: | ||
472 | 41 | return "chroot" | ||
473 | 42 | |||
474 | 43 | |||
475 | 44 | def get_host_distro_release(): | ||
476 | 45 | distinfo = lsb_release.get_distro_information() | ||
477 | 46 | |||
478 | 47 | return distinfo.get('CODENAME', 'n/a') | ||
479 | 48 | |||
480 | 49 | |||
481 | 50 | def is_distro_valid(distro, force): | ||
482 | 51 | if force: | ||
483 | 52 | return UbuntuDistroInfo().valid(distro) | ||
484 | 53 | |||
485 | 54 | if distro == get_host_distro_release(): | ||
486 | 55 | return True | ||
487 | 56 | |||
488 | 57 | supported_distros = UbuntuDistroInfo().supported() | ||
489 | 58 | |||
490 | 59 | try: | ||
491 | 60 | supported_distros.index(distro) | ||
492 | 61 | except ValueError: | ||
493 | 62 | return False | ||
494 | 63 | |||
495 | 64 | return True | ||
496 | 65 | |||
497 | 66 | |||
498 | 67 | def get_distro_codename(distro): | ||
499 | 68 | ubuntu_distro_info = UbuntuDistroInfo() | ||
500 | 69 | |||
501 | 70 | for row in ubuntu_distro_info._rows: | ||
502 | 71 | if row['series'] == distro: | ||
503 | 72 | return row['codename'] | ||
504 | 73 | |||
505 | 74 | return None | ||
507 | 75 | 29 | ||
508 | 76 | 30 | ||
509 | 77 | class LibertineContainerManager(object): | 31 | class LibertineContainerManager(object): |
510 | 78 | 32 | ||
511 | 79 | def __init__(self): | 33 | def __init__(self): |
512 | 80 | self.containers_config = ContainersConfig() | 34 | self.containers_config = ContainersConfig() |
513 | 35 | self.host_info = HostInfo() | ||
514 | 81 | 36 | ||
515 | 82 | def create(self, args): | 37 | def create(self, args): |
516 | 83 | password = None | 38 | password = None |
517 | 84 | 39 | ||
519 | 85 | if args.distro and not is_distro_valid(args.distro, args.force): | 40 | if args.distro and not self.host_info.is_distro_valid(args.distro, args.force): |
520 | 86 | print("Invalid distro %s" % args.distro, file=sys.stderr) | 41 | print("Invalid distro %s" % args.distro, file=sys.stderr) |
521 | 87 | sys.exit(1) | 42 | sys.exit(1) |
522 | 88 | 43 | ||
523 | @@ -93,14 +48,14 @@ | |||
524 | 93 | args.id = get_unique_container_id(distro) | 48 | args.id = get_unique_container_id(distro) |
525 | 94 | 49 | ||
526 | 95 | if not args.type: | 50 | if not args.type: |
528 | 96 | container_type = select_container_type() | 51 | container_type = self.host_info.select_container_type_by_kernel() |
529 | 97 | else: | 52 | else: |
530 | 98 | container_type = args.type | 53 | container_type = args.type |
531 | 99 | 54 | ||
532 | 100 | if not args.distro: | 55 | if not args.distro: |
534 | 101 | args.distro = get_host_distro_release() | 56 | args.distro = self.host_info.get_host_distro_release() |
535 | 102 | elif container_type == "chroot": | 57 | elif container_type == "chroot": |
537 | 103 | host_distro = get_host_distro_release() | 58 | host_distro = self.host_info.get_host_distro_release() |
538 | 104 | 59 | ||
539 | 105 | if args.distro != host_distro: | 60 | if args.distro != host_distro: |
540 | 106 | print("The container distribution needs to match the host ditribution for chroot" | 61 | print("The container distribution needs to match the host ditribution for chroot" |
541 | @@ -109,7 +64,7 @@ | |||
542 | 109 | sys.exit(1) | 64 | sys.exit(1) |
543 | 110 | 65 | ||
544 | 111 | if not args.name: | 66 | if not args.name: |
546 | 112 | args.name = "Ubuntu \'" + get_distro_codename(args.distro) + "\'" | 67 | args.name = "Ubuntu \'" + self.host_info.get_distro_codename(args.distro) + "\'" |
547 | 113 | 68 | ||
548 | 114 | if container_type == "lxc": | 69 | if container_type == "lxc": |
549 | 115 | if args.password: | 70 | if args.password: |
550 | @@ -259,7 +214,7 @@ | |||
551 | 259 | 214 | ||
552 | 260 | container = LibertineContainer(container_id) | 215 | container = LibertineContainer(container_id) |
553 | 261 | 216 | ||
555 | 262 | if args.multiarch and libertine.utils.get_host_architecture() == 'amd64': | 217 | if args.multiarch and self.host_info.get_host_architecture() == 'amd64': |
556 | 263 | multiarch = 'disabled' | 218 | multiarch = 'disabled' |
557 | 264 | if args.multiarch == 'enable': | 219 | if args.multiarch == 'enable': |
558 | 265 | multiarch = 'enabled' | 220 | multiarch = 'enabled' |
559 | 266 | 221 | ||
560 | === modified file 'tools/libertine-launch' | |||
561 | --- tools/libertine-launch 2016-06-24 20:08:12 +0000 | |||
562 | +++ tools/libertine-launch 2016-06-28 18:52:06 +0000 | |||
563 | @@ -24,6 +24,7 @@ | |||
564 | 24 | import psutil | 24 | import psutil |
565 | 25 | import shlex | 25 | import shlex |
566 | 26 | import time | 26 | import time |
567 | 27 | |||
568 | 27 | from libertine import LibertineContainer | 28 | from libertine import LibertineContainer |
569 | 28 | 29 | ||
570 | 29 | 30 | ||
571 | @@ -86,9 +87,6 @@ | |||
572 | 86 | help='exec line') | 87 | help='exec line') |
573 | 87 | args = arg_parser.parse_args() | 88 | args = arg_parser.parse_args() |
574 | 88 | 89 | ||
575 | 89 | if not libertine.utils.container_exists(args.container_id): | ||
576 | 90 | raise RuntimeError("Container ID %s does not exist." % args.container_id) | ||
577 | 91 | |||
578 | 92 | # remove problematic environment variables | 90 | # remove problematic environment variables |
579 | 93 | for e in ['QT_QPA_PLATFORM', 'LD_LIBRARY_PATH', 'FAKECHROOT_BASE', 'FAKECHROOT_CMD_SUBST']: | 91 | for e in ['QT_QPA_PLATFORM', 'LD_LIBRARY_PATH', 'FAKECHROOT_BASE', 'FAKECHROOT_CMD_SUBST']: |
580 | 94 | if e in os.environ: | 92 | if e in os.environ: |
PASSED: Continuous integration, rev:259 /jenkins. canonical. com/libertine/ job/lp- libertine- ci/20/ /jenkins. canonical. com/libertine/ job/build/ 107 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=amd64, release= vivid+overlay, testname= default/ 74 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=amd64, release= xenial+ overlay, testname= default/ 74 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=amd64, release= yakkety, testname= default/ 74 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=i386, release= vivid+overlay, testname= default/ 74 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=i386, release= xenial+ overlay, testname= default/ 74 /jenkins. canonical. com/libertine/ job/test- 0-autopkgtest/ label=i386, release= yakkety, testname= default/ 74 /jenkins. canonical. com/libertine/ job/lp- generic- update- mp/87/console /jenkins. canonical. com/libertine/ job/build- 0-fetch/ 110 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= vivid+overlay/ 95 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= xenial+ overlay/ 95 /jenkins. canonical. com/libertine/ job/build- 1-sourcepkg/ release= yakkety/ 95 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= vivid+overlay/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= vivid+overlay/ 88/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= xenial+ overlay/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= xenial+ overlay/ 88/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= yakkety/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=amd64, release= yakkety/ 88/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= vivid+overlay/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= vivid+overlay/ 88/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= xenial+ overlay/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= xenial+ overlay/ 88/artifact/ output/ *zip*/output. zip /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= yakkety/ 88 /jenkins. canonical. com/libertine/ job/build- 2-binpkg/ arch=i386, release= yakkety/ 88/artifact/ output/ *zip*/output. zip
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: 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:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
deb: https:/
Click here to trigger a rebuild: /jenkins. canonical. com/libertine/ job/lp- libertine- ci/20/rebuild
https:/