summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/functest_utils.py41
1 files changed, 28 insertions, 13 deletions
diff --git a/utils/functest_utils.py b/utils/functest_utils.py
index a69174b9a..41925fc4a 100644
--- a/utils/functest_utils.py
+++ b/utils/functest_utils.py
@@ -196,24 +196,39 @@ def get_ci_envvars():
return ci_env_var
-def execute_command(cmd, logger=None, exit_on_error=True, info=False):
- if logger:
- logger.debug('Executing command : {}'.format(cmd))
- p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
- while p.poll() is None:
- line = p.stdout.readline().rstrip()
+def execute_command(cmd, logger=None,
+ exit_on_error=True,
+ info=False,
+ error_msg="",
+ verbose=True):
+ if not error_msg:
+ error_msg = ("The command '%s' failed." % cmd)
+ msg_exec = ("Executing command: '%s'" % cmd)
+ if verbose:
if logger:
if info:
- logger.info(line)
+ logger.info(msg_exec)
else:
- logger.debug(line)
+ logger.debug(msg_exec)
else:
- print line
+ print(msg_exec)
+ p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+ while p.poll() is None:
+ line = p.stdout.readline().rstrip()
+ if verbose:
+ if logger:
+ if info:
+ logger.info(line)
+ else:
+ logger.debug(line)
+ else:
+ print line
if p.returncode != 0:
- if logger:
- logger.error("Error when executing command %s" % cmd)
- else:
- print("Error when executing command %s" % cmd)
+ if verbose:
+ if logger:
+ logger.error(error_msg)
+ else:
+ print(error_msg)
if exit_on_error:
sys.exit(1)