summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/common/config.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-23 15:35:38 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2017-03-23 15:35:38 +0800
commit54e89dde8714fb6080d17d1373a48e36ce60eff3 (patch)
tree66d222dfd38d105b8427921aa45974ab97ca22e3 /testapi/opnfv_testapi/common/config.py
parenta6460e1b2ebcdbb6f823f26b03e1210c8212497c (diff)
start TestAPI in venv with no config-file
in virtual env mode, config.ini is configured in .venv/etc/opnfv_testapi, in this case when we start it the configuration file needs to be specified, by changing the _default_config, the -config-file is no longer needed when starting TestAPI in venv mode. Change-Id: I0217cfefe578bbc3325bb7577ed268dc21cde4ea Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/opnfv_testapi/common/config.py')
-rw-r--r--testapi/opnfv_testapi/common/config.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/testapi/opnfv_testapi/common/config.py b/testapi/opnfv_testapi/common/config.py
index 105d4fa..362fca6 100644
--- a/testapi/opnfv_testapi/common/config.py
+++ b/testapi/opnfv_testapi/common/config.py
@@ -30,7 +30,7 @@ class APIConfig(object):
"""
def __init__(self):
- self._default_config_location = "/etc/opnfv_testapi/config.ini"
+ self._set_default_config()
self.mongo_url = None
self.mongo_dbname = None
self.api_port = None
@@ -39,6 +39,11 @@ class APIConfig(object):
self._parser = None
self.swagger_base_url = None
+ def _set_default_config(self):
+ venv = os.getenv('VIRTUAL_ENV')
+ self._default_config = os.path.join('/' if not venv else venv,
+ 'etc/opnfv_testapi/config.ini')
+
def _get_parameter(self, section, param):
try:
return self._parser.get(section, param)
@@ -66,7 +71,7 @@ class APIConfig(object):
obj = APIConfig()
if config_location is None:
- config_location = obj._default_config_location
+ config_location = obj._default_config
if not os.path.exists(config_location):
raise ParseError("%s not found" % config_location)