diff options
author | Jing Lu <lvjing5@huawei.com> | 2016-12-01 00:52:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-12-01 00:52:54 +0000 |
commit | f62146fc98322caa63c658b17589cfff280471fb (patch) | |
tree | 4046e9539acc8efc3d442fb7033b2667137d05c9 /api | |
parent | 462f25c8e950110a1624909d4f79ef4219005ba2 (diff) | |
parent | 1558bcf48bdba369187d7cb07482f2fbcc6f4feb (diff) |
Merge "Use flask jsonify method to return json result"
Diffstat (limited to 'api')
-rw-r--r-- | api/actions/test.py | 14 | ||||
-rw-r--r-- | api/utils/common.py | 7 |
2 files changed, 6 insertions, 15 deletions
diff --git a/api/actions/test.py b/api/actions/test.py index b1dc212c2..fda0ffd32 100644 --- a/api/actions/test.py +++ b/api/actions/test.py @@ -7,7 +7,6 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## import uuid -import json import os import logging @@ -22,12 +21,7 @@ def runTestCase(args): opts = args.get('opts', {}) testcase = args['testcase'] except KeyError: - logger.error('Lack of testcase argument') - result = { - 'status': 'error', - 'message': 'need testcase name' - } - return json.dumps(result) + return common_utils.error_handler('Lack of testcase argument') testcase = os.path.join(conf.TEST_CASE_PATH, conf.TEST_CASE_PRE + testcase + '.yaml') @@ -41,8 +35,4 @@ def runTestCase(args): logger.debug('Start to execute command list') common_utils.exec_command_task(command_list, task_id) - result = { - 'status': 'success', - 'task_id': task_id - } - return json.dumps(result) + return common_utils.result_handler('success', task_id) diff --git a/api/utils/common.py b/api/utils/common.py index 09cfc04d4..e3e64a72b 100644 --- a/api/utils/common.py +++ b/api/utils/common.py @@ -8,7 +8,8 @@ ############################################################################## import collections import logging -import json + +from flask import jsonify from api.utils.daemonthread import DaemonThread from yardstick.cmd.cli import YardstickCLI @@ -50,7 +51,7 @@ def error_handler(message): 'status': 'error', 'message': message } - return json.dumps(result) + return jsonify(result) def result_handler(status, data): @@ -58,7 +59,7 @@ def result_handler(status, data): 'status': status, 'result': data } - return json.dumps(result) + return jsonify(result) class Url(object): |