From 5261ebca7a0d4e3dfc86b9ad8655c2587e7d0548 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Tue, 6 Aug 2013 14:53:26 +0000 Subject: stagingarea: move to failed on construction fail This uses the same logic as when a build fails, so it's been consolidated into `StagingArea.abort()`. You could argue that if a build fails before any commands are run, then there's nothing interesting to see, but it will be useful if the hardlink/tarball extract algorithm fails in some corner case. --- morphlib/buildcommand.py | 8 ++++++-- morphlib/builder2.py | 5 +---- morphlib/stagingarea.py | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'morphlib') diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index fe6e0721..32c740a4 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -274,8 +274,12 @@ class BuildCommand(object): use_chroot, extra_env=extra_env, extra_path=extra_path) - self.install_fillers(staging_area) - self.install_dependencies(staging_area, deps, artifact) + try: + self.install_fillers(staging_area) + self.install_dependencies(staging_area, deps, artifact) + except BaseException: + staging_area.abort() + raise else: staging_area = self.create_staging_area(build_env, False) diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 62fd5480..daf50b56 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -354,10 +354,7 @@ class ChunkBuilder(BuilderBase): for line in f: logging.error('OUTPUT FROM FAILED BUILD: %s' % line.rstrip('\n')) - src_dir = self.staging_area.dirname - dest_dir = os.path.join(self.app.settings['tempdir'], - 'failed', os.path.basename(src_dir)) - os.rename(src_dir, dest_dir) + self.staging_area.abort() raise self.staging_area.chroot_close() built_artifacts = self.assemble_chunk_artifacts(destdir) diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py index 9aa8021b..3d756df7 100644 --- a/morphlib/stagingarea.py +++ b/morphlib/stagingarea.py @@ -309,3 +309,17 @@ class StagingArea(object): (self.dirname, ' '.join(argv))) else: return self._app.runcmd(argv, **kwargs) + + def abort(self): # pragma: no cover + '''Handle what to do with a staging area in the case of failure. + This may either remove it or save it for later inspection. + ''' + # TODO: when we add the option to throw away failed builds, + # hook it up here + + + dest_dir = os.path.join(self._app.settings['tempdir'], + 'failed', os.path.basename(self.dirname)) + os.rename(self.dirname, dest_dir) + self.dirname = dest_dir + -- cgit v1.2.1