aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/resources/v2/testcases.py62
-rw-r--r--api/resources/v2/testsuites.py81
-rw-r--r--api/urls.py2
-rw-r--r--yardstick/benchmark/core/testsuite.py42
4 files changed, 186 insertions, 1 deletions
diff --git a/api/resources/v2/testcases.py b/api/resources/v2/testcases.py
new file mode 100644
index 000000000..81b4aa88c
--- /dev/null
+++ b/api/resources/v2/testcases.py
@@ -0,0 +1,62 @@
+import logging
+import errno
+import os
+
+from api import ApiResource
+from yardstick.common.utils import result_handler
+from yardstick.common import constants as consts
+from yardstick.benchmark.core import Param
+from yardstick.benchmark.core.testcase import Testcase
+
+LOG = logging.getLogger(__name__)
+LOG.setLevel(logging.DEBUG)
+
+
+class V2Testcases(ApiResource):
+
+ def get(self):
+ param = Param({})
+ testcase_list = Testcase().list_all(param)
+ return result_handler(consts.API_SUCCESS, testcase_list)
+
+ def post(self):
+ return self._dispatch_post()
+
+ def upload_case(self, args):
+ try:
+ upload_file = args['file']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'file must be provided')
+
+ case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)
+
+ LOG.info('save case file')
+ upload_file.save(case_name)
+
+ return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})
+
+
+class V2Testcase(ApiResource):
+
+ def get(self, case_name):
+ case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
+
+ try:
+ with open(case_path) as f:
+ data = f.read()
+ except IOError as e:
+ if e.errno == errno.ENOENT:
+ return result_handler(consts.API_ERROR, 'case does not exist')
+
+ return result_handler(consts.API_SUCCESS, {'testcase': data})
+
+ def delete(self, case_name):
+ case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
+
+ try:
+ os.remove(case_path)
+ except IOError as e:
+ if e.errno == errno.ENOENT:
+ return result_handler(consts.API_ERROR, 'case does not exist')
+
+ return result_handler(consts.API_SUCCESS, {'testcase': case_name})
diff --git a/api/resources/v2/testsuites.py b/api/resources/v2/testsuites.py
new file mode 100644
index 000000000..ee942eff9
--- /dev/null
+++ b/api/resources/v2/testsuites.py
@@ -0,0 +1,81 @@
+import os
+import errno
+import logging
+
+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)
+
+
+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()
+
+ 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})
+
+
+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})
diff --git a/api/urls.py b/api/urls.py
index 5c7e9f7b5..2211348f3 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -52,5 +52,5 @@ urlpatterns = [
Url('/api/v2/yardstick/testsuites', 'v2_testsuites'),
Url('/api/v2/yardstick/testsuites/action', 'v2_testsuites'),
- Url('/api/v2/yardstick/testsuites/<suite_name>', 'v2_testsuites')
+ Url('/api/v2/yardstick/testsuites/<suite_name>', 'v2_testsuite')
]
diff --git a/yardstick/benchmark/core/testsuite.py b/yardstick/benchmark/core/testsuite.py
new file mode 100644
index 000000000..e3940a0ba
--- /dev/null
+++ b/yardstick/benchmark/core/testsuite.py
@@ -0,0 +1,42 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+""" Handler for yardstick command 'testcase' """
+from __future__ import absolute_import
+from __future__ import print_function
+
+import os
+import logging
+
+from yardstick.common import constants as consts
+
+LOG = logging.getLogger(__name__)
+
+
+class Testsuite(object):
+ """Testcase commands.
+
+ Set of commands to discover and display test cases.
+ """
+
+ def list_all(self, args):
+ """List existing test cases"""
+
+ testsuite_list = self._get_testsuite_file_list()
+
+ return testsuite_list
+
+ def _get_testsuite_file_list(self):
+ try:
+ testsuite_files = sorted(os.listdir(consts.TESTSUITE_DIR))
+ except OSError:
+ LOG.exception('Failed to list dir:\n%s\n', consts.TESTSUITE_DIR)
+ raise
+
+ return testsuite_files