From 9f8f5625182cf8e3dbd4c10b865b179ab8b4fe87 Mon Sep 17 00:00:00 2001 From: Rob Hirschfeld Date: Fri, 4 Apr 2014 00:08:51 -0500 Subject: [PATCH] Add ability to build basic configuration from environment variables if they are passed. For now, just using the most basic variables. This could be expanded later but this should be sufficient for initial testing. The expected env variables are included in the attached doc. This configuration exposes assumptions in the rest of the file where more config data is expected than should be required. The goal of this patch is to ADD ENV CONFIG not to correct how the config data is consumed in the file. Change-Id: I849ec113c00b46c7bb40d748e1d88a5d70f03dc7 --- refstack/tools/execute_test.py | 43 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/refstack/tools/execute_test.py b/refstack/tools/execute_test.py index 137c51b2..66aae504 100755 --- a/refstack/tools/execute_test.py +++ b/refstack/tools/execute_test.py @@ -96,17 +96,40 @@ class Test: def get_mini_config(self): '''Return a mini config in JSON string.''' - if self.app_server_address and self.test_id: - url = "http://%s/get-miniconf?test_id=%s" % \ - (self.app_server_address, self.test_id) - try: - req = urllib2.urlopen(url=url, timeout=10) - return req.readlines()[0] - except: - self.logger.critical('Failed to get mini config from %s' % url) - raise + # create config from environment variables if set + url = os.environ.get("OS_AUTH_URL") + if url: + user = os.environ.get("OS_USERNAME") + self.logger.info('Using Config ENV variables for %s@%s' + % (url, user)) + # for now, very limited configuration. refactor as we add vars + env_config = {"identity": + {"uri": url, + "username": user, + "password": os.environ.get("OS_PASSWORD"), + "tenant_name": os.environ.get("OS_TENANT_NAME"), + "region": os.environ.get("OS_REGION_NAME")}, + "compute": + {"image_ref": os.environ.get("TEMPEST_IMAGE_REF", + "cirros")}} + json_config = json.dumps(env_config, separators=(',', ':')) + self.logger.debug("ENV config: %s" % (json_config)) + return json_config + # otherwise get them from the app server else: - return json.dumps(dict()) + if self.app_server_address and self.test_id: + url = "http://%s/get-miniconf?test_id=%s" % \ + (self.app_server_address, self.test_id) + try: + req = urllib2.urlopen(url=url, timeout=10) + self.logger.info('Using App Server Config from %s' % (url)) + return req.readlines()[0] + except: + self.logger.critical('Failed to get mini config from %s' + % url) + raise + else: + return json.dumps(dict()) def get_test_cases(self): '''Return list of tempest testcases in JSON string.