Raise error on failed run_command.

Lost this somehow in refactoring, but right now failed commands are silent.
Raise an exception and print the error details.

Restore behaviour where we can print command output on success if desired.

Fix a couple tests that were actually failing due to missing rsync dest.
This commit is contained in:
Devan Goodwin 2014-05-09 11:41:19 -03:00
parent e3c4b269e8
commit 2a54ad3ce4
3 changed files with 13 additions and 2 deletions

View file

@ -202,10 +202,18 @@ def run_command(command, print_on_success=False):
"""
Run command.
If command fails, print status code and command output.
If print_on_success is True, print status and output even
when command succeeds.
"""
(status, output) = getstatusoutput(command)
if status > 0:
sys.stderr.write("\n########## ERROR ############\n")
sys.stderr.write("Error running command: %s\n" % command)
sys.stderr.write("Status code: %s\n" % status)
sys.stderr.write("Command output: %s\n" % output)
raise RunCommandException(command, status, output)
elif print_on_success:
print("Command: %s\n" % command)
print("Status code: %s\n" % status)
print("Command output: %s\n" % output)
return output

View file

@ -91,6 +91,7 @@ class FetchBuilderTests(TitoGitTestFixture):
def test_with_releaser(self):
yum_repo_dir = os.path.join(self.output_dir, 'yum')
run_command('mkdir -p %s' % yum_repo_dir)
self._setup_fetchbuilder_releaser(yum_repo_dir)
tito('release --debug yum-test --arg source=%s' %
self.source_filename)

View file

@ -25,6 +25,7 @@ from os.path import join
from functional.fixture import TitoGitTestFixture, tito
from tito.compat import *
from tito.common import run_command
PKG_NAME = "releaseme"
@ -63,6 +64,7 @@ class YumReleaserTests(TitoGitTestFixture):
def test_with_releaser(self):
yum_repo_dir = os.path.join(self.output_dir, 'yum')
run_command('mkdir -p %s' % yum_repo_dir)
self._setup_fetchbuilder_releaser(yum_repo_dir)
tito('release --debug yum-test')