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 ##############################################################################
9 from __future__ import absolute_import
15 import yardstick.common.utils as utils
17 LOG = logging.getLogger(__name__)
19 operation_conf_path = pkg_resources.resource_filename(
20 "yardstick.benchmark.scenarios.availability",
21 "operation_conf.yaml")
24 class OperationMgr(object):
27 self._operation_list = []
29 def init_operations(self, operation_cfgs, context):
30 LOG.debug("operationMgr confg: %s", operation_cfgs)
31 for cfg in operation_cfgs:
32 operation_type = cfg['operation_type']
33 operation_cls = BaseOperation.get_operation_cls(operation_type)
34 operation_ins = operation_cls(cfg, context)
35 operation_ins.key = cfg['key']
37 self._operation_list.append(operation_ins)
39 def __getitem__(self, item):
40 for obj in self._operation_list:
43 raise KeyError("No such operation instance of key - %s" % item)
46 for _instance in self._operation_list:
50 class BaseOperation(object):
54 def __init__(self, config, context):
55 if not BaseOperation.operation_cfgs:
56 with open(operation_conf_path) as stream:
57 BaseOperation.operation_cfgs = yaml.load(stream)
60 self._context = context
63 def get_operation_cls(type):
64 """return operation instance of specified type"""
66 for operation_cls in utils.itersubclasses(BaseOperation):
67 if operation_type == operation_cls.__operation__type__:
69 raise RuntimeError("No such runner_type %s" % operation_type)
71 def get_script_fullpath(self, path):
72 base_path = os.path.dirname(operation_conf_path)
73 return os.path.join(base_path, path)