X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Ftest%2Ftestapi%2Fopnfv_testapi%2Fcommon%2Fconfig.py;h=140e49283390b614f6214b1f0da476c3b4f0b626;hb=ca6539a8f8c7f608623cdd578d2d606322f06370;hp=46765ffd1f36b8f78cb7630f011b2621e4717a27;hpb=a1a745b4820ec46a2e707d77f6178cf9e97654f6;p=releng.git diff --git a/utils/test/testapi/opnfv_testapi/common/config.py b/utils/test/testapi/opnfv_testapi/common/config.py index 46765ffd1..140e49283 100644 --- a/utils/test/testapi/opnfv_testapi/common/config.py +++ b/utils/test/testapi/opnfv_testapi/common/config.py @@ -8,26 +8,25 @@ # feng.xiaowei@zte.com.cn remove prepare_put_request 5-30-2016 ############################################################################## import ConfigParser +import argparse import os +import sys class Config(object): - CONFIG = None def __init__(self): - self.file = self.CONFIG if self.CONFIG else self._default_config() + self.config_file = '/etc/opnfv_testapi/config.ini' + self._set_config_file() self._parse() - self.static_path = os.path.join( - os.path.dirname(os.path.normpath(__file__)), - os.pardir, - 'static') + self._parse_per_page() def _parse(self): - if not os.path.exists(self.file): - raise Exception("%s not found" % self.file) + if not os.path.exists(self.config_file): + raise Exception("%s not found" % self.config_file) config = ConfigParser.RawConfigParser() - config.read(self.file) + config.read(self.config_file) self._parse_section(config) def _parse_section(self, config): @@ -37,6 +36,10 @@ class Config(object): [setattr(self, '{}_{}'.format(section, k), self._parse_value(v)) for k, v in config.items(section)] + def _parse_per_page(self): + if not hasattr(self, 'api_results_per_page'): + self.api_results_per_page = 20 + @staticmethod def _parse_value(value): try: @@ -48,8 +51,13 @@ class Config(object): value = False return value - @staticmethod - def _default_config(): - is_venv = os.getenv('VIRTUAL_ENV') - return os.path.join('/' if not is_venv else is_venv, - 'etc/opnfv_testapi/config.ini') + def _set_config_file(self): + parser = argparse.ArgumentParser() + parser.add_argument("-c", "--config-file", dest='config_file', + help="Config file location", metavar="FILE") + args, _ = parser.parse_known_args(sys.argv) + if hasattr(args, 'config_file') and args.config_file: + self.config_file = args.config_file + + +CONF = Config()