diff options
Diffstat (limited to 'qtip')
-rw-r--r-- | qtip/api/cmd/__init__.py | 0 | ||||
-rw-r--r-- | qtip/api/cmd/server.py | 30 | ||||
-rw-r--r-- | qtip/api/handler/__init__.py | 0 | ||||
-rw-r--r-- | qtip/api/handler/db.py (renamed from qtip/api/db.py) | 0 | ||||
-rw-r--r-- | qtip/api/handler/job_handler.py (renamed from qtip/api/qtip_server.py) | 52 | ||||
-rw-r--r-- | qtip/api/handler/result_handler.py | 58 | ||||
-rw-r--r-- | qtip/api/model/__init__.py | 0 | ||||
-rw-r--r-- | qtip/api/model/job_model.py | 25 | ||||
-rw-r--r-- | qtip/api/result_handler.py | 22 | ||||
-rw-r--r-- | qtip/api/router/__init__.py | 0 | ||||
-rw-r--r-- | qtip/api/router/mapper.py | 7 | ||||
-rw-r--r-- | qtip/runner/perftest.py | 4 | ||||
-rw-r--r-- | qtip/runner/suite.py | 5 | ||||
-rw-r--r-- | qtip/runner/testplan.py | 4 |
14 files changed, 136 insertions, 71 deletions
diff --git a/qtip/api/cmd/__init__.py b/qtip/api/cmd/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/qtip/api/cmd/__init__.py diff --git a/qtip/api/cmd/server.py b/qtip/api/cmd/server.py new file mode 100644 index 00000000..852073a7 --- /dev/null +++ b/qtip/api/cmd/server.py @@ -0,0 +1,30 @@ +############################################################################## +# Copyright (c) 2016 ZTE Corp and others. +# +# All rights reserved. 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 flask import Flask +from flask_restful import Api +from flask_restful_swagger import swagger +import qtip.api.router.mapper as mapper + +app = Flask(__name__) +api = swagger.docs(Api(app), apiVersion='0.1') + + +def add_routers(): + for (handler, url) in mapper.mappers: + api.add_resource(handler, url) + + +def main(): + add_routers() + app.run(host='0.0.0.0') + + +if __name__ == "__main__": + main() diff --git a/qtip/api/handler/__init__.py b/qtip/api/handler/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/qtip/api/handler/__init__.py diff --git a/qtip/api/db.py b/qtip/api/handler/db.py index 24fc27a5..24fc27a5 100644 --- a/qtip/api/db.py +++ b/qtip/api/handler/db.py diff --git a/qtip/api/qtip_server.py b/qtip/api/handler/job_handler.py index e2ee0d27..f230e596 100644 --- a/qtip/api/qtip_server.py +++ b/qtip/api/handler/job_handler.py @@ -1,46 +1,13 @@ -############################################################################## -# Copyright (c) 2016 ZTE Corp and others. -# -# All rights reserved. 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 flask import Flask, abort -from flask_restful import Api, Resource, fields, reqparse -from flask_restful_swagger import swagger import threading from copy import copy -import db -import qtip.utils.args_handler as args_handler -import qtip.api.result_handler as result_handler +from flask.ext.restful import Resource, reqparse +from flask.ext.restful_swagger import swagger +from werkzeug.exceptions import abort -app = Flask(__name__) -api = swagger.docs(Api(app), apiVersion='0.1') - - -@swagger.model -class JobModel: - resource_fields = { - 'installer_type': fields.String, - 'installer_ip': fields.String, - 'max_minutes': fields.Integer, - 'pod_name': fields.String, - 'suite_name': fields.String, - 'type': fields.String, - 'benchmark_name': fields.String, - 'testdb_url': fields.String, - 'node_name': fields.String - } - required = ['installer_type', 'installer_ip'] - - -@swagger.model -class JobResponseModel: - resource_fields = { - 'job_id': fields.String - } +from qtip.api.handler import db, result_handler +from qtip.api.model.job_model import JobResponseModel +from qtip.utils import args_handler as args_handler class Job(Resource): @@ -197,10 +164,3 @@ default is all benchmarks in suite with specified type, if (result_handler.dump_suite_result(suite_name) and testdb_url): result_handler.push_suite_result_to_db(suite_name, testdb_url, installer_type, node_name) db.finish_job(job_id) - - -api.add_resource(JobList, '/api/v1.0/jobs') -api.add_resource(Job, '/api/v1.0/jobs/<string:id>') - -if __name__ == "__main__": - app.run(host='0.0.0.0') diff --git a/qtip/api/handler/result_handler.py b/qtip/api/handler/result_handler.py new file mode 100644 index 00000000..3d1d592e --- /dev/null +++ b/qtip/api/handler/result_handler.py @@ -0,0 +1,58 @@ +############################################################################## +# Copyright (c) 2016 ZTE Corp and others. +# +# All rights reserved. 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 +############################################################################## +import importlib +import json +from os.path import expanduser + +import qtip.utils.dashboard.pushtoDB as push_to_db +from qtip.utils import logger_utils + +logger = logger_utils.QtipLogger('suite_result').get + + +def get_benchmark_result(benchmark_name, suite_name): + benchmark_indices = importlib.import_module('scripts.ref_results' + '.{0}_benchmarks_indices'.format(suite_name)) + methodToCall = getattr(benchmark_indices, '{0}_index'.format(benchmark_name)) + return methodToCall() + + +def dump_suite_result(suite_name): + suite_dict = {} + suite_bench_list = {'compute': ['DPI', 'Dhrystone', 'Whetstone', 'SSL', 'RamSpeed'], + 'storage': ['FIO'], + 'network': ['IPERF']} + temp = 0 + l = len(suite_bench_list[suite_name]) + for benchmark in suite_bench_list[suite_name]: + try: + suite_dict[benchmark] = get_benchmark_result(benchmark.lower(), suite_name) + temp = temp + float(suite_dict[benchmark]['index']) + except OSError: + l = l - 1 + pass + + if l == 0: + logger.info("No {0} suite results found".format(suite_name)) + return False + else: + suite_index = temp / l + suite_dict_f = {'index': suite_index, + 'suite_results': suite_dict} + result_path = expanduser('~') + '/qtip/results' + with open('{0}/{1}_result.json'.format(result_path, suite_name), 'w+') as result_json: + json.dump(suite_dict_f, result_json, indent=4, sort_keys=True) + return True + + +def push_suite_result_to_db(suite_name, test_db_url, installer_type, node_name): + with open('results/{0}_result.json'.format(suite_name), 'r') as result_file: + j = json.load(result_file) + push_to_db.push_results_to_db(test_db_url, '{0}_test_suite'.format(suite_name), + j, installer_type, node_name) diff --git a/qtip/api/model/__init__.py b/qtip/api/model/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/qtip/api/model/__init__.py diff --git a/qtip/api/model/job_model.py b/qtip/api/model/job_model.py new file mode 100644 index 00000000..eef771b0 --- /dev/null +++ b/qtip/api/model/job_model.py @@ -0,0 +1,25 @@ +from flask.ext.restful import fields +from flask.ext.restful_swagger import swagger + + +@swagger.model +class JobModel: + resource_fields = { + 'installer_type': fields.String, + 'installer_ip': fields.String, + 'max_minutes': fields.Integer, + 'pod_name': fields.String, + 'suite_name': fields.String, + 'type': fields.String, + 'benchmark_name': fields.String, + 'testdb_url': fields.String, + 'node_name': fields.String + } + required = ['installer_type', 'installer_ip'] + + +@swagger.model +class JobResponseModel: + resource_fields = { + 'job_id': fields.String + } diff --git a/qtip/api/result_handler.py b/qtip/api/result_handler.py deleted file mode 100644 index de91cd2c..00000000 --- a/qtip/api/result_handler.py +++ /dev/null @@ -1,22 +0,0 @@ -############################################################################## -# Copyright (c) 2016 ZTE Corp and others. -# -# All rights reserved. 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 -############################################################################## -import json -import scripts.ref_results.suite_result as suite_result -import qtip.utils.dashboard.pushtoDB as push_to_db - - -def dump_suite_result(suite_name): - return suite_result.get_suite_result(suite_name) - - -def push_suite_result_to_db(suite_name, test_db_url, installer_type, node_name): - with open('results/{0}_result.json'.format(suite_name), 'r') as result_file: - j = json.load(result_file) - push_to_db.push_results_to_db(test_db_url, '{0}_test_suite'.format(suite_name), - j, installer_type, node_name) diff --git a/qtip/api/router/__init__.py b/qtip/api/router/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/qtip/api/router/__init__.py diff --git a/qtip/api/router/mapper.py b/qtip/api/router/mapper.py new file mode 100644 index 00000000..a5f029ac --- /dev/null +++ b/qtip/api/router/mapper.py @@ -0,0 +1,7 @@ +from qtip.api.handler.job_handler import Job, JobList + + +mappers = [ + (JobList, '/api/v1.0/jobs'), + (Job, '/api/v1.0/jobs/<string:id>'), +] diff --git a/qtip/runner/perftest.py b/qtip/runner/perftest.py index c6d58397..a9b54716 100644 --- a/qtip/runner/perftest.py +++ b/qtip/runner/perftest.py @@ -13,7 +13,9 @@ from benchmark import Benchmark class PerfTest(Benchmark): - """PerfTest is the driver of external performance test tools""" + """WIP(yujunz): + a perftest is the driver of external performance test tools + It is usually referred in a suite to collect performance metric""" # paths to search for perftest _paths = [path.join(p, 'perftest') for p in Benchmark._paths] diff --git a/qtip/runner/suite.py b/qtip/runner/suite.py index 4179af64..0086a20e 100644 --- a/qtip/runner/suite.py +++ b/qtip/runner/suite.py @@ -13,7 +13,10 @@ from benchmark import Benchmark class Suite(Benchmark): - """A suite is consist of one or several perf tests and produces one QPI""" + """WIP(yujunz): + a suite is consist of one or several perf tests and produces one QPI. + It must be executed as part of testplan + """ # paths to search for suites _paths = [path.join(p, 'suite') for p in Benchmark._paths] diff --git a/qtip/runner/testplan.py b/qtip/runner/testplan.py index 57f3c978..f48a7147 100644 --- a/qtip/runner/testplan.py +++ b/qtip/runner/testplan.py @@ -13,7 +13,9 @@ from benchmark import Benchmark class TestPlan(Benchmark): - """A suite is consist of one or several perf tests and produces one QPI""" + """WIP(yujunz): + a test plan is consist of test condition and several suites which can be + executed by user""" # paths to search for suites _paths = [path.join(p, 'testplan') for p in Benchmark._paths] |