common_util: Print tar's stderr if error occurs.
Sometimes a devserver will fail to stage some artifacts and the only
error message that is seen is that tar failed with some non-zero exit
status. This commit will redirect tar's stderr to stdout which will be
placed in the exception that it raises. This will be helpful to see
what exactly went wrong.
BUG=chromium:653362
BRANCH=None
TEST=python -b common_util_unittest.py
Change-Id: I2188da5a5a3de5c3afa6ee365dadb888abb44b80
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/399418
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
diff --git a/common_util_unittest.py b/common_util_unittest.py
index 9cc0165..09d2fc1 100755
--- a/common_util_unittest.py
+++ b/common_util_unittest.py
@@ -146,6 +146,19 @@
os.unlink(link_a)
os.unlink(link_base)
+ def testExtractTarballMissingFile(self):
+ """Verify that stderr from tar is printed if in encounters an error."""
+ tarball = 'a-tarball-which-does-not-exist.tar.gz'
+ dest = self._static_dir
+
+ try:
+ common_util.ExtractTarball(tarball, dest)
+ except common_util.CommonUtilError as e:
+ # Check to see that tar's error message is printed in the exception.
+ self.assertTrue('Cannot open: No such file or directory' in e.args[0],
+ ('tar\'s stderr is missing from the exception.\n%s' %
+ e.args[0]))
+
if __name__ == '__main__':
unittest.main()