From 670362c0c12b3595591a824f633f8f3182554be9 Mon Sep 17 00:00:00 2001 From: Eddie Arrage Date: Thu, 8 Feb 2018 15:10:28 -0800 Subject: Add ablity to config EXTERNAL_NETWORK in env_config.sh - EXTERNAL_NETWORK env variable can be explicitly set - If set, the value will be used in Yardstack configuration - Otherwise, previous method of using output from 'openstack network list' will still be employed Change-Id: I9d8b4a69ff3f5093c034823cc95e92e151bfade6 Signed-off-by: Eddie Arrage --- dovetail/utils/dovetail_utils.py | 51 ++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index 87efa507..5c335679 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -133,30 +133,35 @@ def check_https_enabled(logger=None): def get_ext_net_name(env_file, logger=None): - https_enabled = check_https_enabled(logger) - insecure_option = '' - insecure = os.getenv('OS_INSECURE',) - if https_enabled: - logger.info("https enabled...") - if insecure: - if insecure.lower() == "true": - insecure_option = ' --insecure ' - else: - logger.warn("Env variable OS_INSECURE is {}, if https + no " - "credential used, should be set as True." - .format(insecure)) - - cmd_check = "openstack %s network list" % insecure_option - ret, msg = exec_cmd(cmd_check, logger) - if ret: - logger.error("The credentials info in {} is invalid.".format(env_file)) + ext_net = os.getenv('EXTERNAL_NETWORK') + if ext_net: + return ext_net + else: + https_enabled = check_https_enabled(logger) + insecure_option = '' + insecure = os.getenv('OS_INSECURE',) + if https_enabled: + logger.info("https enabled...") + if insecure: + if insecure.lower() == "true": + insecure_option = ' --insecure ' + else: + logger.warn("Env variable OS_INSECURE is {}, if https + " + "no credential used, should be set as True." + .format(insecure)) + + cmd_check = "openstack %s network list" % insecure_option + ret, msg = exec_cmd(cmd_check, logger) + if ret: + logger.error("The credentials info in {} is invalid." + .format(env_file)) + return None + cmd = "openstack %s network list --long | grep 'External' | head -1 | \ + awk '{print $4}'" % insecure_option + ret, msg = exec_cmd(cmd, logger) + if not ret: + return msg return None - cmd = "openstack %s network list --long | grep 'External' | head -1 | \ - awk '{print $4}'" % insecure_option - ret, msg = exec_cmd(cmd, logger) - if not ret: - return msg - return None def store_db_results(db_url, build_tag, testcase, dest_file, logger): -- cgit 1.2.3-korg