import json
import os
+import logging
+import pathlib
import time
context.data = {'config': os.getenv('NFVBENCH_CONFIG_PATH', '/etc/nfvbench/nfvbench.cfg')}
context.data['PROJECT_NAME'] = os.getenv('PROJECT_NAME', 'nfvbench')
- context.data['TEST_DB_EXT_URL'] = os.getenv('TEST_DB_EXT_URL')
context.data['TEST_DB_URL'] = os.getenv('TEST_DB_URL')
context.data['BASE_TEST_DB_URL'] = ''
if context.data['TEST_DB_URL']:
context.data['NODE_NAME'] = os.getenv('NODE_NAME', 'nfvbench')
context.data['BUILD_TAG'] = os.getenv('BUILD_TAG')
+ # NFVbench server host and port
+ context.host_ip = os.getenv('NFVBENCH_SERVER_HOST', '127.0.0.1')
+ context.port = int(os.getenv('NFVBENCH_SERVER_PORT', '7555'))
+
def before_feature(context, feature):
context.rates = {}
context.start_time = time.time()
context.CASE_NAME = feature.name
+ # Create results dir if needed
+ results_dir = pathlib.Path('/var/lib/xtesting/results/' + context.CASE_NAME)
+ if not results_dir.exists():
+ results_dir.mkdir()
+
+ # Setup a second logger to be able to understand why a test passed or failed
+ # (The main logger is used by behave itself)
+ context.logger = logging.getLogger('behave_tests')
+ context.logger.setLevel(logging.INFO)
+ fh = logging.FileHandler(filename=results_dir / pathlib.Path('behave_tests.log'),
+ mode='w') # Re-create the file at the beginning of the feature
+ fh.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
+ context.logger.addHandler(fh)
+
+ context.logger.info('before_feature: ' + feature.name)
+
def before_scenario(context, scenario):
context.tag = scenario.tags[0]
if loopvm_flavor:
context.json['flavor_type'] = loopvm_flavor
context.synthesis = {}
+ context.percentage_rate = None
+
+ context.logger.info('before_scenario: ' + scenario.name)
def after_feature(context, feature):
- if context.results:
- with open(os.path.join(
- '/var/lib/xtesting/results/' + context.CASE_NAME + '/campaign_result.json'), "w") \
- as outfile:
- json.dump(context.results, outfile)
+ if len(context.results) == 0:
+ # No result to dump
+ return
+
+ results_dir = pathlib.Path('/var/lib/xtesting/results/' + context.CASE_NAME)
+ results_file = results_dir / pathlib.Path('campaign_result.json')
+ results_file.write_text(json.dumps(context.results, indent=4))