1 ##############################################################################
2 # Copyright (c) 2016 Juan Qiu and others
3 # juan_ qiu@tongji.edu.cn
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 ##############################################################################
14 import yardstick.common.utils as utils
16 LOG = logging.getLogger(__name__)
18 operation_conf_path = pkg_resources.resource_filename(
19 "yardstick.benchmark.scenarios.availability",
20 "operation_conf.yaml")
23 class OperationMgr(object):
26 self._operation_list = []
28 def init_operations(self, operation_cfgs, context):
29 LOG.debug("operationMgr confg: %s" % operation_cfgs)
30 for cfg in operation_cfgs:
31 operation_type = cfg['operation_type']
32 operation_cls = BaseOperation.get_operation_cls(operation_type)
33 operation_ins = operation_cls(cfg, context)
34 operation_ins.key = cfg['key']
36 self._operation_list.append(operation_ins)
38 def __getitem__(self, item):
39 for obj in self._operation_list:
42 raise KeyError("No such operation instance of key - %s" % item)
45 for _instance in self._operation_list:
49 class BaseOperation(object):
53 def __init__(self, config, context):
54 if not BaseOperation.operation_cfgs:
55 with open(operation_conf_path) as stream:
56 BaseOperation.operation_cfgs = yaml.load(stream)
59 self._context = context
62 def get_operation_cls(type):
63 '''return operation instance of specified type'''
65 for operation_cls in utils.itersubclasses(BaseOperation):
66 if operation_type == operation_cls.__operation__type__:
68 raise RuntimeError("No such runner_type %s" % operation_type)
70 def get_script_fullpath(self, path):
71 base_path = os.path.dirname(operation_conf_path)
72 return os.path.join(base_path, path)