diff options
author | 2016-08-27 06:26:46 +0000 | |
---|---|---|
committer | 2016-08-27 07:55:16 +0000 | |
commit | f53fc8221faf7718d1cf060038ad3a23463b8398 (patch) | |
tree | a0d3bf61e9e10f1ef006f59b29e47138230fc8ec /utils/test/reporting/yardstick/reportingUtils.py | |
parent | f0830fb30a41e6db542ce7c843c5819fcb205c9e (diff) |
Add the function of yardstick testcase reporter
JIRA: YARDSTICK-324
Change-Id: I58969265f88d5c20f46f0b1097f5b0ccb1d9a40d
Signed-off-by: rexlee8776 <limingjiang@huawei.com>
Diffstat (limited to 'utils/test/reporting/yardstick/reportingUtils.py')
-rw-r--r-- | utils/test/reporting/yardstick/reportingUtils.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/utils/test/reporting/yardstick/reportingUtils.py b/utils/test/reporting/yardstick/reportingUtils.py new file mode 100644 index 000000000..06bcd4926 --- /dev/null +++ b/utils/test/reporting/yardstick/reportingUtils.py @@ -0,0 +1,68 @@ +#!/usr/bin/python +# +# This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +from urllib2 import Request, urlopen, URLError +import logging +import json +import reportingConf as conf + + +def getLogger(module): + logFormatter = logging.Formatter("%(asctime)s [" + + module + + "] [%(levelname)-5.5s] %(message)s") + logger = logging.getLogger() + + fileHandler = logging.FileHandler("{0}/{1}".format('.', conf.LOG_FILE)) + fileHandler.setFormatter(logFormatter) + logger.addHandler(fileHandler) + + consoleHandler = logging.StreamHandler() + consoleHandler.setFormatter(logFormatter) + logger.addHandler(consoleHandler) + logger.setLevel(conf.LOG_LEVEL) + return logger + + +def getScenarioStatus(installer, version): + url = (conf.URL_BASE + "?case=" + "scenario_status" + + "&installer=" + installer + + "&version=" + version +"&period=" + str(conf.PERIOD)) + request = Request(url) + + try: + response = urlopen(request) + k = response.read() + response.close() + results = json.loads(k) + test_results = results['results'] + except URLError, e: + print 'Got an error code:', e + + scenario_results = {} + if test_results is not None: + for r in test_results: + if r['stop_date'] != 'None': + if not r['scenario'] in scenario_results.keys(): + scenario_results[r['scenario']] = [] + scenario_results[r['scenario']].append(r) + + for k,v in scenario_results.items(): + scenario_results[k] = v[:conf.LASTEST_TESTS] + + return scenario_results + + +def _test(): + status = getScenarioStatus("compass", "master") + print "status:++++++++++++++++++++++++" + print json.dumps(status,indent=4) + + +if __name__ == '__main__': # pragma: no cover + _test() |