1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from api import ApiResource
16 from yardstick.common.utils import result_handler
17 from yardstick.common import constants as consts
18 from yardstick.benchmark.core.testsuite import Testsuite
19 from yardstick.benchmark.core import Param
21 LOG = logging.getLogger(__name__)
22 LOG.setLevel(logging.DEBUG)
25 class V2Testsuites(ApiResource):
29 testsuite_list = Testsuite().list_all(param)
32 'testsuites': testsuite_list
35 return result_handler(consts.API_SUCCESS, data)
38 return self._dispatch_post()
40 def create_suite(self, args):
42 suite_name = args['name']
44 return result_handler(consts.API_ERROR, 'name must be provided')
47 testcases = args['testcases']
49 return result_handler(consts.API_ERROR, 'testcases must be provided')
51 testcases = [{'file_name': '{}.yaml'.format(t)} for t in testcases]
53 suite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name))
55 'schema': 'yardstick:suite:0.1',
57 'test_cases_dir': 'tests/opnfv/test_cases/',
58 'test_cases': testcases
61 LOG.info('write test suite')
62 with open(suite, 'w') as f:
63 yaml.dump(suite_content, f, default_flow_style=False)
65 return result_handler(consts.API_SUCCESS, {'suite': suite_name})
68 class V2Testsuite(ApiResource):
70 def get(self, suite_name):
71 suite_path = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name))
73 with open(suite_path) as f:
76 if e.errno == errno.ENOENT:
77 return result_handler(consts.API_ERROR, 'suite does not exist')
79 return result_handler(consts.API_SUCCESS, {'testsuite': data})
81 def delete(self, suite_name):
82 suite_path = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name))
86 if e.errno == errno.ENOENT:
87 return result_handler(consts.API_ERROR, 'suite does not exist')
89 return result_handler(consts.API_SUCCESS, {'testsuite': suite_name})