Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 616381029E for ; Fri, 19 Jul 2013 21:00:53 +0000 (UTC) Received: (qmail 88953 invoked by uid 500); 19 Jul 2013 21:00:53 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 88936 invoked by uid 500); 19 Jul 2013 21:00:53 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 88928 invoked by uid 99); 19 Jul 2013 21:00:53 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jul 2013 21:00:53 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id ECEBD8AF367; Fri, 19 Jul 2013 21:00:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: [#6448] Capture zip stderr and log on exception Date: Fri, 19 Jul 2013 21:00:52 +0000 (UTC) Updated Branches: refs/heads/master ec7edd86a -> 5cddfe0fd [#6448] Capture zip stderr and log on exception Signed-off-by: Tim Van Steenburgh Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5cddfe0f Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5cddfe0f Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5cddfe0f Branch: refs/heads/master Commit: 5cddfe0fd350f3aa93a1551bd952fb465d69d26c Parents: ec7edd8 Author: Tim Van Steenburgh Authored: Fri Jul 19 13:19:22 2013 +0000 Committer: Dave Brondsema Committed: Fri Jul 19 21:00:37 2013 +0000 ---------------------------------------------------------------------- Allura/allura/model/repository.py | 10 ++++-- Allura/allura/tests/unit/test_repo.py | 49 ++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5cddfe0f/Allura/allura/model/repository.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py index 3d893cc..a3d9a44 100644 --- a/Allura/allura/model/repository.py +++ b/Allura/allura/model/repository.py @@ -23,7 +23,7 @@ import mimetypes import logging import string import re -from subprocess import Popen +from subprocess import Popen, PIPE from difflib import SequenceMatcher from hashlib import sha1 from datetime import datetime @@ -741,7 +741,13 @@ def zipdir(source, zipfile, exclude=None): command = [zipbin, '-r', zipfile, source_fn] if exclude: command += ['-x', exclude] - Popen(command, cwd=working_dir).communicate() + p = Popen(command, cwd=working_dir, stdout=PIPE, stderr=PIPE) + stdout, stderr = p.communicate() + if p.returncode != 0: + raise Exception( + "Command: {0} returned non-zero exit code {1}\n" + "STDOUT: {2}\n" + "STDERR: {3}".format(command, p.returncode, stdout, stderr)) Mapper.compile_all() http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5cddfe0f/Allura/allura/tests/unit/test_repo.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py index 5fb6590..499f604 100644 --- a/Allura/allura/tests/unit/test_repo.py +++ b/Allura/allura/tests/unit/test_repo.py @@ -288,15 +288,40 @@ class TestCommit(unittest.TestCase): commit.get_tree.assert_called_with(create=True) -@patch('allura.model.repository.Popen') -@patch('allura.model.repository.tg') -def test_zipdir(tg, popen): - tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'} - src = '/fake/path/to/repo' - zipfile = '/fake/zip/file.tmp' - zipdir(src, zipfile) - popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo'], cwd='/fake/path/to') - popen.reset_mock() - src = '/fake/path/to/repo/' - zipdir(src, zipfile, exclude='file.txt') - popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo', '-x', 'file.txt'], cwd='/fake/path/to') +class TestZipDir(unittest.TestCase): + @patch('allura.model.repository.Popen') + @patch('allura.model.repository.tg') + def test_popen_called(self, tg, popen): + from subprocess import PIPE + popen.return_value.communicate.return_value = 1, 2 + popen.return_value.returncode = 0 + tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'} + src = '/fake/path/to/repo' + zipfile = '/fake/zip/file.tmp' + zipdir(src, zipfile) + popen.assert_called_once_with(['/bin/zip', '-r', zipfile, 'repo'], + cwd='/fake/path/to', stdout=PIPE, stderr=PIPE) + popen.reset_mock() + src = '/fake/path/to/repo/' + zipdir(src, zipfile, exclude='file.txt') + popen.assert_called_once_with( + ['/bin/zip', '-r', zipfile, 'repo', '-x', 'file.txt'], + cwd='/fake/path/to', stdout=PIPE, stderr=PIPE) + + @patch('allura.model.repository.Popen') + @patch('allura.model.repository.tg') + def test_exception_logged(self, tg, popen): + tg.config = {'scm.repos.tarball.zip_binary': '/bin/zip'} + popen.return_value.communicate.return_value = 1, 2 + popen.return_value.returncode = 1 + src = '/fake/path/to/repo' + zipfile = '/fake/zip/file.tmp' + with self.assertRaises(Exception) as cm: + zipdir(src, zipfile) + emsg = str(cm.exception) + self.assertTrue( + "Command: " + "['/bin/zip', '-r', '/fake/zip/file.tmp', 'repo'] " + "returned non-zero exit code 1" in emsg) + self.assertTrue("STDOUT: 1" in emsg) + self.assertTrue("STDERR: 2" in emsg)