blob: 8bbe070dafc93f30eabc64513224fc3e54630287 [file] [log] [blame]
Moshe0bb532c2018-02-26 13:39:57 +02001##############################################################################
2# Copyright 2018 EuropeanSoftwareMarketingLtd.
3# ===================================================================
4# Licensed under the ApacheLicense, Version2.0 (the"License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# software distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and limitations under
12# the License
13##############################################################################
14# vnftest comment: this is a modified copy of
15# yardstick/common/constants.py
16from __future__ import absolute_import
17import os
18import errno
19
20from functools import reduce
21
22import pkg_resources
23
24# this module must only import other modules that do
25# not require loggers to be created, so this cannot
26# include vnftest.common.utils
27from vnftest.common.yaml_loader import yaml_load
28
29dirname = os.path.dirname
30abspath = os.path.abspath
31join = os.path.join
32sep = os.path.sep
33
34CONF = {}
35CONF_FILE = None
36VNFTEST_ROOT_PATH = dirname(
37 dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep
38
39
40def get_param(key, default=''):
Moshe0bb532c2018-02-26 13:39:57 +020041 # don't re-parse yaml for each lookup
42 if not CONF:
Moshe30497ac2018-03-14 14:22:13 +020043 # we have to defer this to runtime so that we can mock os.environ.get in unittests
44 default_path = os.path.join(VNFTEST_ROOT_PATH, "etc/vnftest/vnftest.yaml")
45 conf_file = os.environ.get('CONF_FILE', default_path)
46
Moshe0bb532c2018-02-26 13:39:57 +020047 # do not use vnftest.common.utils.parse_yaml
48 # since vnftest.common.utils creates a logger
49 # and so it cannot be imported before this code
50 try:
51 with open(conf_file) as f:
52 value = yaml_load(f)
53 except IOError:
54 pass
55 except OSError as e:
56 if e.errno != errno.EEXIST:
57 raise
58 else:
59 CONF.update(value)
60 try:
61 return reduce(lambda a, b: a[b], key.split('.'), CONF)
62 except KeyError:
63 if not default:
64 raise
65 return default
66
67
68try:
69 SERVER_IP = get_param('api.server_ip')
70except KeyError:
71 try:
72 from pyroute2 import IPDB
73 except ImportError:
74 SERVER_IP = '172.17.0.1'
75 else:
76 with IPDB() as ip:
77 try:
78 SERVER_IP = ip.routes['default'].gateway
79 except KeyError:
80 # during unittests ip.routes['default'] can be invalid
81 SERVER_IP = '127.0.0.1'
82
83if not SERVER_IP:
84 SERVER_IP = '127.0.0.1'
85
86
87# dir
88CONF_DIR = get_param('dir.conf', join(VNFTEST_ROOT_PATH, 'etc/vnftest'))
89CONF_FILE = join(CONF_DIR, 'vnftest.conf')
90REPOS_DIR = get_param('dir.repos', join(VNFTEST_ROOT_PATH, 'home/onap/repos/vnftest'))
91LOG_DIR = get_param('dir.log', join(VNFTEST_ROOT_PATH, 'tmp/vnftest/'))
92
93TASK_LOG_DIR = get_param('dir.tasklog', join(VNFTEST_ROOT_PATH, 'var/log/vnftest/'))
94CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/vnftest/')
95SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
96TESTCASE_DIR = join(VNFTEST_ROOT_PATH, 'tests/onap/test_cases/')
97TESTSUITE_DIR = join(VNFTEST_ROOT_PATH, 'tests/onap/test_suites/')
98
99# file
100DEFAULT_OUTPUT_FILE = get_param('file.output_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.out'))
101DEFAULT_HTML_FILE = get_param('file.html_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.htm'))
102REPORTING_FILE = get_param('file.reporting_file', join(VNFTEST_ROOT_PATH, 'tmp/report.html'))
103
104# components
105AAI_IP = get_param('component.aai_ip')
106AAI_PORT = get_param('component.aai_port')
107AAI_SSL_PORT = get_param('component.aai_ssl_port')
108MSO_IP = get_param('component.mso_ip')
109SDC_IP = get_param('component.sdc_ip')
110SDC_PORT = get_param('component.sdc_port')
111SDC_CATALOG_PORT = get_param('component.sdc_catalog_port')
112SDC_DESIGNER_USER = get_param('component.sdc_designer_user')
113SDC_TESTER_USER = get_param('component.sdc_tester_user')
114SDC_GOVERNANCE_USER = get_param('component.sdc_governance_user')
115SDC_OPERATIONS_USER = get_param('component.sdc_operations_user')
116
117component_constants = {}
118component_constants['aai_ip'] = AAI_IP
119component_constants['aai_port'] = AAI_PORT
120component_constants['aai_ssl_port'] = AAI_SSL_PORT
121component_constants['mso_ip'] = MSO_IP
122component_constants['sdc_ip'] = SDC_IP
123component_constants['sdc_port'] = SDC_PORT
124component_constants['sdc_catalog_port'] = SDC_CATALOG_PORT
125component_constants['sdc_designer_user'] = SDC_DESIGNER_USER
126component_constants['sdc_tester_user'] = SDC_TESTER_USER
127component_constants['sdc_governance_user'] = SDC_GOVERNANCE_USER
128component_constants['sdc_operations_user'] = SDC_OPERATIONS_USER
129
130
131# api
132API_PORT = 5000
133DOCKER_URL = 'unix://var/run/docker.sock'
134SQLITE = 'sqlite:////tmp/vnftest.db'
135
136API_SUCCESS = 1
137API_ERROR = 2
138TASK_NOT_DONE = 0
139TASK_DONE = 1
140TASK_FAILED = 2
141
142BASE_URL = 'http://localhost:5000'
143ENV_ACTION_API = BASE_URL + '/vnftest/env/action'
144ASYNC_TASK_API = BASE_URL + '/vnftest/asynctask'
145
146# general
147TESTCASE_PRE = 'onap_vnftest_'
148TESTSUITE_PRE = 'onap_'