Add API(v2) to add suite to task 11/37811/2
authorchenjiankun <chenjiankun1@huawei.com>
Thu, 20 Jul 2017 01:56:24 +0000 (01:56 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Fri, 21 Jul 2017 01:16:21 +0000 (01:16 +0000)
JIRA: YARDSTICK-740

API: /api/v2/yardstick/tasks/<task_id>
METHOD: PUT
PARAMS:
{
    'action': 'add_suite',
    'args': {
        'suite_name': 'opnfv_smoke',
        'suite_content': suite_content
    }
}

Change-Id: I1f81c45f143b2fea636cb87f60f2f394bf1380b1
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/resources/v2/tasks.py

index 26da671..668f764 100644 (file)
@@ -164,3 +164,26 @@ class V2Task(ApiResource):
         task_handler.update_attr(task_id, task_update_data)
 
         return result_handler(consts.API_SUCCESS, {'uuid': task_id})
+
+    def add_suite(self, args):
+        task_id = args['task_id']
+        try:
+            name = args['suite_name']
+        except KeyError:
+            return result_handler(consts.API_ERROR, 'suite_name must be provided')
+
+        try:
+            content = args['suite_content']
+        except KeyError:
+            return result_handler(consts.API_ERROR, 'suite_content must be provided')
+
+        LOG.info('update suite info in task')
+        task_handler = V2TaskHandler()
+        task_update_data = {
+            'case_name': name,
+            'content': content,
+            'suite': True
+        }
+        task_handler.update_attr(task_id, task_update_data)
+
+        return result_handler(consts.API_SUCCESS, {'uuid': task_id})