posca_factor_system_bandwidth by default.'''
import importlib
+import sys
+import os
+
+from oslo_serialization import jsonutils
+import json
+import requests
+import datetime
+
import utils.parser as conf_parser
import utils.logger as log
INTERPRETER = "/usr/bin/python"
LOG = log.Logger(__name__).getLogger()
# ------------------------------------------------------
-# run posca testcase
+# run testcase in posca
# ------------------------------------------------------
module.run(test_config)
-def posca_run(test_level, test_name):
+def report(testcase, start_date, stop_date, criteria, details_doc):
+ headers = {'Content-type': 'application/json'}
+ results = {
+ "project_name": "bottlenecks",
+ "case_name": testcase,
+ "description": ("test results for " + testcase),
+ "pod_name": os.environ.get('NODE_NAME', 'unknown'),
+ "installer": os.environ.get('INSTALLER_TYPE', 'unknown'),
+ "version": os.environ.get('BRANCH', 'unknown'),
+ "build_tag": os.environ.get('BUILD_TAG', 'unknown'),
+ "stop_date": str(stop_date),
+ "start_date": str(start_date),
+ "criteria": criteria,
+ "scenario": os.environ.get('DEPLOY_SCENARIO', 'unknown')
+ }
+ results['details'] = {"test_results": details_doc}
+
+ target = "http://testresults.opnfv.org/test/api/v1/results"
+ timeout = 5
+
+ try:
+ LOG.debug('Test result : %s', jsonutils.dump_as_bytes(results))
+ print ('Start posting test results to community MongoDB')
+ res = requests.post(target,
+ data=jsonutils.dump_as_bytes(results),
+ headers=headers,
+ timeout=timeout)
+ LOG.debug('Test result posting finished with status code'
+ ' %d.' % res.status_code)
+ print ('Test results posting finished with status code'
+ ' %d.' % res.status_code)
+ except Exception as err:
+ LOG.exception('Failed to record result data: %s', err)
+
+
+def posca_run(test_level, test_name, REPORT="False"):
if test_level == "testcase":
config = conf_parser.Parser.testcase_read("posca", test_name)
elif test_level == "teststory":
config = conf_parser.Parser.story_read("posca", test_name)
for testcase in config:
- print(config[testcase])
+ LOG.info("Begin to run %s testcase in POSCA testsuite", testcase)
+ config[testcase]['out_file'] =\
+ conf_parser.Parser.testcase_out_dir(testcase)
+ start_date = datetime.datetime.now()
posca_testcase_run(testcase, config[testcase])
- if con_dic["dashboard"] == "y":
- cmd = '/home/opnfv/bottlenecks/testsuites/posca/testcase_dashboard/\
-system_bandwidth.py'
- pargs = [INTERPRETER, cmd]
- LOG.info("\nBegin to establish dashboard.")
- sub_result = subprocess.Popen(pargs)
- sub_result.wait()
+ stop_date = datetime.datetime.now()
+ LOG.info("End of %s testcase in POSCA testsuite", testcase)
+
+ criteria = "FAIL"
+ if REPORT == "True":
+ details_doc = []
+ if os.path.exists(config[testcase]['out_file']):
+ with open(config[testcase]['out_file']) as details_result:
+ details_doc =[json.loads(data) for data in details_result.readlines()] # noqa
+ if len(details_doc):
+ criteria = "PASS"
+ report(testcase, start_date, stop_date, criteria, details_doc)
def main():
- test_level = "testcase"
- test_name = "posca_factor_system_bandwidth"
- posca_run(test_level, test_name)
+ test_level = sys.argv[1]
+ test_name = sys.argv[2]
+ REPORT = sys.argv[3]
+ posca_run(test_level, test_name, REPORT)
if __name__ == '__main__':
main()
-