Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #172 from neiljerram/log-error-output
Browse files Browse the repository at this point in the history
log_and_run: log output when command fails
  • Loading branch information
lwr20 authored Dec 2, 2016
2 parents 4b452cd + aef7f17 commit 394c8b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions calico_test/tests/st/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@ def get_ip(v6=False):


def log_and_run(command):
try:
logger.info(command)
results = check_output(command, shell=True, stderr=STDOUT).rstrip()

def log_output(results):
lines = results.split("\n")
for line in lines:
logger.info(" # %s", line)

try:
logger.info(command)
results = check_output(command, shell=True, stderr=STDOUT).rstrip()
log_output(results)
return results
except CalledProcessError as e:
# Wrap the original exception with one that gives a better error
# message (including command output).
logger.info(" # Return code: %s", e.returncode)
log_output(e.output.rstrip())
raise CommandExecError(e)


Expand Down

0 comments on commit 394c8b1

Please sign in to comment.