Merge "Add test case file, document and related scripts of yardstick tc058(HA_TC015)"
[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 REPOS_DIR = get_param('dir.repos', '/home/opnfv/repos/yardstick')
63 RELENG_DIR = get_param('dir.releng', '/home/opnfv/repos/releng')
64 LOG_DIR = get_param('dir.log', '/tmp/yardstick/')
65 YARDSTICK_ROOT_PATH = dirname(
66     dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep
67 TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/yardstick/')
68 CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/yardstick/')
69 ANSIBLE_DIR = join(REPOS_DIR, 'ansible')
70 SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
71 TESTCASE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_cases/')
72 TESTSUITE_DIR = join(YARDSTICK_ROOT_PATH, 'tests/opnfv/test_suites/')
73 DOCS_DIR = join(REPOS_DIR, 'docs/testing/user/userguide/')
74 OPENSTACK_CONF_DIR = '/etc/openstack'
75
76 # file
77 OPENRC = get_param('file.openrc', '/etc/yardstick/openstack.creds')
78 ETC_HOSTS = get_param('file.etc_hosts', '/etc/hosts')
79 CONF_FILE = join(CONF_DIR, 'yardstick.conf')
80 POD_FILE = join(CONF_DIR, 'pod.yaml')
81 CLOUDS_CONF = join(OPENSTACK_CONF_DIR, 'clouds.yml')
82 K8S_CONF_FILE = join(CONF_DIR, 'admin.conf')
83 CONF_SAMPLE_FILE = join(CONF_SAMPLE_DIR, 'yardstick.conf.sample')
84 FETCH_SCRIPT = get_param('file.fetch_script', 'utils/fetch_os_creds.sh')
85 FETCH_SCRIPT = join(RELENG_DIR, FETCH_SCRIPT)
86 CLEAN_IMAGES_SCRIPT = get_param('file.clean_image_script',
87                                 'tests/ci/clean_images.sh')
88 CLEAN_IMAGES_SCRIPT = join(REPOS_DIR, CLEAN_IMAGES_SCRIPT)
89 LOAD_IMAGES_SCRIPT = get_param('file.load_image_script',
90                                'tests/ci/load_images.sh')
91 LOAD_IMAGES_SCRIPT = join(REPOS_DIR, LOAD_IMAGES_SCRIPT)
92 DEFAULT_OUTPUT_FILE = get_param('file.output_file', '/tmp/yardstick.out')
93 DEFAULT_HTML_FILE = get_param('file.html_file', '/tmp/yardstick.htm')
94 REPORTING_FILE = get_param('file.reporting_file', '/tmp/report.html')
95
96 # influxDB
97 INFLUXDB_IP = get_param('influxdb.ip', SERVER_IP)
98 INFLUXDB_PORT = get_param('influxdb.port', 8086)
99 INFLUXDB_USER = get_param('influxdb.username', 'root')
100 INFLUXDB_PASS = get_param('influxdb.password', 'root')
101 INFLUXDB_DB_NAME = get_param('influxdb.db_name', 'yardstick')
102 INFLUXDB_IMAGE = get_param('influxdb.image', 'tutum/influxdb')
103 INFLUXDB_TAG = get_param('influxdb.tag', '0.13')
104 INFLUXDB_DASHBOARD_PORT = 8083
105
106 # grafana
107 GRAFANA_IP = get_param('grafana.ip', SERVER_IP)
108 GRAFANA_PORT = get_param('grafana.port', 3000)
109 GRAFANA_USER = get_param('grafana.username', 'admin')
110 GRAFANA_PASS = get_param('grafana.password', 'admin')
111 GRAFANA_IMAGE = get_param('grafana.image', 'grafana/grafana')
112 GRAFANA_TAG = get_param('grafana.tag', '3.1.1')
113 GRAFANA_MAPPING_PORT = 1948
114
115 # api
116 API_PORT = 5000
117 DOCKER_URL = 'unix://var/run/docker.sock'
118 INSTALLERS = ['apex', 'compass', 'fuel', 'joid']
119 SQLITE = 'sqlite:////tmp/yardstick.db'
120
121 API_SUCCESS = 1
122 API_ERROR = 2
123 TASK_NOT_DONE = 0
124 TASK_DONE = 1
125 TASK_FAILED = 2
126
127 BASE_URL = 'http://localhost:5000'
128 ENV_ACTION_API = BASE_URL + '/yardstick/env/action'
129 ASYNC_TASK_API = BASE_URL + '/yardstick/asynctask'
130
131 # general
132 TESTCASE_PRE = 'opnfv_yardstick_'
133 TESTSUITE_PRE = 'opnfv_'