From eb0151059dcc1efff797eeeb9f0e77e344426ef6 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Wed, 8 Feb 2017 17:48:47 +0100 Subject: Fix source_credentials in openstack_utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It fixes issues raised when an env var contains '=' (e.g. LS_COLORS). It now exports the vars listed in rc_file without creating a new process. Change-Id: I6e6a4e3ab9c45afe4d40015831acb283acbe564c Signed-off-by: Cédric Ollivier --- functest/utils/openstack_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'functest/utils') diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py index 64f18504..a0d78ae9 100755 --- a/functest/utils/openstack_utils.py +++ b/functest/utils/openstack_utils.py @@ -10,7 +10,7 @@ import os import os.path -import subprocess +import re import sys import time @@ -112,12 +112,12 @@ def get_credentials(other_creds={}): def source_credentials(rc_file): - pipe = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE, - shell=True) - output = pipe.communicate()[0] - env = dict((line.split("=", 1) for line in output.splitlines())) - os.environ.update(env) - return env + with open(rc_file, "r") as f: + for line in f: + var = line.rstrip('"\n').replace('export ', '').split("=") + key = re.sub(r'^ *| *$', '', var[0]) + value = re.sub(r'^[" ]*|[ "]*$', '', "".join(var[1:])) + os.environ[key] = value def get_credentials_for_rally(): -- cgit 1.2.3-korg