2 # Copyright 2021 Orange
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
17 """Define classes required to run any Behave test suites."""
19 from __future__ import division
25 from xtesting.core.behaveframework import BehaveFramework
27 __author__ = "François-Régis Menguy <francoisregis.menguy@orange.com>"
30 class BehaveDriver(BehaveFramework):
31 """NFVbench custom BehaveDriver for Xtesting."""
32 # pylint: disable=too-many-instance-attributes
34 __logger = logging.getLogger('xtesting.core.behavedriver')
36 def __init__(self, **kwargs):
37 super().__init__(**kwargs)
38 self.campaign_json_file = os.path.join(self.res_dir, 'campaign_result.json')
40 def extract_nfvbench_results(self):
41 with open(self.campaign_json_file) as stream_:
42 self.details['results'] = json.load(stream_)
44 def run(self, **kwargs):
46 """Override existing Xtesting BehaveFramework core script run method
47 to extract NFVbench result and push them to DB
50 * run Xtesting behave method:
51 * create the output directories if required,
52 * run behave features with parameters
53 * get the behave results in output.json,
54 * get the nfvbench results in campaign_result.json
57 kwargs: Arbitrary keyword arguments.
60 EX_OK if all suites ran well.
61 EX_RUN_ERROR otherwise.
65 self.extract_nfvbench_results()
66 self.__logger.info("NFVbench results were successfully parsed")
67 except Exception: # pylint: disable=broad-except
68 self.__logger.exception("Cannot parse NFVbench results")
69 return self.EX_RUN_ERROR