Moshe | 0bb532c | 2018-02-26 13:39:57 +0200 | [diff] [blame] | 1 | ############################################################################## |
| 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 |
| 16 | from __future__ import absolute_import |
| 17 | import os |
| 18 | import errno |
| 19 | |
| 20 | from functools import reduce |
| 21 | |
| 22 | import 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 |
| 27 | from vnftest.common.yaml_loader import yaml_load |
| 28 | |
| 29 | dirname = os.path.dirname |
| 30 | abspath = os.path.abspath |
| 31 | join = os.path.join |
| 32 | sep = os.path.sep |
| 33 | |
| 34 | CONF = {} |
| 35 | CONF_FILE = None |
| 36 | VNFTEST_ROOT_PATH = dirname( |
| 37 | dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + sep |
| 38 | |
| 39 | |
| 40 | def get_param(key, default=''): |
Moshe | 0bb532c | 2018-02-26 13:39:57 +0200 | [diff] [blame] | 41 | # don't re-parse yaml for each lookup |
| 42 | if not CONF: |
Moshe | 30497ac | 2018-03-14 14:22:13 +0200 | [diff] [blame] | 43 | # 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 | |
Moshe | 0bb532c | 2018-02-26 13:39:57 +0200 | [diff] [blame] | 47 | # 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 | |
| 68 | try: |
| 69 | SERVER_IP = get_param('api.server_ip') |
| 70 | except 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 | |
| 83 | if not SERVER_IP: |
| 84 | SERVER_IP = '127.0.0.1' |
| 85 | |
| 86 | |
| 87 | # dir |
| 88 | CONF_DIR = get_param('dir.conf', join(VNFTEST_ROOT_PATH, 'etc/vnftest')) |
| 89 | CONF_FILE = join(CONF_DIR, 'vnftest.conf') |
| 90 | REPOS_DIR = get_param('dir.repos', join(VNFTEST_ROOT_PATH, 'home/onap/repos/vnftest')) |
| 91 | LOG_DIR = get_param('dir.log', join(VNFTEST_ROOT_PATH, 'tmp/vnftest/')) |
| 92 | |
| 93 | TASK_LOG_DIR = get_param('dir.tasklog', join(VNFTEST_ROOT_PATH, 'var/log/vnftest/')) |
| 94 | CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/vnftest/') |
| 95 | SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples') |
| 96 | TESTCASE_DIR = join(VNFTEST_ROOT_PATH, 'tests/onap/test_cases/') |
| 97 | TESTSUITE_DIR = join(VNFTEST_ROOT_PATH, 'tests/onap/test_suites/') |
| 98 | |
| 99 | # file |
| 100 | DEFAULT_OUTPUT_FILE = get_param('file.output_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.out')) |
| 101 | DEFAULT_HTML_FILE = get_param('file.html_file', join(VNFTEST_ROOT_PATH, 'tmp/vnftest.htm')) |
| 102 | REPORTING_FILE = get_param('file.reporting_file', join(VNFTEST_ROOT_PATH, 'tmp/report.html')) |
| 103 | |
| 104 | # components |
| 105 | AAI_IP = get_param('component.aai_ip') |
| 106 | AAI_PORT = get_param('component.aai_port') |
| 107 | AAI_SSL_PORT = get_param('component.aai_ssl_port') |
| 108 | MSO_IP = get_param('component.mso_ip') |
| 109 | SDC_IP = get_param('component.sdc_ip') |
| 110 | SDC_PORT = get_param('component.sdc_port') |
| 111 | SDC_CATALOG_PORT = get_param('component.sdc_catalog_port') |
| 112 | SDC_DESIGNER_USER = get_param('component.sdc_designer_user') |
| 113 | SDC_TESTER_USER = get_param('component.sdc_tester_user') |
| 114 | SDC_GOVERNANCE_USER = get_param('component.sdc_governance_user') |
| 115 | SDC_OPERATIONS_USER = get_param('component.sdc_operations_user') |
| 116 | |
| 117 | component_constants = {} |
| 118 | component_constants['aai_ip'] = AAI_IP |
| 119 | component_constants['aai_port'] = AAI_PORT |
| 120 | component_constants['aai_ssl_port'] = AAI_SSL_PORT |
| 121 | component_constants['mso_ip'] = MSO_IP |
| 122 | component_constants['sdc_ip'] = SDC_IP |
| 123 | component_constants['sdc_port'] = SDC_PORT |
| 124 | component_constants['sdc_catalog_port'] = SDC_CATALOG_PORT |
| 125 | component_constants['sdc_designer_user'] = SDC_DESIGNER_USER |
| 126 | component_constants['sdc_tester_user'] = SDC_TESTER_USER |
| 127 | component_constants['sdc_governance_user'] = SDC_GOVERNANCE_USER |
| 128 | component_constants['sdc_operations_user'] = SDC_OPERATIONS_USER |
| 129 | |
| 130 | |
| 131 | # api |
| 132 | API_PORT = 5000 |
| 133 | DOCKER_URL = 'unix://var/run/docker.sock' |
| 134 | SQLITE = 'sqlite:////tmp/vnftest.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 + '/vnftest/env/action' |
| 144 | ASYNC_TASK_API = BASE_URL + '/vnftest/asynctask' |
| 145 | |
| 146 | # general |
| 147 | TESTCASE_PRE = 'onap_vnftest_' |
| 148 | TESTSUITE_PRE = 'onap_' |