Support for xtesting
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / rapidxt.py
1 #!/usr/bin/python3
2
3 ##
4 ## Copyright (c) 2020 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18  
19 # pylint: disable=missing-docstring
20
21 import json
22 import os
23 import sys
24 import time
25
26 from xtesting.core import testcase
27 from runrapid import RapidTestManager
28 from rapid_cli import RapidCli
29 from rapid_log import RapidLog
30
31 class RapidXt(testcase.TestCase):
32
33     def run(self, **kwargs):
34         try:
35             test_params = RapidTestManager.get_defaults()
36             for key in kwargs:
37                 test_params[key] = kwargs[key]
38             os.makedirs(self.res_dir, exist_ok=True)
39             log_file = '{}/RUN{}.{}.log'.format(self.res_dir,
40                 test_params['environment_file'], test_params['test_file'])
41             RapidLog.log_init(log_file, test_params['loglevel'],
42                 test_params['screenloglevel'] , test_params['version']  )
43             test_manager = RapidTestManager()
44             self.start_time = time.time()
45             self.result, self.details = test_manager.run_tests(test_params)
46             self.result = 100 * self.result
47             RapidLog.info('Test result is : {}'.format(self.result))
48             self.stop_time = time.time()
49         except Exception:  # pylint: disable=broad-except
50             print("Unexpected error:", sys.exc_info()[0])
51             self.result = 0
52             self.stop_time = time.time()