summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/actions/samples.py37
-rw-r--r--api/conf.py2
-rw-r--r--api/urls.py1
-rw-r--r--api/views.py13
4 files changed, 53 insertions, 0 deletions
diff --git a/api/actions/samples.py b/api/actions/samples.py
new file mode 100644
index 000000000..545447aec
--- /dev/null
+++ b/api/actions/samples.py
@@ -0,0 +1,37 @@
+##############################################################################
+# Copyright (c) 2016 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
+##############################################################################
+import uuid
+import os
+import logging
+
+from api import conf
+from api.utils import common as common_utils
+
+logger = logging.getLogger(__name__)
+
+
+def runTestCase(args):
+ try:
+ opts = args.get('opts', {})
+ testcase = args['testcase']
+ except KeyError:
+ return common_utils.error_handler('Lack of testcase argument')
+
+ testcase = os.path.join(conf.SAMPLE_PATH, testcase + '.yaml')
+
+ task_id = str(uuid.uuid4())
+
+ command_list = ['task', 'start']
+ command_list = common_utils.get_command_list(command_list, opts, testcase)
+ logger.debug('The command_list is: %s', command_list)
+
+ logger.debug('Start to execute command list')
+ common_utils.exec_command_task(command_list, task_id)
+
+ return common_utils.result_handler('success', task_id)
diff --git a/api/conf.py b/api/conf.py
index e1da4aba0..df44042b1 100644
--- a/api/conf.py
+++ b/api/conf.py
@@ -18,6 +18,8 @@ TEST_ACTION = ['runTestCase']
TEST_CASE_PATH = '../tests/opnfv/test_cases/'
+SAMPLE_PATH = '../samples/'
+
TEST_CASE_PRE = 'opnfv_yardstick_'
TEST_SUITE_PATH = '../tests/opnfv/test_suites/'
diff --git a/api/urls.py b/api/urls.py
index 323e5cb9f..50be91ead 100644
--- a/api/urls.py
+++ b/api/urls.py
@@ -12,6 +12,7 @@ from api.utils.common import Url
urlpatterns = [
Url('/yardstick/testcases/release/action', views.Release, 'release'),
+ Url('/yardstick/testcases/samples/action', views.Samples, 'samples'),
Url('/yardstick/results', views.Results, 'results'),
Url('/yardstick/env/action', views.Env, 'env')
]
diff --git a/api/views.py b/api/views.py
index 065de673b..f899251dd 100644
--- a/api/views.py
+++ b/api/views.py
@@ -13,6 +13,7 @@ from flask_restful import Resource
from api.utils import common as common_utils
from api.actions import test as test_action
+from api.actions import samples as samples_action
from api.actions import result as result_action
from api.actions import env as env_action
@@ -31,6 +32,18 @@ class Release(Resource):
return common_utils.error_handler('Wrong action')
+class Samples(Resource):
+ def post(self):
+ action = common_utils.translate_to_str(request.json.get('action', ''))
+ args = common_utils.translate_to_str(request.json.get('args', {}))
+ logger.debug('Input args is: action: %s, args: %s', action, args)
+
+ try:
+ return getattr(samples_action, action)(args)
+ except AttributeError:
+ return common_utils.error_handler('Wrong action')
+
+
class Results(Resource):
def get(self):
args = common_utils.translate_to_str(request.args)