X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2Fconstants.py;h=fe394fd4d0b126b9a5baf17ade35efe67c2c0495;hb=349366a285555f4e874ef7a827c9dbc62988a4ab;hp=8e8114fbb096ae4f1a00e835943cf32440ea494a;hpb=7786deb79662368c80386e6eaee4e9bfe12fcd2f;p=yardstick.git diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py index 8e8114fbb..fe394fd4d 100644 --- a/yardstick/common/constants.py +++ b/yardstick/common/constants.py @@ -8,15 +8,36 @@ ############################################################################## from __future__ import absolute_import import os +from functools import reduce -from yardstick.common.utils import get_param +import pkg_resources +from yardstick.common.utils import parse_yaml dirname = os.path.dirname abspath = os.path.abspath join = os.path.join sep = os.path.sep +CONF = {} + + +def get_param(key, default=''): + + # we have to defer this to runtime so that we can mock os.environ.get in unittests + conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml') + + # don't re-parse yaml for each lookup + if not CONF: + CONF.update(parse_yaml(conf_file)) + try: + return reduce(lambda a, b: a[b], key.split('.'), CONF) + except KeyError: + if not default: + raise + return default + + try: SERVER_IP = get_param('api.server_ip') except KeyError: @@ -41,7 +62,9 @@ CONF_DIR = get_param('dir.conf', '/etc/yardstick') REPOS_DIR = get_param('dir.repos', '/home/opnfv/repos/yardstick') RELENG_DIR = get_param('dir.releng', '/home/opnfv/repos/releng') LOG_DIR = get_param('dir.log', '/tmp/yardstick/') -YARDSTICK_ROOT_PATH = dirname(dirname(dirname(abspath(__file__)))) + sep +YARDSTICK_ROOT_PATH = dirname( + dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep +TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/yardstick/') CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/yardstick/') ANSIBLE_DIR = join(REPOS_DIR, 'ansible') SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples') @@ -68,6 +91,7 @@ LOAD_IMAGES_SCRIPT = get_param('file.load_image_script', LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT) DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out') DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm') +REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html') # influxDB INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)