From 75f55c05789beb4fbe2391d33349058bba4ea5c0 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 12 Jan 2017 07:50:30 +0000 Subject: Create API to get a list of all test cases JIRA: YARDSTICK-456 Currently we do not have a API to get a list of all test cases; Currently the test case info is from the comment; So I create a API to get a list of all test cases; And create a 'description' attribute to record info of a test case; And use the CLI call this API; Change-Id: Ife800600446683664097835c7b9f11899c85771d Signed-off-by: chenjiankun --- api/client.py | 37 +++++++++++++++++++++++++++++++++++++ api/resources/testcases.py | 21 +++++++++++++++++++++ api/urls.py | 1 + api/views.py | 5 +++++ 4 files changed, 64 insertions(+) create mode 100644 api/client.py create mode 100644 api/resources/testcases.py (limited to 'api') diff --git a/api/client.py b/api/client.py new file mode 100644 index 000000000..167754c39 --- /dev/null +++ b/api/client.py @@ -0,0 +1,37 @@ +############################################################################## +# Copyright (c) 2016 Huawei Technologies Co.,Ltd 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 logging +import requests + +from oslo_serialization import jsonutils + +from yardstick.common import constants as consts + +logger = logging.getLogger(__name__) + + +def post(url, data={}): + url = '{}{}'.format(consts.BASE_URL, url) + data = jsonutils.dumps(data) + headers = {'Content-Type': 'application/json'} + try: + response = requests.post(url, data=data, headers=headers) + result = response.json() + logger.debug('The result is: %s', result) + + return result + except Exception as e: + logger.exception('Failed: %s', e) + raise + + +def get(url): + url = '{}{}'.format(consts.BASE_URL, url) + response = requests.get(url) + return response.json() diff --git a/api/resources/testcases.py b/api/resources/testcases.py new file mode 100644 index 000000000..6ee15efb3 --- /dev/null +++ b/api/resources/testcases.py @@ -0,0 +1,21 @@ +# ############################################################################ +# Copyright (c) 2017 Huawei Technologies Co.,Ltd 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 yardstick.benchmark.core.testcase import Testcase +from yardstick.benchmark.core import Param +from api.utils import common as common_utils + + +def default(args): + return listAllTestcases(args) + + +def listAllTestcases(args): + param = Param(args) + testcase_list = Testcase().list_all(param) + return common_utils.result_handler(1, testcase_list) diff --git a/api/urls.py b/api/urls.py index 04b7485f1..3ccb67dbc 100644 --- a/api/urls.py +++ b/api/urls.py @@ -13,6 +13,7 @@ from api.utils.common import Url urlpatterns = [ Url('/yardstick/asynctask', views.Asynctask, 'asynctask'), + Url('/yardstick/testcases', views.Testcases, 'testcases'), Url('/yardstick/testcases/release/action', views.ReleaseAction, 'release'), Url('/yardstick/testcases/samples/action', views.SamplesAction, 'samples'), Url('/yardstick/testsuites/action', views.TestsuitesAction, 'testsuites'), diff --git a/api/views.py b/api/views.py index 0c39bfad0..9fd236fad 100644 --- a/api/views.py +++ b/api/views.py @@ -30,6 +30,11 @@ class Asynctask(ApiResource): return self._dispatch_get() +class Testcases(ApiResource): + def get(self): + return self._dispatch_get() + + class ReleaseAction(ApiResource): @swag_from(os.getcwd() + '/swagger/docs/release_action.yaml') def post(self): -- cgit 1.2.3-korg