diff options
Diffstat (limited to 'functest/api/resources')
-rw-r--r-- | functest/api/resources/v1/creds.py | 13 | ||||
-rw-r--r-- | functest/api/resources/v1/envs.py | 14 | ||||
-rw-r--r-- | functest/api/resources/v1/tasks.py | 12 | ||||
-rw-r--r-- | functest/api/resources/v1/testcases.py | 19 | ||||
-rw-r--r-- | functest/api/resources/v1/tiers.py | 22 |
5 files changed, 72 insertions, 8 deletions
diff --git a/functest/api/resources/v1/creds.py b/functest/api/resources/v1/creds.py index 45e4559f..f445017d 100644 --- a/functest/api/resources/v1/creds.py +++ b/functest/api/resources/v1/creds.py @@ -13,8 +13,11 @@ Resources to handle openstack related requests import collections import logging +import pkg_resources +import socket from flask import jsonify +from flasgger.utils import swag_from from functest.api.base import ApiResource from functest.api.common import api_utils @@ -24,16 +27,26 @@ from functest.utils.constants import CONST LOGGER = logging.getLogger(__name__) +ADDRESS = socket.gethostbyname(socket.gethostname()) +ENDPOINT_CREDS = ('http://{}:5000/api/v1/functest/openstack'.format(ADDRESS)) + class V1Creds(ApiResource): """ V1Creds Resource class""" + @swag_from( + pkg_resources.resource_filename('functest', 'api/swagger/creds.yaml'), + endpoint='{0}/credentials'.format(ENDPOINT_CREDS)) def get(self): # pylint: disable=no-self-use """ Get credentials """ os_utils.source_credentials(CONST.__getattribute__('openstack_creds')) credentials_show = OpenStack.show_credentials() return jsonify(credentials_show) + @swag_from( + pkg_resources.resource_filename('functest', + 'api/swagger/creds_action.yaml'), + endpoint='{0}/action'.format(ENDPOINT_CREDS)) def post(self): """ Used to handle post request """ return self._dispatch_post() diff --git a/functest/api/resources/v1/envs.py b/functest/api/resources/v1/envs.py index 8020544f..65e61c4b 100644 --- a/functest/api/resources/v1/envs.py +++ b/functest/api/resources/v1/envs.py @@ -10,23 +10,37 @@ Resources to handle environment related requests """ +import pkg_resources +import socket + import IPy from flask import jsonify +from flasgger.utils import swag_from from functest.api.base import ApiResource from functest.api.common import api_utils from functest.cli.commands.cli_env import Env import functest.utils.functest_utils as ft_utils +ADDRESS = socket.gethostbyname(socket.gethostname()) +ENDPOINT_ENVS = ('http://{}:5000/api/v1/functest/envs'.format(ADDRESS)) + class V1Envs(ApiResource): """ V1Envs Resource class""" + @swag_from( + pkg_resources.resource_filename('functest', 'api/swagger/envs.yaml'), + endpoint=ENDPOINT_ENVS) def get(self): # pylint: disable=no-self-use """ Get environment """ environment_show = Env().show() return jsonify(environment_show) + @swag_from( + pkg_resources.resource_filename('functest', + 'api/swagger/envs_action.yaml'), + endpoint='{0}/action'.format(ENDPOINT_ENVS)) def post(self): """ Used to handle post request """ return self._dispatch_post() diff --git a/functest/api/resources/v1/tasks.py b/functest/api/resources/v1/tasks.py index f099918f..6bf625a8 100644 --- a/functest/api/resources/v1/tasks.py +++ b/functest/api/resources/v1/tasks.py @@ -15,9 +15,11 @@ import errno import json import logging import os +import pkg_resources import uuid from flask import jsonify +from flasgger.utils import swag_from from functest.api.base import ApiResource from functest.api.common import api_utils @@ -31,6 +33,8 @@ LOGGER = logging.getLogger(__name__) class V1Task(ApiResource): """ V1Task Resource class""" + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/task.yaml')) def get(self, task_id): # pylint: disable=no-self-use """ GET the result of the task id """ try: @@ -66,6 +70,8 @@ class V1Task(ApiResource): class V1TaskLog(ApiResource): """ V1TaskLog Resource class""" + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/task_log.yaml')) def get(self, task_id): # pylint: disable=no-self-use """ GET the log of the task id """ try: @@ -80,11 +86,15 @@ class V1TaskLog(ApiResource): return api_utils.result_handler(status=1, data='No such task id') task_log_dir = CONST.__getattribute__('dir_results') + # pylint: disable=maybe-no-member + index = int(self._get_args().get('index', 0)) try: with open(os.path.join(task_log_dir, '{}.log'.format(task_id)), 'r') as log_file: + log_file.seek(index) data = log_file.readlines() + index = log_file.tell() except OSError as err: if err.errno == errno.ENOENT: return api_utils.result_handler( @@ -93,7 +103,7 @@ class V1TaskLog(ApiResource): return api_utils.result_handler( status=1, data='Error with log file') - return_data = {'data': data} + return_data = {'data': data, 'index': index} switcher = {'IN PROGRESS': 0, 'FAIL': 1, 'FINISHED': 2} diff --git a/functest/api/resources/v1/testcases.py b/functest/api/resources/v1/testcases.py index cc2d4e19..7cc70bbc 100644 --- a/functest/api/resources/v1/testcases.py +++ b/functest/api/resources/v1/testcases.py @@ -13,11 +13,14 @@ Resources to handle testcase related requests import logging import os +import re import pkg_resources +import socket import uuid import ConfigParser from flask import jsonify +from flasgger.utils import swag_from from functest.api.base import ApiResource from functest.api.common import api_utils, thread @@ -28,20 +31,30 @@ import functest.utils.functest_utils as ft_utils LOGGER = logging.getLogger(__name__) +ADDRESS = socket.gethostbyname(socket.gethostname()) +ENDPOINT_TESTCASES = ('http://{}:5000/api/v1/functest/testcases' + .format(ADDRESS)) + class V1Testcases(ApiResource): """ V1Testcases Resource class""" + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/testcases.yaml')) def get(self): # pylint: disable=no-self-use """ GET all testcases """ testcases_list = Testcase().list() - result = {'testcases': testcases_list.split('\n')[:-1]} + result = {'testcases': re.split(' |\n ', testcases_list)[1:]} return jsonify(result) class V1Testcase(ApiResource): """ V1Testcase Resource class""" + @swag_from( + pkg_resources.resource_filename('functest', + 'api/swagger/testcase.yaml'), + endpoint='{0}/<testcase_name>'.format(ENDPOINT_TESTCASES)) def get(self, testcase_name): # pylint: disable=no-self-use """ GET the info of one testcase""" testcase = Testcase().show(testcase_name) @@ -61,6 +74,10 @@ class V1Testcase(ApiResource): result.update({'dependency': dependency_dict}) return jsonify(result) + @swag_from( + pkg_resources.resource_filename('functest', + 'api/swagger/testcase_run.yaml'), + endpoint='{0}/action'.format(ENDPOINT_TESTCASES)) def post(self): """ Used to handle post request """ return self._dispatch_post() diff --git a/functest/api/resources/v1/tiers.py b/functest/api/resources/v1/tiers.py index 4f4849e9..523df130 100644 --- a/functest/api/resources/v1/tiers.py +++ b/functest/api/resources/v1/tiers.py @@ -11,9 +11,11 @@ Resources to handle tier related requests """ +import pkg_resources import re from flask import jsonify +from flasgger.utils import swag_from from functest.api.base import ApiResource from functest.api.common import api_utils @@ -23,6 +25,8 @@ from functest.cli.commands.cli_tier import Tier class V1Tiers(ApiResource): """ V1Tiers Resource class """ + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/tiers.yaml')) def get(self): # pylint: disable=no-self-use """ GET all tiers """ @@ -31,7 +35,7 @@ class V1Tiers(ApiResource): data = [i.strip() for i in data if i != ''] data_dict = dict() for i in range(len(data) / 2): - one_data = {data[i * 2]: data[i * 2 + 1]} + one_data = {data[i * 2].lstrip('- ').rstrip(':'): data[i * 2 + 1]} if i == 0: data_dict = one_data else: @@ -43,16 +47,19 @@ class V1Tiers(ApiResource): class V1Tier(ApiResource): """ V1Tier Resource class """ + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/tier.yaml')) def get(self, tier_name): # pylint: disable=no-self-use """ GET the info of one tier """ - testcases = Tier().gettests(tier_name) - if not testcases: + tier_info = Tier().show(tier_name) + if not tier_info: 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') + tier_info.__dict__.pop('skipped_tests_array') + testcases = Tier().gettests(tier_name) result = {'tier': tier_name, 'testcases': testcases} result.update(tier_info.__dict__) return jsonify(result) @@ -61,12 +68,15 @@ class V1Tier(ApiResource): class V1TestcasesinTier(ApiResource): """ V1TestcasesinTier Resource class """ + @swag_from(pkg_resources.resource_filename( + 'functest', 'api/swagger/testcases_in_tier.yaml')) def get(self, tier_name): # pylint: disable=no-self-use """ GET all testcases within given tier """ - testcases = Tier().gettests(tier_name) - if not testcases: + tier_info = Tier().show(tier_name) + if not tier_info: return api_utils.result_handler( status=1, data="The tier with name '%s' does not exist." % tier_name) + testcases = Tier().gettests(tier_name) result = {'tier': tier_name, 'testcases': testcases} return jsonify(result) |