Add intermediate variables for attacker,monitor,result_checker
[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 import errno
12
13 from functools import reduce
14
15 import pkg_resources
16
17 # this module must only import other modules that do
18 # not require loggers to be created, so this cannot
19 # include yardstick.common.utils
20 from yardstick.common.yaml_loader import yaml_load
21
22 dirname = os.path.dirname
23 abspath = os.path.abspath
24 join = os.path.join
25 sep = os.path.sep
26
27 CONF = {}
28
29
30 def get_param(key, default=''):
31
32     # we have to defer this to runtime so that we can mock os.environ.get in unittests
33     conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml')
34
35     # don't re-parse yaml for each lookup
36     if not CONF:
37         # do not use yardstick.common.utils.parse_yaml
38         # since yardstick.common.utils creates a logger
39         # and so it cannot be imported before this code
40         try:
41             with open(conf_file) as f:
42                 value = yaml_load(f)
43         except IOError:
44             pass
45         except OSError as e:
46             if e.errno != errno.EEXIST:
47                 raise
48         else:
49             CONF.update(value)
50     try:
51         return reduce(lambda a, b: a[b], key.split('.'), CONF)
52     except KeyError:
53         if not default:
54             raise
55         return default
56
57
58 try:
59     SERVER_IP = get_param('api.server_ip')
60 except KeyError:
61     try:
62         from pyroute2 import IPDB
63     except ImportError:
64         SERVER_IP = '172.17.0.1'
65     else:
66         with IPDB() as ip:
67             try:
68                 SERVER_IP = ip.routes['default'].gateway
69             except KeyError:
70                 # during unittests ip.routes['default'] can be invalid
71                 SERVER_IP = '127.0.0.1'
72
73 if not SERVER_IP:
74     SERVER_IP = '127.0.0.1'
75
76
77 # dir
78 CONF_DIR = get_param('dir.conf', '/etc/yardstick')
79 IMAGE_DIR = get_param('dir.images', '/home/opnfv/images/')
80 REPOS_DIR = get_param('dir.repos', '/home/opnfv/repos/yardstick')
81 RELENG_DIR = get_param('dir.releng', '/home/opnfv/repos/releng')
82 LOG_DIR = get_param('dir.log', '/tmp/yardstick/')
83 YARDSTICK_ROOT_PATH = dirname(
84     dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep
85 TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/yardstick/')
86 CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/yardstick/')
87 ANSIBLE_DIR = join(REPOS_DIR, 'ansible')
88 SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
89 TESTCASE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_cases/')
90 TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
91 DOCS_DIR = join(REPOS_DIR, 'docs/testing/user/userguide/')
92 OPENSTACK_CONF_DIR = '/etc/openstack'
93
94 # file
95 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
96 ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
97 CONF_FILE = join(CONF_DIR, 'yardstick.conf')
98 POD_FILE = join(CONF_DIR, 'pod.yaml')
99 CLOUDS_CONF = join(OPENSTACK_CONF_DIR, 'clouds.yml')
100 K8S_CONF_FILE = join(CONF_DIR, 'admin.conf')
101 CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')
102 FETCH_SCRIPT = get_param('file.fetch_script', 'utils/fetch_os_creds.sh')
103 FETCH_SCRIPT = join(RELENG_DIR, FETCH_SCRIPT)
104 CLEAN_IMAGES_SCRIPT = get_param('file.clean_image_script',
105                                 'tests/ci/clean_images.sh')
106 CLEAN_IMAGES_SCRIPT = join(REPOS_DIR, CLEAN_IMAGES_SCRIPT)
107 LOAD_IMAGES_SCRIPT = get_param('file.load_image_script',
108                                'tests/ci/load_images.sh')
109 LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT)
110 DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out')
111 DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm')
112 REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html')
113
114 # influxDB
115 INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)
116 INFLUXDB_PORT = get_param('influxdb.port', 8086)
117 INFLUXDB_USER = get_param('influxdb.username', 'root')
118 INFLUXDB_PASS = get_param('influxdb.password', 'root')
119 INFLUXDB_DB_NAME = get_param('influxdb.db_name', 'yardstick')
120 INFLUXDB_IMAGE = get_param('influxdb.image', 'tutum/influxdb')
121 INFLUXDB_TAG = get_param('influxdb.tag', '0.13')
122 INFLUXDB_DASHBOARD_PORT = 8083
123
124 # grafana
125 GRAFANA_IP = get_param('grafana.ip', SERVER_IP)
126 GRAFANA_PORT = get_param('grafana.port', 3000)
127 GRAFANA_USER = get_param('grafana.username', 'admin')
128 GRAFANA_PASS = get_param('grafana.password', 'admin')
129 GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
130 GRAFANA_TAG = get_param('grafana.tag', '4.4.3')
131 GRAFANA_MAPPING_PORT = 1948
132
133 # api
134 API_PORT = 5000
135 DOCKER_URL = 'unix://var/run/docker.sock'
136 INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
137 SQLITE = 'sqlite:////tmp/yardstick.db'
138
139 API_SUCCESS = 1
140 API_ERROR = 2
141 TASK_NOT_DONE = 0
142 TASK_DONE = 1
143 TASK_FAILED = 2
144
145 BASE_URL = 'http://localhost:5000'
146 ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
147 ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
148
149 # general
150 TESTCASE_PRE = 'opnfv_yardstick_'
151 TESTSUITE_PRE = 'opnfv_'