summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Yu <Gabriel.yuyang@huawei.com>2018-01-16 16:49:49 +0800
committerYu Yang (Gabriel) <Gabriel.yuyang@huawei.com>2018-03-13 15:06:13 +0000
commit5df28e11b200349de3af2acf735ff0fad20283c2 (patch)
tree53334d7174c90317221e804e2ab483301c253989
parentd481acd8c2d994d54b24eb665854a02f29d1d224 (diff)
bug-fix: support insecure option for quota setting
JIRA: BOTTLENECK-221 Quota setting has openstack cmd executed by bash not supporting insecure option for https Change-Id: I223080b67af9aa1677e2e39daaf727f3a6c0ea97 Signed-off-by: Yang Yu <Gabriel.yuyang@huawei.com> (cherry picked from commit c9dc6c5ff980c32f82b0533e5a25eabebfbd0c6a)
-rw-r--r--utils/env_prepare/quota_prepare.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/utils/env_prepare/quota_prepare.py b/utils/env_prepare/quota_prepare.py
index 267e70ab..8dcdf3d6 100644
--- a/utils/env_prepare/quota_prepare.py
+++ b/utils/env_prepare/quota_prepare.py
@@ -42,14 +42,37 @@ nova_quota = {"ram": -1,
"injected_file_path_bytes": -1}
+def check_https_enabled():
+ LOG.debug("Check if https is enabled in OpenStack")
+ os_auth_url = os.getenv('OS_AUTH_URL')
+ if os_auth_url.startswith('https'):
+ LOG.debug("https is enabled")
+ return True
+ LOG.debug("https is not enabled")
+ return False
+
+
def quota_env_prepare():
+ https_enabled = check_https_enabled()
+ insecure_option = ''
+ insecure = os.getenv('OS_INSECURE',)
+ if https_enabled:
+ LOG.info("https is enabled")
+ if insecure:
+ if insecure.lower() == "true":
+ insecure_option = ' --insecure '
+ else:
+ LOG.warn("Env variable OS_INSECURE is {}: if https + no "
+ "credential used, it should be set as True."
+ .format(insecure))
+
tenant_name = os.getenv("OS_TENANT_NAME")
- cmd = ("openstack project list | grep " +
+ cmd = ("openstack {} project list | grep ".format(insecure_option) +
tenant_name +
" | awk '{print $2}'")
result = commands.getstatusoutput(cmd)
- if result[0] == 0:
+ if result[0] == 0 and 'exception' not in result[1]:
LOG.info("Get %s project id is %s" % (tenant_name, result[1]))
else:
LOG.error("can't get openstack project id")