Merge lp:~cjwatson/launchpad-buildd/build-livefs-operation into lp:launchpad-buildd
- build-livefs-operation
- Merge into trunk
Proposed by
Colin Watson
Status: | Merged |
---|---|
Merged at revision: | 261 |
Proposed branch: | lp:~cjwatson/launchpad-buildd/build-livefs-operation |
Merge into: | lp:launchpad-buildd |
Prerequisite: | lp:~cjwatson/launchpad-buildd/gather-results-via-backend |
Diff against target: |
607 lines (+289/-127) 10 files modified
MANIFEST.in (+0/-1) debian/changelog (+1/-0) debian/launchpad-buildd.install (+0/-1) lpbuildd/livefs.py (+2/-11) lpbuildd/target/backend.py (+2/-1) lpbuildd/target/build_livefs.py (+77/-109) lpbuildd/target/chroot.py (+4/-1) lpbuildd/target/cli.py (+2/-0) lpbuildd/target/tests/test_build_livefs.py (+196/-0) lpbuildd/tests/test_livefs.py (+5/-3) |
To merge this branch: | bzr merge lp:~cjwatson/launchpad-buildd/build-livefs-operation |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
William Grant | code | Approve | |
Review via email: mp+328657@code.launchpad.net |
Commit message
Convert buildlivefs to the new Operation framework and add unit tests.
Description of the change
To post a comment you must log in.
- 259. By Colin Watson
-
Silence a logging warning.
Revision history for this message
William Grant (wgrant) : | # |
review:
Approve
(code)
- 260. By Colin Watson
-
Merge trunk.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'MANIFEST.in' |
2 | --- MANIFEST.in 2017-08-22 14:46:10 +0000 |
3 | +++ MANIFEST.in 2017-08-22 16:37:45 +0000 |
4 | @@ -1,6 +1,5 @@ |
5 | include LICENSE |
6 | include Makefile |
7 | -include bin/buildlivefs |
8 | include bin/buildrecipe |
9 | include bin/buildsnap |
10 | include bin/generate-translation-templates |
11 | |
12 | === modified file 'debian/changelog' |
13 | --- debian/changelog 2017-08-22 16:27:41 +0000 |
14 | +++ debian/changelog 2017-08-22 16:37:45 +0000 |
15 | @@ -22,6 +22,7 @@ |
16 | * Rewrite scan-for-processes in Python, allowing it to have unit tests. |
17 | * Improve "RUN:" log messages to be copy-and-pasteable as shell commands, |
18 | which is sometimes useful while debugging. |
19 | + * Convert buildlivefs to the new Operation framework and add unit tests. |
20 | |
21 | -- Colin Watson <cjwatson@ubuntu.com> Tue, 25 Jul 2017 23:07:58 +0100 |
22 | |
23 | |
24 | === modified file 'debian/launchpad-buildd.install' |
25 | --- debian/launchpad-buildd.install 2017-08-22 14:46:10 +0000 |
26 | +++ debian/launchpad-buildd.install 2017-08-22 16:37:45 +0000 |
27 | @@ -3,7 +3,6 @@ |
28 | debian/upgrade-config usr/share/launchpad-buildd |
29 | sbuildrc usr/share/launchpad-buildd |
30 | template-buildd-slave.conf usr/share/launchpad-buildd |
31 | -bin/buildlivefs usr/share/launchpad-buildd/slavebin |
32 | bin/buildrecipe usr/share/launchpad-buildd/slavebin |
33 | bin/buildsnap usr/share/launchpad-buildd/slavebin |
34 | bin/generate-translation-templates usr/share/launchpad-buildd/slavebin |
35 | |
36 | === modified file 'lpbuildd/livefs.py' |
37 | --- lpbuildd/livefs.py 2017-08-05 09:43:43 +0000 |
38 | +++ lpbuildd/livefs.py 2017-08-22 16:37:45 +0000 |
39 | @@ -25,10 +25,6 @@ |
40 | |
41 | initial_build_state = LiveFilesystemBuildState.BUILD_LIVEFS |
42 | |
43 | - def __init__(self, slave, buildid, **kwargs): |
44 | - DebianBuildManager.__init__(self, slave, buildid, **kwargs) |
45 | - self.build_livefs_path = os.path.join(self._slavebin, "buildlivefs") |
46 | - |
47 | def initiate(self, files, chroot, extra_args): |
48 | """Initiate a build with a given set of files and chroot.""" |
49 | self.subarch = extra_args.get("subarch") |
50 | @@ -45,17 +41,12 @@ |
51 | |
52 | def doRunBuild(self): |
53 | """Run the process to build the live filesystem.""" |
54 | - args = [ |
55 | - "buildlivefs", |
56 | - "--build-id", self._buildid, |
57 | - "--arch", self.arch_tag, |
58 | - ] |
59 | + args = [] |
60 | if self.subarch: |
61 | args.extend(["--subarch", self.subarch]) |
62 | args.extend(["--project", self.project]) |
63 | if self.subproject: |
64 | args.extend(["--subproject", self.subproject]) |
65 | - args.extend(["--series", self.series]) |
66 | if self.datestamp: |
67 | args.extend(["--datestamp", self.datestamp]) |
68 | if self.image_format: |
69 | @@ -66,7 +57,7 @@ |
70 | args.extend(["--locale", self.locale]) |
71 | for ppa in self.extra_ppas: |
72 | args.extend(["--extra-ppa", ppa]) |
73 | - self.runSubProcess(self.build_livefs_path, args) |
74 | + self.runTargetSubProcess("buildlivefs", *args) |
75 | |
76 | def iterate_BUILD_LIVEFS(self, retcode): |
77 | """Finished building the live filesystem.""" |
78 | |
79 | === modified file 'lpbuildd/target/backend.py' |
80 | --- lpbuildd/target/backend.py 2017-08-22 15:55:44 +0000 |
81 | +++ lpbuildd/target/backend.py 2017-08-22 16:37:45 +0000 |
82 | @@ -37,13 +37,14 @@ |
83 | raise NotImplementedError |
84 | |
85 | def run(self, args, env=None, input_text=None, get_output=False, |
86 | - **kwargs): |
87 | + echo=False, **kwargs): |
88 | """Run a command in the target environment. |
89 | |
90 | :param args: the command and arguments to run. |
91 | :param env: additional environment variables to set. |
92 | :param input_text: input text to pass on the command's stdin. |
93 | :param get_output: if True, return the output from the command. |
94 | + :param echo: if True, print the command before executing it. |
95 | :param kwargs: additional keyword arguments for `subprocess.Popen`. |
96 | """ |
97 | raise NotImplementedError |
98 | |
99 | === renamed file 'bin/buildlivefs' => 'lpbuildd/target/build_livefs.py' (properties changed: +x to -x) |
100 | --- bin/buildlivefs 2017-07-28 11:15:51 +0000 |
101 | +++ lpbuildd/target/build_livefs.py 2017-08-22 16:37:45 +0000 |
102 | @@ -1,30 +1,25 @@ |
103 | -#! /usr/bin/python -u |
104 | # Copyright 2013-2017 Canonical Ltd. This software is licensed under the |
105 | # GNU Affero General Public License version 3 (see the file LICENSE). |
106 | |
107 | -"""A script that builds a live file system.""" |
108 | - |
109 | from __future__ import print_function |
110 | |
111 | __metaclass__ = type |
112 | |
113 | -from optparse import OptionParser |
114 | +from collections import OrderedDict |
115 | +import logging |
116 | import os |
117 | -import subprocess |
118 | -import sys |
119 | -import traceback |
120 | - |
121 | -from lpbuildd.util import ( |
122 | - set_personality, |
123 | - shell_escape, |
124 | - ) |
125 | - |
126 | - |
127 | -RETCODE_SUCCESS = 0 |
128 | + |
129 | +from lpbuildd.target.operation import Operation |
130 | +from lpbuildd.util import shell_escape |
131 | + |
132 | + |
133 | RETCODE_FAILURE_INSTALL = 200 |
134 | RETCODE_FAILURE_BUILD = 201 |
135 | |
136 | |
137 | +logger = logging.getLogger(__name__) |
138 | + |
139 | + |
140 | def get_build_path(build_id, *extra): |
141 | """Generate a path within the build directory. |
142 | |
143 | @@ -35,27 +30,34 @@ |
144 | return os.path.join(os.environ["HOME"], "build-" + build_id, *extra) |
145 | |
146 | |
147 | -class LiveFSBuilder: |
148 | - """Builds a live file system.""" |
149 | - |
150 | - def __init__(self, options): |
151 | - self.options = options |
152 | - self.chroot_path = get_build_path( |
153 | - self.options.build_id, 'chroot-autobuild') |
154 | - |
155 | - def chroot(self, args, echo=False): |
156 | - """Run a command in the chroot. |
157 | - |
158 | - :param args: the command and arguments to run. |
159 | - """ |
160 | - args = set_personality( |
161 | - args, self.options.arch, series=self.options.series) |
162 | - if echo: |
163 | - print("Running in chroot: %s" % |
164 | - ' '.join("'%s'" % arg for arg in args)) |
165 | - sys.stdout.flush() |
166 | - subprocess.check_call([ |
167 | - "/usr/bin/sudo", "/usr/sbin/chroot", self.chroot_path] + args) |
168 | +class BuildLiveFS(Operation): |
169 | + |
170 | + description = "Build a live file system." |
171 | + |
172 | + @classmethod |
173 | + def add_arguments(cls, parser): |
174 | + super(BuildLiveFS, cls).add_arguments(parser) |
175 | + parser.add_argument( |
176 | + "--subarch", metavar="SUBARCH", |
177 | + help="build for subarchitecture SUBARCH") |
178 | + parser.add_argument( |
179 | + "--project", metavar="PROJECT", help="build for project PROJECT") |
180 | + parser.add_argument( |
181 | + "--subproject", metavar="SUBPROJECT", |
182 | + help="build for subproject SUBPROJECT") |
183 | + parser.add_argument("--datestamp", help="date stamp") |
184 | + parser.add_argument( |
185 | + "--image-format", metavar="FORMAT", |
186 | + help="produce an image in FORMAT") |
187 | + parser.add_argument( |
188 | + "--proposed", default=False, action="store_true", |
189 | + help="enable use of -proposed pocket") |
190 | + parser.add_argument( |
191 | + "--locale", metavar="LOCALE", |
192 | + help="use ubuntu-defaults-image to build an image for LOCALE") |
193 | + parser.add_argument( |
194 | + "--extra-ppa", dest="extra_ppas", default=[], action="append", |
195 | + help="use this additional PPA") |
196 | |
197 | def run_build_command(self, args, env=None, echo=False): |
198 | """Run a build command in the chroot. |
199 | @@ -67,6 +69,7 @@ |
200 | |
201 | :param args: the command and arguments to run. |
202 | :param env: dictionary of additional environment variables to set. |
203 | + :param echo: if True, print the command before executing it. |
204 | """ |
205 | args = [shell_escape(arg) for arg in args] |
206 | if env: |
207 | @@ -74,28 +77,28 @@ |
208 | "%s=%s" % (key, shell_escape(value)) |
209 | for key, value in env.items()] + args |
210 | command = "cd /build && %s" % " ".join(args) |
211 | - self.chroot(["/bin/sh", "-c", command], echo=echo) |
212 | + self.backend.run(["/bin/sh", "-c", command], echo=echo) |
213 | |
214 | def install(self): |
215 | - self.chroot(["apt-get", "-y", "install", "livecd-rootfs"]) |
216 | - if self.options.arch == "i386": |
217 | - self.chroot([ |
218 | + self.backend.run(["apt-get", "-y", "install", "livecd-rootfs"]) |
219 | + if self.args.arch == "i386": |
220 | + self.backend.run([ |
221 | "apt-get", "-y", "--no-install-recommends", "install", |
222 | "ltsp-server", |
223 | ]) |
224 | - if self.options.locale is not None: |
225 | - self.chroot([ |
226 | + if self.args.locale is not None: |
227 | + self.backend.run([ |
228 | "apt-get", "-y", "--install-recommends", "install", |
229 | "ubuntu-defaults-builder", |
230 | ]) |
231 | |
232 | def build(self): |
233 | - if self.options.locale is not None: |
234 | + if self.args.locale is not None: |
235 | self.run_build_command([ |
236 | "ubuntu-defaults-image", |
237 | - "--locale", self.options.locale, |
238 | - "--arch", self.options.arch, |
239 | - "--release", self.options.series, |
240 | + "--locale", self.args.locale, |
241 | + "--arch", self.args.arch, |
242 | + "--release", self.args.series, |
243 | ]) |
244 | else: |
245 | self.run_build_command(["rm", "-rf", "auto"]) |
246 | @@ -106,70 +109,35 @@ |
247 | self.run_build_command(["ln", "-s", lb_script_path, "auto/"]) |
248 | self.run_build_command(["lb", "clean", "--purge"]) |
249 | |
250 | - base_lb_env = { |
251 | - "PROJECT": self.options.project, |
252 | - "ARCH": self.options.arch, |
253 | - } |
254 | - if self.options.subproject is not None: |
255 | - base_lb_env["SUBPROJECT"] = self.options.subproject |
256 | - if self.options.subarch is not None: |
257 | - base_lb_env["SUBARCH"] = self.options.subarch |
258 | - lb_env = dict(base_lb_env) |
259 | - lb_env["SUITE"] = self.options.series |
260 | - if self.options.datestamp is not None: |
261 | - lb_env["NOW"] = self.options.datestamp |
262 | - if self.options.image_format is not None: |
263 | - lb_env["IMAGEFORMAT"] = self.options.image_format |
264 | - if self.options.proposed: |
265 | + base_lb_env = OrderedDict() |
266 | + base_lb_env["PROJECT"] = self.args.project |
267 | + base_lb_env["ARCH"] = self.args.arch |
268 | + if self.args.subproject is not None: |
269 | + base_lb_env["SUBPROJECT"] = self.args.subproject |
270 | + if self.args.subarch is not None: |
271 | + base_lb_env["SUBARCH"] = self.args.subarch |
272 | + lb_env = base_lb_env.copy() |
273 | + lb_env["SUITE"] = self.args.series |
274 | + if self.args.datestamp is not None: |
275 | + lb_env["NOW"] = self.args.datestamp |
276 | + if self.args.image_format is not None: |
277 | + lb_env["IMAGEFORMAT"] = self.args.image_format |
278 | + if self.args.proposed: |
279 | lb_env["PROPOSED"] = "1" |
280 | - if self.options.extra_ppas: |
281 | - lb_env["EXTRA_PPAS"] = " ".join(self.options.extra_ppas) |
282 | + if self.args.extra_ppas: |
283 | + lb_env["EXTRA_PPAS"] = " ".join(self.args.extra_ppas) |
284 | self.run_build_command(["lb", "config"], env=lb_env) |
285 | self.run_build_command(["lb", "build"], env=base_lb_env) |
286 | |
287 | - |
288 | -def main(): |
289 | - parser = OptionParser() |
290 | - parser.add_option("--build-id", help="build identifier") |
291 | - parser.add_option( |
292 | - "--arch", metavar="ARCH", help="build for architecture ARCH") |
293 | - parser.add_option( |
294 | - "--subarch", metavar="SUBARCH", |
295 | - help="build for subarchitecture SUBARCH") |
296 | - parser.add_option( |
297 | - "--project", metavar="PROJECT", help="build for project PROJECT") |
298 | - parser.add_option( |
299 | - "--subproject", metavar="SUBPROJECT", |
300 | - help="build for subproject SUBPROJECT") |
301 | - parser.add_option( |
302 | - "--series", metavar="SERIES", help="build for series SERIES") |
303 | - parser.add_option("--datestamp", help="date stamp") |
304 | - parser.add_option( |
305 | - "--image-format", metavar="FORMAT", help="produce an image in FORMAT") |
306 | - parser.add_option( |
307 | - "--proposed", default=False, action="store_true", |
308 | - help="enable use of -proposed pocket") |
309 | - parser.add_option( |
310 | - "--locale", metavar="LOCALE", |
311 | - help="use ubuntu-defaults-image to build an image for LOCALE") |
312 | - parser.add_option( |
313 | - "--extra-ppa", dest="extra_ppas", default=[], action="append", |
314 | - help="use this additional PPA") |
315 | - options, _ = parser.parse_args() |
316 | - |
317 | - builder = LiveFSBuilder(options) |
318 | - try: |
319 | - builder.install() |
320 | - except Exception: |
321 | - traceback.print_exc() |
322 | - return RETCODE_FAILURE_INSTALL |
323 | - try: |
324 | - builder.build() |
325 | - except Exception: |
326 | - traceback.print_exc() |
327 | - return RETCODE_FAILURE_BUILD |
328 | - return RETCODE_SUCCESS |
329 | - |
330 | - |
331 | -if __name__ == "__main__": |
332 | - sys.exit(main()) |
333 | + def run(self): |
334 | + try: |
335 | + self.install() |
336 | + except Exception: |
337 | + logger.exception('Install failed') |
338 | + return RETCODE_FAILURE_INSTALL |
339 | + try: |
340 | + self.build() |
341 | + except Exception: |
342 | + logger.exception('Build failed') |
343 | + return RETCODE_FAILURE_BUILD |
344 | + return 0 |
345 | |
346 | === modified file 'lpbuildd/target/chroot.py' |
347 | --- lpbuildd/target/chroot.py 2017-08-22 16:01:39 +0000 |
348 | +++ lpbuildd/target/chroot.py 2017-08-22 16:37:45 +0000 |
349 | @@ -53,7 +53,7 @@ |
350 | self.copy_in(path, path) |
351 | |
352 | def run(self, args, env=None, input_text=None, get_output=False, |
353 | - **kwargs): |
354 | + echo=False, **kwargs): |
355 | """See `Backend`.""" |
356 | if env: |
357 | args = ["env"] + [ |
358 | @@ -61,6 +61,9 @@ |
359 | for key, value in env.items()] + args |
360 | if self.arch is not None: |
361 | args = set_personality(args, self.arch, series=self.series) |
362 | + if echo: |
363 | + print("Running in chroot: %s" % ' '.join( |
364 | + shell_escape(arg) for arg in args)) |
365 | cmd = ["sudo", "/usr/sbin/chroot", self.chroot_path] + args |
366 | if input_text is None and not get_output: |
367 | subprocess.check_call(cmd, cwd=self.chroot_path, **kwargs) |
368 | |
369 | === modified file 'lpbuildd/target/cli.py' |
370 | --- lpbuildd/target/cli.py 2017-08-22 14:52:43 +0000 |
371 | +++ lpbuildd/target/cli.py 2017-08-22 16:37:45 +0000 |
372 | @@ -14,6 +14,7 @@ |
373 | OverrideSourcesList, |
374 | Update, |
375 | ) |
376 | +from lpbuildd.target.build_livefs import BuildLiveFS |
377 | from lpbuildd.target.lifecycle import ( |
378 | Create, |
379 | KillProcesses, |
380 | @@ -44,6 +45,7 @@ |
381 | |
382 | operations = { |
383 | "add-trusted-keys": AddTrustedKeys, |
384 | + "buildlivefs": BuildLiveFS, |
385 | "override-sources-list": OverrideSourcesList, |
386 | "mount-chroot": Start, |
387 | "remove-build": Remove, |
388 | |
389 | === added file 'lpbuildd/target/tests/test_build_livefs.py' |
390 | --- lpbuildd/target/tests/test_build_livefs.py 1970-01-01 00:00:00 +0000 |
391 | +++ lpbuildd/target/tests/test_build_livefs.py 2017-08-22 16:37:45 +0000 |
392 | @@ -0,0 +1,196 @@ |
393 | +# Copyright 2017 Canonical Ltd. This software is licensed under the |
394 | +# GNU Affero General Public License version 3 (see the file LICENSE). |
395 | + |
396 | +__metaclass__ = type |
397 | + |
398 | +import subprocess |
399 | + |
400 | +from fixtures import FakeLogger |
401 | +from testtools import TestCase |
402 | +from testtools.matchers import ( |
403 | + AnyMatch, |
404 | + Equals, |
405 | + Is, |
406 | + MatchesAll, |
407 | + MatchesDict, |
408 | + MatchesListwise, |
409 | + ) |
410 | + |
411 | +from lpbuildd.target.build_livefs import ( |
412 | + RETCODE_FAILURE_BUILD, |
413 | + RETCODE_FAILURE_INSTALL, |
414 | + ) |
415 | +from lpbuildd.target.cli import parse_args |
416 | +from lpbuildd.tests.fakeslave import FakeMethod |
417 | + |
418 | + |
419 | +class RanCommand(MatchesListwise): |
420 | + |
421 | + def __init__(self, args, echo=None, **env): |
422 | + kwargs_matcher = {} |
423 | + if echo is not None: |
424 | + kwargs_matcher["echo"] = Is(echo) |
425 | + if env: |
426 | + kwargs_matcher["env"] = MatchesDict(env) |
427 | + super(RanCommand, self).__init__( |
428 | + [Equals((args,)), MatchesDict(kwargs_matcher)]) |
429 | + |
430 | + |
431 | +class RanAptGet(RanCommand): |
432 | + |
433 | + def __init__(self, *args): |
434 | + super(RanAptGet, self).__init__(["apt-get", "-y"] + list(args)) |
435 | + |
436 | + |
437 | +class RanBuildCommand(RanCommand): |
438 | + |
439 | + def __init__(self, command): |
440 | + super(RanBuildCommand, self).__init__( |
441 | + ["/bin/sh", "-c", "cd /build && " + command], echo=False) |
442 | + |
443 | + |
444 | +class TestBuildLiveFS(TestCase): |
445 | + |
446 | + def test_run_build_command_no_env(self): |
447 | + args = [ |
448 | + "buildlivefs", |
449 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
450 | + ] |
451 | + build_livefs = parse_args(args=args).operation |
452 | + build_livefs.run_build_command(["echo", "hello world"]) |
453 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
454 | + RanBuildCommand("echo 'hello world'"), |
455 | + ])) |
456 | + |
457 | + def test_run_build_command_env(self): |
458 | + args = [ |
459 | + "buildlivefs", |
460 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
461 | + ] |
462 | + build_livefs = parse_args(args=args).operation |
463 | + build_livefs.run_build_command( |
464 | + ["echo", "hello world"], env={"FOO": "bar baz"}) |
465 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
466 | + RanBuildCommand("env FOO='bar baz' echo 'hello world'"), |
467 | + ])) |
468 | + |
469 | + def test_install(self): |
470 | + args = [ |
471 | + "buildlivefs", |
472 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
473 | + ] |
474 | + build_livefs = parse_args(args=args).operation |
475 | + build_livefs.install() |
476 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
477 | + RanAptGet("install", "livecd-rootfs"), |
478 | + ])) |
479 | + |
480 | + def test_install_i386(self): |
481 | + args = [ |
482 | + "buildlivefs", |
483 | + "--backend=fake", "--series=xenial", "--arch=i386", "1", |
484 | + ] |
485 | + build_livefs = parse_args(args=args).operation |
486 | + build_livefs.install() |
487 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
488 | + RanAptGet("install", "livecd-rootfs"), |
489 | + RanAptGet("--no-install-recommends", "install", "ltsp-server"), |
490 | + ])) |
491 | + |
492 | + def test_install_locale(self): |
493 | + args = [ |
494 | + "buildlivefs", |
495 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
496 | + "--locale=zh_CN", |
497 | + ] |
498 | + build_livefs = parse_args(args=args).operation |
499 | + build_livefs.install() |
500 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
501 | + RanAptGet("install", "livecd-rootfs"), |
502 | + RanAptGet( |
503 | + "--install-recommends", "install", "ubuntu-defaults-builder"), |
504 | + ])) |
505 | + |
506 | + def test_build(self): |
507 | + args = [ |
508 | + "buildlivefs", |
509 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
510 | + "--project=ubuntu", |
511 | + ] |
512 | + build_livefs = parse_args(args=args).operation |
513 | + build_livefs.build() |
514 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
515 | + RanBuildCommand("rm -rf auto"), |
516 | + RanBuildCommand("mkdir -p auto"), |
517 | + RanBuildCommand( |
518 | + "ln -s /usr/share/livecd-rootfs/live-build/auto/config auto/"), |
519 | + RanBuildCommand( |
520 | + "ln -s /usr/share/livecd-rootfs/live-build/auto/build auto/"), |
521 | + RanBuildCommand( |
522 | + "ln -s /usr/share/livecd-rootfs/live-build/auto/clean auto/"), |
523 | + RanBuildCommand("lb clean --purge"), |
524 | + RanBuildCommand( |
525 | + "env PROJECT=ubuntu ARCH=amd64 SUITE=xenial lb config"), |
526 | + RanBuildCommand("env PROJECT=ubuntu ARCH=amd64 lb build"), |
527 | + ])) |
528 | + |
529 | + def test_build_locale(self): |
530 | + args = [ |
531 | + "buildlivefs", |
532 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
533 | + "--locale=zh_CN", |
534 | + ] |
535 | + build_livefs = parse_args(args=args).operation |
536 | + build_livefs.build() |
537 | + self.assertThat(build_livefs.backend.run.calls, MatchesListwise([ |
538 | + RanBuildCommand( |
539 | + "ubuntu-defaults-image --locale zh_CN --arch amd64 " |
540 | + "--release xenial"), |
541 | + ])) |
542 | + |
543 | + def test_run_succeeds(self): |
544 | + args = [ |
545 | + "buildlivefs", |
546 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
547 | + "--project=ubuntu", |
548 | + ] |
549 | + build_livefs = parse_args(args=args).operation |
550 | + self.assertEqual(0, build_livefs.run()) |
551 | + self.assertThat(build_livefs.backend.run.calls, MatchesAll( |
552 | + AnyMatch(RanAptGet("install", "livecd-rootfs")), |
553 | + AnyMatch(RanBuildCommand( |
554 | + "env PROJECT=ubuntu ARCH=amd64 lb build")))) |
555 | + |
556 | + def test_run_install_fails(self): |
557 | + class FailInstall(FakeMethod): |
558 | + def __call__(self, run_args, *args, **kwargs): |
559 | + super(FailInstall, self).__call__(run_args, *args, **kwargs) |
560 | + if run_args[0] == "apt-get": |
561 | + raise subprocess.CalledProcessError(1, run_args) |
562 | + |
563 | + self.useFixture(FakeLogger()) |
564 | + args = [ |
565 | + "buildlivefs", |
566 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
567 | + "--project=ubuntu", |
568 | + ] |
569 | + build_livefs = parse_args(args=args).operation |
570 | + build_livefs.backend.run = FailInstall() |
571 | + self.assertEqual(RETCODE_FAILURE_INSTALL, build_livefs.run()) |
572 | + |
573 | + def test_run_build_fails(self): |
574 | + class FailBuild(FakeMethod): |
575 | + def __call__(self, run_args, *args, **kwargs): |
576 | + super(FailBuild, self).__call__(run_args, *args, **kwargs) |
577 | + if run_args[0] == "/bin/sh": |
578 | + raise subprocess.CalledProcessError(1, run_args) |
579 | + |
580 | + self.useFixture(FakeLogger()) |
581 | + args = [ |
582 | + "buildlivefs", |
583 | + "--backend=fake", "--series=xenial", "--arch=amd64", "1", |
584 | + "--project=ubuntu", |
585 | + ] |
586 | + build_livefs = parse_args(args=args).operation |
587 | + build_livefs.backend.run = FailBuild() |
588 | + self.assertEqual(RETCODE_FAILURE_BUILD, build_livefs.run()) |
589 | |
590 | === modified file 'lpbuildd/tests/test_livefs.py' |
591 | --- lpbuildd/tests/test_livefs.py 2017-08-22 15:55:44 +0000 |
592 | +++ lpbuildd/tests/test_livefs.py 2017-08-22 16:37:45 +0000 |
593 | @@ -75,9 +75,11 @@ |
594 | self.assertEqual( |
595 | LiveFilesystemBuildState.BUILD_LIVEFS, self.getState()) |
596 | expected_command = [ |
597 | - "sharepath/slavebin/buildlivefs", "buildlivefs", "--build-id", |
598 | - self.buildid, "--arch", "i386", "--project", "ubuntu", |
599 | - "--series", "saucy", |
600 | + "sharepath/slavebin/in-target", "in-target", |
601 | + "buildlivefs", |
602 | + "--backend=chroot", "--series=saucy", "--arch=i386", |
603 | + self.buildid, |
604 | + "--project", "ubuntu", |
605 | ] |
606 | self.assertEqual(expected_command, self.buildmanager.commands[-1]) |
607 | self.assertEqual( |