From 84d6ac910706e61fbe420f0813733ffdfce34f75 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Thu, 20 Jul 2017 04:04:40 +0000 Subject: Add API(v2) to create test suite JIRA: YARDSTICK-746 API: /api/v2/yardstick/testsuites/action METHOD: POST PARAMS: { 'action': 'create_suite', 'args': { 'name': 'case_name', 'testcases': [ 'opnfv_yardstick_tc002' ] } } Change-Id: I7e07c599e64e7eedda274c72344e394f5535f055 Signed-off-by: chenjiankun --- api/resources/v2/testsuites.py | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 api/resources/v2/testsuites.py (limited to 'api') diff --git a/api/resources/v2/testsuites.py b/api/resources/v2/testsuites.py new file mode 100644 index 000000000..9a3a07a7f --- /dev/null +++ b/api/resources/v2/testsuites.py @@ -0,0 +1,44 @@ +import os +import logging + +import yaml + +from api import ApiResource +from yardstick.common.utils import result_handler +from yardstick.common import constants as consts + +LOG = logging.getLogger(__name__) +LOG.setLevel(logging.DEBUG) + + +class V2Testsuites(ApiResource): + + def post(self): + return self._dispatch_post() + + def create_suite(self, args): + try: + suite_name = args['name'] + except KeyError: + return result_handler(consts.API_ERROR, 'name must be provided') + + try: + testcases = args['testcases'] + except KeyError: + return result_handler(consts.API_ERROR, 'testcases must be provided') + + testcases = [{'file_name': '{}.yaml'.format(t)} for t in testcases] + + suite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name)) + suite_content = { + 'schema': 'yardstick:suite:0.1', + 'name': suite_name, + 'test_cases_dir': 'tests/opnfv/test_cases/', + 'test_cases': testcases + } + + LOG.info('write test suite') + with open(suite, 'w') as f: + yaml.dump(suite_content, f, default_flow_style=False) + + return result_handler(consts.API_SUCCESS, {'suite': suite_name}) -- cgit 1.2.3-korg