Create API to run test suite 07/26407/4
authorJingLu5 <lvjing5@huawei.com>
Thu, 22 Dec 2016 04:07:55 +0000 (12:07 +0800)
committerJingLu5 <lvjing5@huawei.com>
Tue, 10 Jan 2017 15:31:35 +0000 (15:31 +0000)
JIRA: YARDSTICK-475

This API will be used to run test suite files in the test/opnfv/test_suites directory

Change-Id: I208edf9abed62fd6436de988ac85bfe99c4d01bd
Signed-off-by: JingLu5 <lvjing5@huawei.com>
api/conf.py
api/resources/testsuites_action.py [new file with mode: 0644]
api/swagger/docs/release_action.yaml [moved from api/swagger/docs/testcases.yaml with 100% similarity]
api/swagger/docs/testsuites_action.yaml [new file with mode: 0644]
api/swagger/models.py
api/urls.py
api/views.py

index df44042..3d9d190 100644 (file)
@@ -24,4 +24,6 @@ TEST_CASE_PRE = 'opnfv_yardstick_'
 
 TEST_SUITE_PATH = '../tests/opnfv/test_suites/'
 
+TEST_SUITE_PRE = 'opnfv_'
+
 OUTPUT_CONFIG_FILE_PATH = '/etc/yardstick/yardstick.conf'
diff --git a/api/resources/testsuites_action.py b/api/resources/testsuites_action.py
new file mode 100644 (file)
index 0000000..f833dc2
--- /dev/null
@@ -0,0 +1,45 @@
+##############################################################################
+# 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
+##############################################################################
+
+"""Yardstick test suite api action"""
+
+from __future__ import absolute_import
+import uuid
+import os
+import logging
+
+from api import conf
+from api.utils import common as common_utils
+
+logger = logging.getLogger(__name__)
+
+
+def runTestSuite(args):
+    try:
+        opts = args.get('opts', {})
+        testsuite = args['testsuite']
+    except KeyError:
+        return common_utils.error_handler('Lack of testsuite argument')
+
+    if 'suite' not in opts:
+        opts['suite'] = 'true'
+
+    testsuite = os.path.join(conf.TEST_SUITE_PATH,
+                             conf.TEST_SUITE_PRE + testsuite + '.yaml')
+
+    task_id = str(uuid.uuid4())
+
+    command_list = ['task', 'start']
+    command_list = common_utils.get_command_list(command_list, opts, testsuite)
+    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/swagger/docs/testsuites_action.yaml b/api/swagger/docs/testsuites_action.yaml
new file mode 100644 (file)
index 0000000..ebf01e4
--- /dev/null
@@ -0,0 +1,50 @@
+TestSuites Actions
+
+This API may offer many actions, including runTestSuite
+
+action: runTestSuite
+This api offer the interface to run a test suite in yardstick
+we will return a task_id for querying
+you can use the returned task_id to get the result data
+---
+tags:
+  - Testsuite Action
+parameters:
+  - in: body
+    name: body
+    description: this is the input json dict
+    schema:
+      id: TestSuiteActionModel
+      required:
+        - action
+        - args
+      properties:
+        action:
+          type: string
+          description: this is action for testsuite
+          default: runTestSuite
+        args:
+          schema:
+            id: TestSuiteActionArgsModel
+            required:
+              - testsuite
+            properties:
+              testsuite:
+                type: string
+                description: this is the test suite name
+                default: smoke
+              opts:
+                schema:
+                  id: TestSuiteActionArgsOptsModel
+responses:
+  200:
+    description: A result json dict
+    schema:
+      id: result
+      properties:
+        status:
+          type: string
+          default: success
+        result:
+          type: string
+          description: task_id of this task
index 7c65fbb..9a0157e 100644 (file)
@@ -42,6 +42,37 @@ class TestCaseActionModel:
     }
 
 
+# for testsuite/action runTestSuite action
+@swagger.model
+class TestSuiteActionArgsOptsTaskArgModel:
+    resource_fields = {
+    }
+
+
+@swagger.model
+class TestSuiteActionArgsOptsModel:
+    resource_fields = {
+        'task-args': TestSuiteActionArgsOptsTaskArgModel,
+        'keep-deploy': fields.String,
+        'suite': fields.String
+    }
+
+@swagger.model
+class TestSuiteActionArgsModel:
+    resource_fields = {
+        'testsuite': fields.String,
+        'opts': TestSuiteActionArgsOptsModel
+    }
+
+
+@swagger.model
+class TestSuiteActionModel:
+    resource_fields = {
+        'action': fields.String,
+        'args': TestSuiteActionArgsModel
+    }
+
+
 # for results
 @swagger.model
 class ResultModel:
index 0fffd12..7f9f0bb 100644 (file)
@@ -13,6 +13,7 @@ from api.utils.common import Url
 urlpatterns = [
     Url('/yardstick/testcases/release/action', views.ReleaseAction, 'release'),
     Url('/yardstick/testcases/samples/action', views.SamplesAction, 'samples'),
+    Url('/yardstick/testsuites/action', views.TestsuitesAction, 'testsuites'),
     Url('/yardstick/results', views.Results, 'results'),
     Url('/yardstick/env/action', views.EnvAction, 'env')
 ]
index ee13b47..bdff7c0 100644 (file)
@@ -25,7 +25,7 @@ TestCaseActionArgsOptsTaskArgModel = models.TestCaseActionArgsOptsTaskArgModel
 
 
 class ReleaseAction(ApiResource):
-    @swag_from(os.getcwd() + '/swagger/docs/testcases.yaml')
+    @swag_from(os.getcwd() + '/swagger/docs/release_action.yaml')
     def post(self):
         return self._dispatch_post()
 
@@ -35,6 +35,18 @@ class SamplesAction(ApiResource):
         return self._dispatch_post()
 
 
+TestSuiteActionModel = models.TestSuiteActionModel
+TestSuiteActionArgsModel = models.TestSuiteActionArgsModel
+TestSuiteActionArgsOptsModel = models.TestSuiteActionArgsOptsModel
+TestSuiteActionArgsOptsTaskArgModel = models.TestSuiteActionArgsOptsTaskArgModel
+
+
+class TestsuitesAction(ApiResource):
+    @swag_from(os.getcwd() + '/swagger/docs/testsuites_action.yaml')
+    def post(self):
+        return self._dispatch_post()
+
+
 ResultModel = models.ResultModel