Merge lp:~cjwatson/launchpad-buildd/faster-cleanup into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 338
Proposed branch: lp:~cjwatson/launchpad-buildd/faster-cleanup
Merge into: lp:launchpad-buildd
Diff against target: 192 lines (+116/-6)
4 files modified
debian/changelog (+8/-0)
lpbuildd/debian.py (+4/-3)
lpbuildd/slave.py (+11/-3)
lpbuildd/tests/test_debian.py (+93/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/faster-cleanup
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+344938@code.launchpad.net

Commit message

If the extra build arguments include fast_cleanup: True, then skip the final cleanup steps of the build. This can be used when building in a VM that is guaranteed to be torn down after the build.

Description of the change

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2018-04-23 08:45:51 +0000
+++ debian/changelog 2018-05-02 09:01:56 +0000
@@ -1,3 +1,11 @@
1launchpad-buildd (162) UNRELEASED; urgency=medium
2
3 * If the extra build arguments include fast_cleanup: True, then skip the
4 final cleanup steps of the build. This can be used when building in a
5 VM that is guaranteed to be torn down after the build.
6
7 -- Colin Watson <cjwatson@ubuntu.com> Wed, 02 May 2018 09:58:15 +0100
8
1launchpad-buildd (161) xenial; urgency=medium9launchpad-buildd (161) xenial; urgency=medium
210
3 * Pass build URL to snapcraft using SNAPCRAFT_IMAGE_INFO.11 * Pass build URL to snapcraft using SNAPCRAFT_IMAGE_INFO.
412
=== modified file 'lpbuildd/debian.py'
--- lpbuildd/debian.py 2017-08-22 13:45:46 +0000
+++ lpbuildd/debian.py 2018-05-02 09:01:56 +0000
@@ -115,7 +115,7 @@
115 finally:115 finally:
116 chfile.close()116 chfile.close()
117117
118 def iterate(self, success):118 def iterate(self, success, quiet=False):
119 # When a Twisted ProcessControl class is killed by SIGTERM,119 # When a Twisted ProcessControl class is killed by SIGTERM,
120 # which we call 'build process aborted', 'None' is returned as120 # which we call 'build process aborted', 'None' is returned as
121 # exit_code.121 # exit_code.
@@ -123,8 +123,9 @@
123 # We may have been aborted in between subprocesses; pretend that123 # We may have been aborted in between subprocesses; pretend that
124 # we were terminated by a signal, which is close enough.124 # we were terminated by a signal, which is close enough.
125 success = 128 + signal.SIGKILL125 success = 128 + signal.SIGKILL
126 log.msg("Iterating with success flag %s against stage %s"126 if not quiet:
127 % (success, self._state))127 log.msg("Iterating with success flag %s against stage %s"
128 % (success, self._state))
128 func = getattr(self, "iterate_" + self._state, None)129 func = getattr(self, "iterate_" + self._state, None)
129 if func is None:130 if func is None:
130 raise ValueError("Unknown internal state " + self._state)131 raise ValueError("Unknown internal state " + self._state)
131132
=== modified file 'lpbuildd/slave.py'
--- lpbuildd/slave.py 2018-03-08 11:29:25 +0000
+++ lpbuildd/slave.py 2018-05-02 09:01:56 +0000
@@ -203,20 +203,27 @@
203203
204 def doCleanup(self):204 def doCleanup(self):
205 """Remove the build tree etc."""205 """Remove the build tree etc."""
206 self.runTargetSubProcess("remove-build")206 if not self.fast_cleanup:
207 self.runTargetSubProcess("remove-build")
207208
208 # Sanitize the URLs in the buildlog file if this is a build209 # Sanitize the URLs in the buildlog file if this is a build
209 # in a private archive.210 # in a private archive.
210 if self.needs_sanitized_logs:211 if self.needs_sanitized_logs:
211 self._slave.sanitizeBuildlog(self._slave.cachePath("buildlog"))212 self._slave.sanitizeBuildlog(self._slave.cachePath("buildlog"))
212213
214 if self.fast_cleanup:
215 self.iterate(0, quiet=True)
216
213 def doMounting(self):217 def doMounting(self):
214 """Mount things in the chroot, e.g. proc."""218 """Mount things in the chroot, e.g. proc."""
215 self.runTargetSubProcess("mount-chroot")219 self.runTargetSubProcess("mount-chroot")
216220
217 def doUnmounting(self):221 def doUnmounting(self):
218 """Unmount the chroot."""222 """Unmount the chroot."""
219 self.runTargetSubProcess("umount-chroot")223 if self.fast_cleanup:
224 self.iterate(0, quiet=True)
225 else:
226 self.runTargetSubProcess("umount-chroot")
220227
221 def initiate(self, files, chroot, extra_args):228 def initiate(self, files, chroot, extra_args):
222 """Initiate a build given the input files.229 """Initiate a build given the input files.
@@ -237,6 +244,7 @@
237244
238 self.series = extra_args['series']245 self.series = extra_args['series']
239 self.arch_tag = extra_args.get('arch_tag', self._slave.getArch())246 self.arch_tag = extra_args.get('arch_tag', self._slave.getArch())
247 self.fast_cleanup = extra_args.get('fast_cleanup', False)
240248
241 # Check whether this is a build in a private archive and249 # Check whether this is a build in a private archive and
242 # whether the URLs in the buildlog file should be sanitized250 # whether the URLs in the buildlog file should be sanitized
@@ -259,7 +267,7 @@
259 """267 """
260 return {}268 return {}
261269
262 def iterate(self, success):270 def iterate(self, success, quiet=False):
263 """Perform an iteration of the slave.271 """Perform an iteration of the slave.
264272
265 The BuildManager tends to work by invoking several273 The BuildManager tends to work by invoking several
266274
=== modified file 'lpbuildd/tests/test_debian.py'
--- lpbuildd/tests/test_debian.py 2017-08-22 14:46:10 +0000
+++ lpbuildd/tests/test_debian.py 2018-05-02 09:01:56 +0000
@@ -328,3 +328,96 @@
328 self.assertFalse(self.slave.wasCalled('depFail'))328 self.assertFalse(self.slave.wasCalled('depFail'))
329 self.assertTrue(self.slave.wasCalled('buildOK'))329 self.assertTrue(self.slave.wasCalled('buildOK'))
330 self.assertTrue(self.slave.wasCalled('buildComplete'))330 self.assertTrue(self.slave.wasCalled('buildComplete'))
331
332 def test_iterate_fast_cleanup(self):
333 # The build manager can be told that it doesn't need to do the final
334 # cleanup steps, because the VM is about to be torn down anyway. It
335 # iterates such a build from start to finish, but without calling
336 # umount-chroot or remove-build.
337 extra_args = {
338 'arch_tag': 'amd64',
339 'archives': [
340 'deb http://ppa.launchpad.dev/owner/name/ubuntu xenial main',
341 ],
342 'fast_cleanup': True,
343 'series': 'xenial',
344 }
345 self.startBuild(extra_args)
346
347 self.buildmanager.iterate(0)
348 self.assertEqual(DebianBuildState.UNPACK, self.getState())
349 self.assertEqual(
350 (['sharepath/slavebin/in-target', 'in-target',
351 'unpack-chroot',
352 '--backend=chroot', '--series=xenial', '--arch=amd64',
353 self.buildid,
354 os.path.join(self.buildmanager._cachepath, 'chroot.tar.gz')],
355 None),
356 self.buildmanager.commands[-1])
357 self.assertEqual(
358 self.buildmanager.iterate, self.buildmanager.iterators[-1])
359
360 self.buildmanager.iterate(0)
361 self.assertEqual(DebianBuildState.MOUNT, self.getState())
362 self.assertEqual(
363 (['sharepath/slavebin/in-target', 'in-target',
364 'mount-chroot',
365 '--backend=chroot', '--series=xenial', '--arch=amd64',
366 self.buildid],
367 None),
368 self.buildmanager.commands[-1])
369 self.assertEqual(
370 self.buildmanager.iterate, self.buildmanager.iterators[-1])
371
372 self.buildmanager.iterate(0)
373 self.assertEqual(DebianBuildState.SOURCES, self.getState())
374 self.assertEqual(
375 (['sharepath/slavebin/in-target', 'in-target',
376 'override-sources-list',
377 '--backend=chroot', '--series=xenial', '--arch=amd64',
378 self.buildid,
379 'deb http://ppa.launchpad.dev/owner/name/ubuntu xenial main'],
380 None),
381 self.buildmanager.commands[-1])
382 self.assertEqual(
383 self.buildmanager.iterate, self.buildmanager.iterators[-1])
384
385 self.buildmanager.iterate(0)
386 self.assertEqual(DebianBuildState.UPDATE, self.getState())
387 self.assertEqual(
388 (['sharepath/slavebin/in-target', 'in-target',
389 'update-debian-chroot',
390 '--backend=chroot', '--series=xenial', '--arch=amd64',
391 self.buildid],
392 None),
393 self.buildmanager.commands[-1])
394 self.assertEqual(
395 self.buildmanager.iterate, self.buildmanager.iterators[-1])
396
397 self.buildmanager.iterate(0)
398 self.assertEqual(MockBuildState.MAIN, self.getState())
399 self.assertEqual(
400 (['/bin/true', 'true'], None), self.buildmanager.commands[-1])
401 self.assertEqual(
402 self.buildmanager.iterate, self.buildmanager.iterators[-1])
403
404 self.buildmanager.iterate(0)
405 self.assertEqual(MockBuildState.MAIN, self.getState())
406 self.assertEqual(
407 (['sharepath/slavebin/in-target', 'in-target',
408 'scan-for-processes',
409 '--backend=chroot', '--series=xenial', '--arch=amd64',
410 self.buildid],
411 None),
412 self.buildmanager.commands[-1])
413 self.assertNotEqual(
414 self.buildmanager.iterate, self.buildmanager.iterators[-1])
415
416 self.buildmanager.iterateReap(self.getState(), 0)
417 self.assertFalse(self.slave.wasCalled('builderFail'))
418 self.assertFalse(self.slave.wasCalled('chrootFail'))
419 self.assertFalse(self.slave.wasCalled('buildFail'))
420 self.assertFalse(self.slave.wasCalled('depFail'))
421 self.assertTrue(self.slave.wasCalled('buildOK'))
422 self.assertTrue(self.slave.wasCalled('buildComplete'))
423

Subscribers

People subscribed via source and target branches

to all changes: