aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v1/testsuites.py
blob: 3e14670b4ec91de95f5c0d7853d8ba79ae54b770 (plain)
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold }
##############################################################################
# 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
##############################################################################
from __future__ import absolute_import
import uuid
import os
import logging

from flasgger.utils import swag_from

from api import ApiResource
from api.utils.thread import TaskThread
from yardstick.common import constants as consts
from yardstick.common.utils import result_handler
from yardstick.benchmark.core import Param
from yardstick.benchmark.core.task import Task
from api.swagger import models
from api.database.v1.handlers import TasksHandler

LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)


TestSuiteActionModel = models.TestSuiteActionModel
TestSuiteActionArgsModel = models.TestSuiteActionArgsModel
TestSuiteActionArgsOptsModel = models.TestSuiteActionArgsOptsModel
TestSuiteActionArgsOptsTaskArgModel = \
    models.TestSuiteActionArgsOptsTaskArgModel


class V1Testsuite(ApiResource):

    @swag_from(os.path.join(consts.REPOS_DIR,
                            'api/swagger/docs/testsuites_action.yaml'))
    def post(self):
        return self._dispatch_post()

    def run_test_suite(self, args):
        try:
            name = args['testsuite']
        except KeyError:
            return result_handler(consts.API_ERROR,
                                  'testsuite must be provided')

        testsuite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(name))

        task_id = str(uuid.uuid4())

        task_args = {
            'inputfile': [testsuite],
            'task_id': task_id,
            'suite': True
        }
        task_args.update(args.get('opts', {}))

        param = Param(task_args)
        task_thread = TaskThread(Task().start, param, TasksHandler())
        task_thread.start()

        return result_handler(consts.API_SUCCESS, {'task_id': task_id})