https + no credential support 03/35903/5
authorMatthewLi <matthew.lijun@huawei.com>
Thu, 8 Jun 2017 01:21:48 +0000 (21:21 -0400)
committerMatthewLi <matthew.lijun@huawei.com>
Fri, 9 Jun 2017 09:19:02 +0000 (05:19 -0400)
JIRA: DOVETAIL-440

Change-Id: I2bb430de040127dea493e8bb5423ad8204f799e2
Signed-off-by: MatthewLi <matthew.lijun@huawei.com>
dovetail/utils/dovetail_utils.py

index e6a775f..ae96940 100644 (file)
@@ -111,21 +111,29 @@ def source_env(env_file):
     with open(env_file, 'r') as f:
         lines = f.readlines()
     for line in lines:
-        for match in re.findall(r"export (.*)=(.*)", line):
-            match = (match[0].strip('\"'), match[1].strip('\"'))
-            match = (match[0].strip('\''), match[1].strip('\''))
-            os.environ.update({match[0]: match[1]})
+        if line.lstrip().startswith('export'):
+            for match in re.findall(r"export (.*)=(.*)", line):
+                match = (match[0].strip('\"'), match[1].strip('\"'))
+                match = (match[0].strip('\''), match[1].strip('\''))
+                os.environ.update({match[0]: match[1]})
 
 
 def get_ext_net_name(env_file, logger=None):
-    source_env(env_file)
-    cmd_check = "openstack network list"
+    insecure_option = ''
+    insecure = os.getenv('OS_INSECURE',)
+    if insecure == "true":
+        insecure_option = ' --insecure '
+    else:
+        print "Warn: env variable OS_INSECUE is %s, if https+no credential \
+               used, it should be set as true" % insecure
+
+    cmd_check = "openstack %s network list" % insecure_option
     ret, msg = exec_cmd(cmd_check, logger)
     if ret:
         logger.error("The credentials info in %s is invalid." % env_file)
         return None
-    cmd = "openstack network list --long | grep 'External' | head -1 | \
-           awk '{print $4}'"
+    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