summaryrefslogtreecommitdiffstats
path: root/vnftest/common/constants.py
blob: a613ff0b9129d9d3051fe440b36717525abb2c46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
##############################################################################
# Copyright 2018 EuropeanSoftwareMarketingLtd.
# ===================================================================
#  Licensed under the ApacheLicense, Version2.0 (the"License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#  http://www.apache.org/licenses/LICENSE-2.0
#
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under
# the License
##############################################################################
# vnftest comment: this is a modified copy of
# yardstick/common/constants.py
from __future__ import absolute_import
import os
import errno

from functools import reduce

import pkg_resources

# this module must only import other modules that do
# not require loggers to be created, so this cannot
# include vnftest.common.utils
from vnftest.common.yaml_loader import yaml_load

dirname = os.path.dirname
abspath = os.path.abspath
join = os.path.join

CONF = {}
CONF_FILE = None
VNFTEST_ROOT_PATH = os.environ.get('VNFTEST_ROOT_PATH', dirname(dirname(abspath(pkg_resources.resource_filename(__name__, "")))) + os.path.sep)

def get_param(key, default=''):
    # don't re-parse yaml for each lookup
    if not CONF:
        # we have to defer this to runtime so that we can mock os.environ.get in unittests
        default_path = os.path.join(VNFTEST_ROOT_PATH, "etc/vnftest/vnftest.yaml")
        conf_file = os.environ.get('CONF_FILE', default_path)

        # do not use vnftest.common.utils.parse_yaml
        # since vnftest.common.utils creates a logger
        # and so it cannot be imported before this code
        try:
            with open(conf_file) as f:
                value = yaml_load(f)
        except IOError:
            pass
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        else:
            CONF.update(value)
    try:
        return reduce(lambda a, b: a[b], key.split('.'), CONF)
    except KeyError:
        if not default:
            raise
        return default

# dir
CONF_DIR = get_param('dir.conf', '/etc/vnftest')
IMAGE_DIR = get_param('dir.images', join(VNFTEST_ROOT_PATH, '../../images/'))
PACKAGE_DIR = get_param('dir.packages', join(VNFTEST_ROOT_PATH, '../../packages/'))
CONF_FILE = join(CONF_DIR, 'vnftest.conf')
REPOS_DIR = get_param('dir.repos', join(VNFTEST_ROOT_PATH, '..'))
LOG_DIR = get_param('dir.log', '/var/log/vnftest/')
REPORT_DIR = get_param('dir.report', '/tmp/')

TASK_LOG_DIR = get_param('dir.tasklog', '/var/log/vnftest/')
CONF_SAMPLE_DIR = join(REPOS_DIR, 'etc/vnftest/')
SAMPLE_CASE_DIR = join(REPOS_DIR, 'samples')
TESTCASE_DIR = join(VNFTEST_ROOT_PATH, 'vnftest/test_config/onap/test_cases/')
TESTSUITE_DIR = join(VNFTEST_ROOT_PATH, 'vnftest/test_config/onap/test_suites/')

# api
API_PORT = 5000
DOCKER_URL = 'unix://var/run/docker.sock'
SQLITE = 'sqlite:////tmp/vnftest.db'

API_SUCCESS = 1
API_ERROR = 2
TASK_NOT_DONE = 0
TASK_DONE = 1
TASK_FAILED = 2

BASE_URL = 'http://localhost:5000'
ENV_ACTION_API = BASE_URL + '/vnftest/env/action'
ASYNC_TASK_API = BASE_URL + '/vnftest/asynctask'

# flags
IS_EXISTING = 'is_existing'
IS_PUBLIC = 'is_public'

# general
TESTCASE_PRE = 'onap_vnftest_'
TESTSUITE_PRE = 'onap_'


# OpenStack cloud default config parameters
OS_CLOUD_DEFAULT_CONFIG = {'verify': False}