X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=api%2Fresources%2Fv2%2Ftestsuites.py;h=ee942eff99034b6d9866733e52043b22a6ea5214;hb=acc000cff316fa9883217121a3c30b0e2145a363;hp=9a3a07a7f6898d49a2593110d5c1854f7a029515;hpb=0d77985517a40c54a38a851729bdaa3741a81059;p=yardstick.git diff --git a/api/resources/v2/testsuites.py b/api/resources/v2/testsuites.py index 9a3a07a7f..ee942eff9 100644 --- a/api/resources/v2/testsuites.py +++ b/api/resources/v2/testsuites.py @@ -1,4 +1,5 @@ import os +import errno import logging import yaml @@ -6,6 +7,8 @@ import yaml from api import ApiResource from yardstick.common.utils import result_handler from yardstick.common import constants as consts +from yardstick.benchmark.core.testsuite import Testsuite +from yardstick.benchmark.core import Param LOG = logging.getLogger(__name__) LOG.setLevel(logging.DEBUG) @@ -13,6 +16,16 @@ LOG.setLevel(logging.DEBUG) class V2Testsuites(ApiResource): + def get(self): + param = Param({}) + testsuite_list = Testsuite().list_all(param) + + data = { + 'testsuites': testsuite_list + } + + return result_handler(consts.API_SUCCESS, data) + def post(self): return self._dispatch_post() @@ -42,3 +55,27 @@ class V2Testsuites(ApiResource): yaml.dump(suite_content, f, default_flow_style=False) return result_handler(consts.API_SUCCESS, {'suite': suite_name}) + + +class V2Testsuite(ApiResource): + + def get(self, suite_name): + suite_path = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name)) + try: + with open(suite_path) as f: + data = f.read() + except IOError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'suite does not exist') + + return result_handler(consts.API_SUCCESS, {'testsuite': data}) + + def delete(self, suite_name): + suite_path = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name)) + try: + os.remove(suite_path) + except IOError as e: + if e.errno == errno.ENOENT: + return result_handler(consts.API_ERROR, 'suite does not exist') + + return result_handler(consts.API_SUCCESS, {'testsuite': suite_name})