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 resultchecker_conf_path = pkg_resources.resource_filename(
20 "yardstick.benchmark.scenarios.availability",
21 "result_checker_conf.yaml")
24 class ResultCheckerMgr(object):
27 self._result_checker_list = []
29 def init_ResultChecker(self, resultchecker_cfgs, context):
30 LOG.debug("resultcheckerMgr confg: %s", resultchecker_cfgs)
32 for cfg in resultchecker_cfgs:
33 resultchecker_type = cfg['checker_type']
34 resultchecker_cls = BaseResultChecker.get_resultchecker_cls(
36 resultchecker_ins = resultchecker_cls(cfg, context)
37 resultchecker_ins.key = cfg['key']
38 resultchecker_ins.setup()
39 self._result_checker_list.append(resultchecker_ins)
41 def __getitem__(self, item):
42 for obj in self._result_checker_list:
45 raise KeyError("No such result checker instance of key - %s" % item)
49 for obj in self._result_checker_list:
54 class BaseResultChecker(object):
56 resultchecker_cfgs = {}
58 def __init__(self, config, context):
59 if not BaseResultChecker.resultchecker_cfgs:
60 with open(resultchecker_conf_path) as stream:
61 BaseResultChecker.resultchecker_cfgs = yaml.load(stream)
62 self.actualResult = object()
63 self.expectedResult = object()
67 self._context = context
68 self.setup_done = False
71 def get_resultchecker_cls(type):
72 """return resultchecker instance of specified type"""
73 resultchecker_type = type
74 for checker_cls in utils.itersubclasses(BaseResultChecker):
75 if resultchecker_type == checker_cls.__result_checker__type__:
77 raise RuntimeError("No such runner_type %s" % resultchecker_type)
79 def get_script_fullpath(self, path):
80 base_path = os.path.dirname(resultchecker_conf_path)
81 return os.path.join(base_path, path)
87 if(self.actualResult == self.expectedResult):