diff options
Diffstat (limited to 'functest/api/resources/v1')
-rw-r--r-- | functest/api/resources/v1/envs.py | 9 | ||||
-rw-r--r-- | functest/api/resources/v1/tasks.py | 14 | ||||
-rw-r--r-- | functest/api/resources/v1/testcases.py | 16 | ||||
-rw-r--r-- | functest/api/resources/v1/tiers.py | 11 |
4 files changed, 36 insertions, 14 deletions
diff --git a/functest/api/resources/v1/envs.py b/functest/api/resources/v1/envs.py index fb76fa63..8020544f 100644 --- a/functest/api/resources/v1/envs.py +++ b/functest/api/resources/v1/envs.py @@ -33,10 +33,11 @@ class V1Envs(ApiResource): def prepare(self, args): # pylint: disable=no-self-use, unused-argument """ Prepare environment """ - try: - ft_utils.execute_command("prepare_env start") - except Exception as err: # pylint: disable=broad-except - return api_utils.result_handler(status=1, data=str(err)) + + result_env = ft_utils.execute_command("prepare_env start") + if not result_env == 0: + return api_utils.result_handler( + status=1, data="Failed to prepare env") return api_utils.result_handler( status=0, data="Prepare env successfully") diff --git a/functest/api/resources/v1/tasks.py b/functest/api/resources/v1/tasks.py index e05db51b..f099918f 100644 --- a/functest/api/resources/v1/tasks.py +++ b/functest/api/resources/v1/tasks.py @@ -50,12 +50,15 @@ class V1Task(ApiResource): if status not in ['IN PROGRESS', 'FAIL', 'FINISHED']: return api_utils.result_handler(status=1, data='internal server error') + + switcher = {'IN PROGRESS': 0, 'FAIL': 1, 'FINISHED': 2} if status == 'IN PROGRESS': - result = {'status': status, 'result': ''} + result = {'status': switcher.get(status), 'result': ''} elif status == 'FAIL': - result = {'status': status, 'error': task.error} + result = {'status': switcher.get(status), 'error': task.error} else: - result = {'status': status, 'result': json.loads(task.result)} + result = {'status': switcher.get(status), + 'result': json.loads(task.result)} return jsonify(result) @@ -92,4 +95,7 @@ class V1TaskLog(ApiResource): return_data = {'data': data} - return api_utils.result_handler(status=task.status, data=return_data) + switcher = {'IN PROGRESS': 0, 'FAIL': 1, 'FINISHED': 2} + + return api_utils.result_handler(status=switcher.get(task.status), + data=return_data) diff --git a/functest/api/resources/v1/testcases.py b/functest/api/resources/v1/testcases.py index d708cf37..b7d7b4aa 100644 --- a/functest/api/resources/v1/testcases.py +++ b/functest/api/resources/v1/testcases.py @@ -17,7 +17,7 @@ import pkg_resources import uuid import ConfigParser -from flask import abort, jsonify +from flask import jsonify from functest.api.base import ApiResource from functest.api.common import api_utils, thread @@ -46,8 +46,11 @@ class V1Testcase(ApiResource): """ GET the info of one testcase""" testcase = Testcase().show(testcase_name) if not testcase: - abort(404, "The test case '%s' does not exist or is not supported" - % testcase_name) + return api_utils.result_handler( + status=1, + data="The test case '%s' does not exist or is not supported" + % testcase_name) + testcase_info = api_utils.change_obj_to_dict(testcase) dependency_dict = api_utils.change_obj_to_dict( testcase_info.get('dependency')) @@ -70,6 +73,13 @@ class V1Testcase(ApiResource): return api_utils.result_handler( status=1, data='testcase name must be provided') + testcase = Testcase().show(case_name) + if not testcase: + return api_utils.result_handler( + status=1, + data="The test case '%s' does not exist or is not supported" + % case_name) + task_id = str(uuid.uuid4()) task_args = {'testcase': case_name, 'task_id': task_id} diff --git a/functest/api/resources/v1/tiers.py b/functest/api/resources/v1/tiers.py index 71a98bea..4f4849e9 100644 --- a/functest/api/resources/v1/tiers.py +++ b/functest/api/resources/v1/tiers.py @@ -13,9 +13,10 @@ Resources to handle tier related requests import re -from flask import abort, jsonify +from flask import jsonify from functest.api.base import ApiResource +from functest.api.common import api_utils from functest.cli.commands.cli_tier import Tier @@ -46,7 +47,9 @@ class V1Tier(ApiResource): """ GET the info of one tier """ testcases = Tier().gettests(tier_name) if not testcases: - abort(404, "The tier with name '%s' does not exist." % tier_name) + return api_utils.result_handler( + status=1, + data="The tier with name '%s' does not exist." % tier_name) tier_info = Tier().show(tier_name) tier_info.__dict__.pop('name') tier_info.__dict__.pop('tests_array') @@ -62,6 +65,8 @@ class V1TestcasesinTier(ApiResource): """ GET all testcases within given tier """ testcases = Tier().gettests(tier_name) if not testcases: - abort(404, "The tier with name '%s' does not exist." % tier_name) + return api_utils.result_handler( + status=1, + data="The tier with name '%s' does not exist." % tier_name) result = {'tier': tier_name, 'testcases': testcases} return jsonify(result) |