aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-07-27 01:42:51 +0000
committerLinda Wang <wangwulin@huawei.com>2017-07-27 02:35:20 +0000
commit1943d0b5aa9dde34d700b232dc9b8c53be80f197 (patch)
tree960efa22fd0091d8d3d56f5277c2465a5096080b
parentcb328f47bb104f0a4046674df22401ccc1f71b5b (diff)
Omit space line in openrc file
For alpine testing in compass OSA, sourcing openrc failed due to space lines included. Change-Id: I23166090a2fa7c2ce0aa03be581231cbb3cea34a Signed-off-by: Linda Wang <wangwulin@huawei.com>
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py2
-rw-r--r--functest/utils/openstack_utils.py10
2 files changed, 6 insertions, 6 deletions
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 828fb3d4..cabd18e5 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -390,8 +390,6 @@ class OSUtilsTesting(unittest.TestCase):
self._test_source_credentials('export OS_TENANT_NAME =admin')
self._test_source_credentials('export OS_TENANT_NAME = admin')
self._test_source_credentials('export OS_TENANT_NAME = "admin"')
- self._test_source_credentials('OS_TENANT_NAME', value='')
- self._test_source_credentials('export OS_TENANT_NAME', value='')
# This test will fail as soon as rc_file is fixed
self._test_source_credentials(
'export "\'OS_TENANT_NAME\'" = "\'admin\'"')
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 4f8d6c35..1bdfa253 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -117,13 +117,15 @@ def get_credentials(other_creds={}):
def source_credentials(rc_file):
with open(rc_file, "r") as f:
for line in f:
- var = line.rstrip('"\n').replace('export ', '').split("=")
+ var = (line.rstrip('"\n').replace('export ', '').split("=")
+ if re.search(r'(.*)=(.*)', line) else None)
# The two next lines should be modified as soon as rc_file
# conforms with common rules. Be aware that it could induce
# issues if value starts with '
- key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
- value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
- os.environ[key] = value
+ if var:
+ key = re.sub(r'^["\' ]*|[ \'"]*$', '', var[0])
+ value = re.sub(r'^["\' ]*|[ \'"]*$', '', "".join(var[1:]))
+ os.environ[key] = value
def get_credentials_for_rally():