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 import Param
19 from yardstick.benchmark.core.testcase import Testcase
21 LOG = logging.getLogger(__name__)
22 LOG.setLevel(logging.DEBUG)
25 class V2Testcases(ApiResource):
29 testcase_list = Testcase().list_all(param)
30 return result_handler(consts.API_SUCCESS, {'testcases': testcase_list})
33 return self._dispatch_post()
35 def upload_case(self, args):
37 upload_file = args['file']
39 return result_handler(consts.API_ERROR, 'file must be provided')
41 case_name = os.path.join(consts.TESTCASE_DIR, upload_file.filename)
43 LOG.info('save case file')
44 upload_file.save(case_name)
46 return result_handler(consts.API_SUCCESS, {'testcase': upload_file.filename})
49 class V2Testcase(ApiResource):
51 def get(self, case_name):
52 case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
55 with open(case_path) as f:
58 if e.errno == errno.ENOENT:
59 return result_handler(consts.API_ERROR, 'case does not exist')
61 options = {k: {'description': '', 'type': v.__class__.__name__}
62 for k, v in jinja2schema.infer(data).items()}
63 # [('segmentation_id', < scalar >), ('image', < string >), ('provider', < scalar >),
64 # ('physical_network', < string >), ('packetsize', < number >)]
65 for k, v in options.items():
66 if k == 'segmentation_id':
67 options[k]['type'] = 'Number'
69 options[k]['type'] = 'String'
70 return result_handler(consts.API_SUCCESS, {'testcase': data, 'args': options})
72 def delete(self, case_name):
73 case_path = os.path.join(consts.TESTCASE_DIR, '{}.yaml'.format(case_name))
78 if e.errno == errno.ENOENT:
79 return result_handler(consts.API_ERROR, 'case does not exist')
81 return result_handler(consts.API_SUCCESS, {'testcase': case_name})