7 from api import ApiResource
8 from yardstick.common.utils import result_handler
9 from yardstick.common import constants as consts
10 from yardstick.benchmark.core.testsuite import Testsuite
11 from yardstick.benchmark.core import Param
13 LOG = logging.getLogger(__name__)
14 LOG.setLevel(logging.DEBUG)
17 class V2Testsuites(ApiResource):
21 testsuite_list = Testsuite().list_all(param)
24 'testsuites': testsuite_list
27 return result_handler(consts.API_SUCCESS, data)
30 return self._dispatch_post()
32 def create_suite(self, args):
34 suite_name = args['name']
36 return result_handler(consts.API_ERROR, 'name must be provided')
39 testcases = args['testcases']
41 return result_handler(consts.API_ERROR, 'testcases must be provided')
43 testcases = [{'file_name': '{}.yaml'.format(t)} for t in testcases]
45 suite = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name))
47 'schema': 'yardstick:suite:0.1',
49 'test_cases_dir': 'tests/opnfv/test_cases/',
50 'test_cases': testcases
53 LOG.info('write test suite')
54 with open(suite, 'w') as f:
55 yaml.dump(suite_content, f, default_flow_style=False)
57 return result_handler(consts.API_SUCCESS, {'suite': suite_name})
60 class V2Testsuite(ApiResource):
62 def get(self, suite_name):
63 suite_path = os.path.join(consts.TESTSUITE_DIR, '{}.yaml'.format(suite_name))
65 with open(suite_path) as f:
68 if e.errno == errno.ENOENT:
69 return result_handler(consts.API_ERROR, 'suite does not exist')
71 return result_handler(consts.API_SUCCESS, {'testsuite': data})