12cd4cc2a018fd690a2733d5cbe19d1d2ba94df2
[nfvbench.git] / behave_tests / features / environment.py
1 #!/usr/bin/env python
2 # Copyright 2021 Orange
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15 #
16
17
18 import json
19 import os
20 import time
21
22
23 def before_all(context):
24     context.data = {'config': os.getenv('NFVBENCH_CONFIG_PATH', '/etc/nfvbench/nfvbench.cfg')}
25
26     context.data['PROJECT_NAME'] = os.getenv('PROJECT_NAME', 'nfvbench')
27     context.data['TEST_DB_EXT_URL'] = os.getenv('TEST_DB_EXT_URL')
28     context.data['TEST_DB_URL'] = os.getenv('TEST_DB_URL')
29     context.data['BASE_TEST_DB_URL'] = ''
30     if context.data['TEST_DB_URL']:
31         context.data['BASE_TEST_DB_URL'] = context.data['TEST_DB_URL'].replace('results', '')
32     context.data['INSTALLER_TYPE'] = os.getenv('INSTALLER_TYPE')
33     context.data['DEPLOY_SCENARIO'] = os.getenv('DEPLOY_SCENARIO')
34     context.data['NODE_NAME'] = os.getenv('NODE_NAME', 'nfvbench')
35     context.data['BUILD_TAG'] = os.getenv('BUILD_TAG')
36
37     # NFVbench server host and port
38     context.host_ip = os.getenv('NFVBENCH_SERVER_HOST', '127.0.0.1')
39     context.port = int(os.getenv('NFVBENCH_SERVER_PORT', '7555'))
40
41
42 def before_feature(context, feature):
43     context.rates = {}
44     context.results = {}
45     context.start_time = time.time()
46     context.CASE_NAME = feature.name
47
48
49 def before_scenario(context, scenario):
50     context.tag = scenario.tags[0]
51     context.json = {'log_file': '/var/lib/xtesting/results/' + context.CASE_NAME + '/nfvbench.log'}
52     user_label = os.getenv('NFVBENCH_USER_LABEL', None)
53     if user_label:
54         context.json['user_label'] = user_label
55     loopvm_flavor = os.getenv('NFVBENCH_LOOPVM_FLAVOR_NAME', None)
56     if loopvm_flavor:
57         context.json['flavor_type'] = loopvm_flavor
58     context.synthesis = {}
59
60
61 def after_feature(context, feature):
62     if context.results:
63         with open(os.path.join(
64                 '/var/lib/xtesting/results/' + context.CASE_NAME + '/campaign_result.json'), "w") \
65                 as outfile:
66             json.dump(context.results, outfile)