summaryrefslogtreecommitdiff
path: root/morphlib/stagingarea.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-12-18 10:26:04 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-12-18 10:26:04 +0000
commitc57952ef44a0f1f161441970fcf2f27a39b0de7c (patch)
treeb4fee53259020cb4d3da21e352041fac3edf93f5 /morphlib/stagingarea.py
parent70858749d82afe841d06f6a96350168bc3ba51f7 (diff)
parent9449dbfe1bb1800dfb15de025b87e1846e25e74a (diff)
downloadmorph-c57952ef44a0f1f161441970fcf2f27a39b0de7c.tar.gz
Merge branch 'sam/improve-command-failure-errors'
Reviewed-By: Richard Ipsum <richard.ipsum@codethink.co.uk> Reviewed-By: Richard Maw <richard.maw@codethink.co.uk> Reviewed-By: Daniel Silverstone <daniel.silverstone@codethink.co.uk> Reviewed-By: Mike Smith <mike.smith@codethink.co.uk>
Diffstat (limited to 'morphlib/stagingarea.py')
-rw-r--r--morphlib/stagingarea.py50
1 files changed, 32 insertions, 18 deletions
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py
index b676d4db..e7783890 100644
--- a/morphlib/stagingarea.py
+++ b/morphlib/stagingarea.py
@@ -274,22 +274,38 @@ class StagingArea(object):
else:
binds = ()
+ container_config=dict(
+ cwd=kwargs.pop('cwd', '/'),
+ root=chroot_dir,
+ mounts=self.to_mount,
+ binds=binds,
+ mount_proc=mount_proc,
+ writable_paths=do_not_mount_dirs)
+
cmdline = morphlib.util.containerised_cmdline(
- argv, cwd=kwargs.pop('cwd', '/'),
- root=chroot_dir, mounts=self.to_mount,
- binds=binds, mount_proc=mount_proc,
- writable_paths=do_not_mount_dirs)
- try:
- if kwargs.get('logfile') != None:
- logfile = kwargs.pop('logfile')
- teecmd = ['tee', '-a', logfile]
- return self._app.runcmd(cmdline, teecmd, **kwargs)
- else:
- return self._app.runcmd(cmdline, **kwargs)
- except cliapp.AppException as e:
- raise cliapp.AppException('In staging area %s: running '
- 'command \'%s\' failed.' %
- (self.dirname, ' '.join(argv)))
+ argv, **container_config)
+
+ if kwargs.get('logfile') != None:
+ logfile = kwargs.pop('logfile')
+ teecmd = ['tee', '-a', logfile]
+ exit, out, err = self._app.runcmd_unchecked(
+ cmdline, teecmd, **kwargs)
+ else:
+ exit, out, err = self._app.runcmd_unchecked(cmdline, **kwargs)
+
+ if exit == 0:
+ return out
+ else:
+ logging.debug('Command returned code %i', exit)
+ msg = morphlib.util.error_message_for_containerised_commandline(
+ argv, err, container_config)
+ raise cliapp.AppException(
+ 'In staging area %s: %s' % (self._failed_location(), msg))
+
+ def _failed_location(self): # pragma: no cover
+ '''Path this staging area will be moved to if an error occurs.'''
+ return os.path.join(self._app.settings['tempdir'], 'failed',
+ os.path.basename(self.dirname))
def abort(self): # pragma: no cover
'''Handle what to do with a staging area in the case of failure.
@@ -298,9 +314,7 @@ class StagingArea(object):
# 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))
+ dest_dir = self._failed_location()
os.rename(self.dirname, dest_dir)
self.dirname = dest_dir