Merge "Kubernetes context adoption when run in CI"
[yardstick.git] / yardstick / common / constants.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
10 import os
11 from functools import reduce
12
13 import pkg_resources
14
15 from yardstick.common.utils import parse_yaml
16
17 dirname = os.path.dirname
18 abspath = os.path.abspath
19 join = os.path.join
20 sep = os.path.sep
21
22 CONF = {}
23
24
25 def get_param(key, default=''):
26
27     # we have to defer this to runtime so that we can mock os.environ.get in unittests
28     conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml')
29
30     # don't re-parse yaml for each lookup
31     if not CONF:
32         CONF.update(parse_yaml(conf_file))
33     try:
34         return reduce(lambda a, b: a[b], key.split('.'), CONF)
35     except KeyError:
36         if not default:
37             raise
38         return default
39
40
41 try:
42     SERVER_IP = get_param('api.server_ip')
43 except KeyError:
44     try:
45         from pyroute2 import IPDB
46     except ImportError:
47         SERVER_IP = '172.17.0.1'
48     else:
49         with IPDB() as ip:
50             try:
51                 SERVER_IP = ip.routes['default'].gateway
52             except KeyError:
53                 # during unittests ip.routes['default'] can be invalid
54                 SERVER_IP = '127.0.0.1'
55
56 if not SERVER_IP:
57     SERVER_IP = '127.0.0.1'
58
59
60 # dir
61 CONF_DIR = get_param('dir.conf', '/etc/yardstick')
62 IMAGE_DIR = get_param('dir.images', '/home/opnfv/images/')
63 REPOS_DIR = get_param('dir.repos', '/home/opnfv/repos/yardstick')
64 RELENG_DIR = get_param('dir.releng', '/home/opnfv/repos/releng')
65 LOG_DIR = get_param('dir.log', '/tmp/yardstick/')
66 YARDSTICK_ROOT_PATH = dirname(
67     dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep
68 TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/yardstick/')
69 CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/yardstick/')
70 ANSIBLE_DIR = join(REPOS_DIR, 'ansible')
71 SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
72 TESTCASE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_cases/')
73 TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
74 DOCS_DIR = join(REPOS_DIR, 'docs/testing/user/userguide/')
75 OPENSTACK_CONF_DIR = '/etc/openstack'
76
77 # file
78 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
79 ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
80 CONF_FILE = join(CONF_DIR, 'yardstick.conf')
81 POD_FILE = join(CONF_DIR, 'pod.yaml')
82 CLOUDS_CONF = join(OPENSTACK_CONF_DIR, 'clouds.yml')
83 K8S_CONF_FILE = join(CONF_DIR, 'admin.conf')
84 CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')
85 FETCH_SCRIPT = get_param('file.fetch_script', 'utils/fetch_os_creds.sh')
86 FETCH_SCRIPT = join(RELENG_DIR, FETCH_SCRIPT)
87 CLEAN_IMAGES_SCRIPT = get_param('file.clean_image_script',
88                                 'tests/ci/clean_images.sh')
89 CLEAN_IMAGES_SCRIPT = join(REPOS_DIR, CLEAN_IMAGES_SCRIPT)
90 LOAD_IMAGES_SCRIPT = get_param('file.load_image_script',
91                                'tests/ci/load_images.sh')
92 LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT)
93 DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out')
94 DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm')
95 REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html')
96
97 # influxDB
98 INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)
99 INFLUXDB_PORT = get_param('influxdb.port', 8086)
100 INFLUXDB_USER = get_param('influxdb.username', 'root')
101 INFLUXDB_PASS = get_param('influxdb.password', 'root')
102 INFLUXDB_DB_NAME = get_param('influxdb.db_name', 'yardstick')
103 INFLUXDB_IMAGE = get_param('influxdb.image', 'tutum/influxdb')
104 INFLUXDB_TAG = get_param('influxdb.tag', '0.13')
105 INFLUXDB_DASHBOARD_PORT = 8083
106
107 # grafana
108 GRAFANA_IP = get_param('grafana.ip', SERVER_IP)
109 GRAFANA_PORT = get_param('grafana.port', 3000)
110 GRAFANA_USER = get_param('grafana.username', 'admin')
111 GRAFANA_PASS = get_param('grafana.password', 'admin')
112 GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
113 GRAFANA_TAG = get_param('grafana.tag', '4.4.3')
114 GRAFANA_MAPPING_PORT = 1948
115
116 # api
117 API_PORT = 5000
118 DOCKER_URL = 'unix://var/run/docker.sock'
119 INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
120 SQLITE = 'sqlite:////tmp/yardstick.db'
121
122 API_SUCCESS = 1
123 API_ERROR = 2
124 TASK_NOT_DONE = 0
125 TASK_DONE = 1
126 TASK_FAILED = 2
127
128 BASE_URL = 'http://localhost:5000'
129 ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
130 ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
131
132 # general
133 TESTCASE_PRE = 'opnfv_yardstick_'
134 TESTSUITE_PRE = 'opnfv_'