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

Commit 394c8b1

Browse files
authored
Merge pull request #172 from neiljerram/log-error-output
log_and_run: log output when command fails
2 parents 4b452cd + aef7f17 commit 394c8b1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

calico_test/tests/st/utils/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,22 @@ def get_ip(v6=False):
6666

6767

6868
def log_and_run(command):
69-
try:
70-
logger.info(command)
71-
results = check_output(command, shell=True, stderr=STDOUT).rstrip()
69+
70+
def log_output(results):
7271
lines = results.split("\n")
7372
for line in lines:
7473
logger.info(" # %s", line)
74+
75+
try:
76+
logger.info(command)
77+
results = check_output(command, shell=True, stderr=STDOUT).rstrip()
78+
log_output(results)
7579
return results
7680
except CalledProcessError as e:
7781
# Wrap the original exception with one that gives a better error
7882
# message (including command output).
7983
logger.info(" # Return code: %s", e.returncode)
84+
log_output(e.output.rstrip())
8085
raise CommandExecError(e)
8186

8287

0 commit comments

Comments
 (0)