X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fcommon%2Fconfig.py;h=362fca6408956584cf7bf76929e49cde8a7e341f;hb=87ceba647aa252717ebede6085a89df350f32031;hp=45e134fc17a05c2f85ae738886982332e24496d2;hpb=c9663a366bab59d56f938dbfb9d8eb0dffafebfc;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/common/config.py b/utils/test/testapi/opnfv_testapi/common/config.py index 45e134fc1..362fca640 100644 --- a/utils/test/testapi/opnfv_testapi/common/config.py +++ b/utils/test/testapi/opnfv_testapi/common/config.py @@ -23,14 +23,14 @@ class ParseError(Exception): return 'error parsing config file : %s' % self.msg -class APIConfig: +class APIConfig(object): """ The purpose of this class is to load values correctly from the config file. Each key is declared as an attribute in __init__() and linked in parse() """ 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: 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: 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)