Add API to run test case under samples directory 69/25169/3
authorchenjiankun <chenjiankun1@huawei.com>
Tue, 29 Nov 2016 17:53:25 +0000 (17:53 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Thu, 1 Dec 2016 02:16:06 +0000 (02:16 +0000)
JIRA: YARDSTICK-432

Change-Id: I8ca6409449e2b960ac9f48c8eb8a6ae9959a4fc8
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/actions/samples.py [new file with mode: 0644]
api/conf.py
api/urls.py
api/views.py

diff --git a/api/actions/samples.py b/api/actions/samples.py
new file mode 100644 (file)
index 0000000..545447a
--- /dev/null
@@ -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)
index e1da4ab..df44042 100644 (file)
@@ -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/'
index 323e5cb..50be91e 100644 (file)
@@ -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')
 ]
index 065de67..f899251 100644 (file)
@@ -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)