aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2017-07-21 01:15:05 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-21 01:15:05 +0000
commit0d77985517a40c54a38a851729bdaa3741a81059 (patch)
tree2fb6fbc2660f55f9a9945437fc7ee67cace714ea /api/resources/v2
parente8be89e06808273e5badc913af1781afb3dbdcb4 (diff)
parent84d6ac910706e61fbe420f0813733ffdfce34f75 (diff)
Merge "Add API(v2) to create test suite"
Diffstat (limited to 'api/resources/v2')
-rw-r--r--api/resources/v2/testsuites.py44
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})