diff options
author | 2016-05-05 14:36:03 +0200 | |
---|---|---|
committer | 2016-05-05 14:36:03 +0200 | |
commit | e8b9ccdeb1d12e9958baf307c79a9a6cc180a6d5 (patch) | |
tree | db362a9acc5d84cc077407148282baa6383962d9 | |
parent | 577356cf5d86c9476de496a5dda98ef2b4e5e2c5 (diff) |
Don't exit on error when destroying rally deployment
Also, some improvements in execute_command function
Change-Id: I8271d55202b8859701275d5f7322a7bd4894e475
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
-rw-r--r-- | ci/prepare_env.py | 34 | ||||
-rw-r--r-- | utils/functest_utils.py | 41 |
2 files changed, 45 insertions, 30 deletions
diff --git a/ci/prepare_env.py b/ci/prepare_env.py index bd6c9864..a861fed8 100644 --- a/ci/prepare_env.py +++ b/ci/prepare_env.py @@ -203,7 +203,7 @@ def verify_deployment(): if "ERROR" in line: logger.error(line) sys.exit("Problem while running 'check_os.sh'.") - logger.debug(line) + logger.info(line) def install_rally(): @@ -211,34 +211,34 @@ def install_rally(): logger.info("Creating Rally environment...") cmd = "rally deployment destroy opnfv-rally" - ft_utils.execute_command(cmd, logger=None, exit_on_error=False) + ft_utils.execute_command(cmd, logger=logger, exit_on_error=False, + error_msg=("Deployment %s does not exist." + % DEPLOYMENT_MAME), verbose=False) cmd = "rally deployment create --fromenv --name=" + DEPLOYMENT_MAME - if not ft_utils.execute_command(cmd, logger): - logger.error("Problem while creating Rally deployment.") - sys.exit(cmd) + ft_utils.execute_command(cmd, logger, + error_msg="Problem creating Rally deployment") logger.info("Installing tempest from existing repo...") cmd = ("rally verify install --source " + TEMPEST_REPO_DIR + " --system-wide") - if not ft_utils.execute_command(cmd, logger): - logger.error("Problem while installing Tempest.") - sys.exit(cmd) + ft_utils.execute_command(cmd, logger, + error_msg="Problem installing Tempest.") cmd = "rally deployment check" - if not ft_utils.execute_command(cmd, logger): - logger.error("OpenStack not responding or faulty Rally deployment.") - sys.exit(cmd) + ft_utils.execute_command(cmd, logger, + error_msg=("OpenStack not responding or " + "faulty Rally deployment.")) cmd = "rally show images" - if not ft_utils.execute_command(cmd, logger): - logger.error("Problem while listing OpenStack images.") - sys.exit(cmd) + ft_utils.execute_command(cmd, logger, + error_msg=("Problem while listing " + "OpenStack images.")) cmd = "rally show flavors" - if not ft_utils.execute_command(cmd, logger): - logger.error("Problem while showing OpenStack flavors.") - sys.exit(cmd) + ft_utils.execute_command(cmd, logger, + error_msg=("Problem while showing " + "OpenStack flavors.")) def generate_os_defaults(): diff --git a/utils/functest_utils.py b/utils/functest_utils.py index a69174b9..41925fc4 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) |