diff options
author | chenjiankun <chenjiankun1@huawei.com> | 2017-07-20 04:04:40 +0000 |
---|---|---|
committer | chenjiankun <chenjiankun1@huawei.com> | 2017-07-20 04:04:40 +0000 |
commit | 84d6ac910706e61fbe420f0813733ffdfce34f75 (patch) | |
tree | 703eeea305ae0184f579c3412232fc4550ed5ec1 | |
parent | df77b6585cb54d2e4691b946ea1bc9cca637c108 (diff) |
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 <chenjiankun1@huawei.com>
-rw-r--r-- | api/resources/v2/testsuites.py | 44 |
1 files changed, 44 insertions, 0 deletions
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}) |