Merge "Log VM OS version, Sample VNF branch/commit ID"
[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
10 import errno
11 import os
12 from functools import reduce
13
14 import pkg_resources
15
16 from yardstick.common.yaml_loader import yaml_load
17
18
19 dirname = os.path.dirname
20 abspath = os.path.abspath
21 join = os.path.join
22 sep = os.path.sep
23
24 CONF = {}
25
26
27 def get_param(key, default=''):
28
29     # we have to defer this to runtime so that we can mock os.environ.get in unittests
30     conf_file = os.environ.get('CONF_FILE', '/etc/yardstick/yardstick.yaml')
31
32     # don't re-parse yaml for each lookup
33     if not CONF:
34         # do not use yardstick.common.utils.parse_yaml
35         # since yardstick.common.utils creates a logger
36         # and so it cannot be imported before this code
37         try:
38             with open(conf_file) as f:
39                 value = yaml_load(f)
40         except (IOError, OSError) as e:
41             if e.errno != errno.ENOENT:
42                 raise
43         else:
44             CONF.update(value)
45     try:
46         return reduce(lambda a, b: a[b], key.split('.'), CONF)
47     except KeyError:
48         if not default:
49             raise
50         return default
51
52
53 try:
54     SERVER_IP = get_param('api.server_ip')
55 except KeyError:
56     try:
57         from pyroute2 import IPDB
58     except ImportError:
59         SERVER_IP = '172.17.0.1'
60     else:
61         with IPDB() as ip:
62             try:
63                 SERVER_IP = ip.routes['default'].gateway
64             except KeyError:
65                 # during unittests ip.routes['default'] can be invalid
66                 SERVER_IP = '127.0.0.1'
67
68 if not SERVER_IP:
69     SERVER_IP = '127.0.0.1'
70
71
72 # dir
73 CONF_DIR = get_param('dir.conf', '/etc/yardstick')
74 IMAGE_DIR = get_param('dir.images', '/home/opnfv/images/')
75 REPOS_DIR = get_param('dir.repos', '/home/opnfv/repos/yardstick')
76 RELENG_DIR = get_param('dir.releng', '/home/opnfv/repos/releng')
77 LOG_DIR = get_param('dir.log', '/tmp/yardstick/')
78 YARDSTICK_ROOT_PATH = dirname(
79     dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep
80 TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/yardstick/')
81 CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/yardstick/')
82 ANSIBLE_DIR = join(REPOS_DIR, 'ansible')
83 ANSIBLE_ROLES_PATH = join(REPOS_DIR, 'ansible/roles/')
84 SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
85 TESTCASE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_cases/')
86 TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
87 DOCS_DIR = join(REPOS_DIR, 'docs/testing/user/userguide/')
88 OPENSTACK_CONF_DIR = '/etc/openstack'
89
90 # file
91 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
92 ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
93 CONF_FILE = join(CONF_DIR, 'yardstick.conf')
94 POD_FILE = join(CONF_DIR, 'pod.yaml')
95 CLOUDS_CONF = join(OPENSTACK_CONF_DIR, 'clouds.yml')
96 K8S_CONF_FILE = join(CONF_DIR, 'admin.conf')
97 CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')
98 FETCH_SCRIPT = get_param('file.fetch_script', 'utils/fetch_os_creds.sh')
99 FETCH_SCRIPT = join(RELENG_DIR, FETCH_SCRIPT)
100 CLEAN_IMAGES_SCRIPT = get_param('file.clean_image_script',
101                                 'tests/ci/clean_images.sh')
102 CLEAN_IMAGES_SCRIPT = join(REPOS_DIR, CLEAN_IMAGES_SCRIPT)
103 LOAD_IMAGES_SCRIPT = get_param('file.load_image_script',
104                                'tests/ci/load_images.sh')
105 LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT)
106 DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out')
107 DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm')
108 REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html')
109
110 # influxDB
111 INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)
112 INFLUXDB_PORT = get_param('influxdb.port', 8086)
113 INFLUXDB_USER = get_param('influxdb.username', 'root')
114 INFLUXDB_PASS = get_param('influxdb.password', 'root')
115 INFLUXDB_DB_NAME = get_param('influxdb.db_name', 'yardstick')
116 INFLUXDB_IMAGE = get_param('influxdb.image', 'tutum/influxdb')
117 INFLUXDB_TAG = get_param('influxdb.tag', '0.13')
118 INFLUXDB_DASHBOARD_PORT = 8083
119 QUEUE_PUT_TIMEOUT = 10
120
121 # grafana
122 GRAFANA_IP = get_param('grafana.ip', SERVER_IP)
123 GRAFANA_PORT = get_param('grafana.port', 3000)
124 GRAFANA_USER = get_param('grafana.username', 'admin')
125 GRAFANA_PASS = get_param('grafana.password', 'admin')
126 GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
127 GRAFANA_TAG = get_param('grafana.tag', '4.4.3')
128 GRAFANA_MAPPING_PORT = 1948
129
130 # api
131 API_PORT = 5000
132 DOCKER_URL = 'unix://var/run/docker.sock'
133 INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
134 SQLITE = 'sqlite:////tmp/yardstick.db'
135
136 API_SUCCESS = 1
137 API_ERROR = 2
138 TASK_NOT_DONE = 0
139 TASK_DONE = 1
140 TASK_FAILED = 2
141
142 BASE_URL = 'http://localhost:5000'
143 ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
144 ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
145
146 API_ERRORS = {
147     'UploadOpenrcError': {
148         'message': "Upload openrc ERROR!",
149         'status': API_ERROR,
150     },
151     'UpdateOpenrcError': {
152         'message': "Update openrc ERROR!",
153         'status': API_ERROR,
154     },
155     'ApiServerError': {
156         'message': "An unkown exception happened to Api Server!",
157         'status': API_ERROR,
158     },
159 }
160
161 # flags
162 IS_EXISTING = 'is_existing'
163 IS_PUBLIC = 'is_public'
164
165 # general
166 TESTCASE_PRE = 'opnfv_yardstick_'
167 TESTSUITE_PRE = 'opnfv_'
168
169 # OpenStack cloud default config parameters
170 OS_CLOUD_DEFAULT_CONFIG = {'verify': False}
171
172 # Kubernetes
173 SCOPE_NAMESPACED = 'Namespaced'
174 SCOPE_CLUSTER = 'Cluster'
175
176 # VNF definition
177 SSH_PORT = 22
178 LUA_PORT = 22022
179
180 # IMIX mode
181 DISTRIBUTION_IN_PACKETS = 'mode_DIP'
182 DISTRIBUTION_IN_BYTES = 'mode_DIB'