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 resultchecker_conf_path = pkg_resources.resource_filename(
19 "yardstick.benchmark.scenarios.availability",
20 "result_checker_conf.yaml")
23 class ResultCheckerMgr(object):
26 self._result_checker_list = []
28 def init_ResultChecker(self, resultchecker_cfgs, context):
29 LOG.debug("resultcheckerMgr confg: %s" % resultchecker_cfgs)
31 for cfg in resultchecker_cfgs:
32 resultchecker_type = cfg['checker_type']
33 resultchecker_cls = BaseResultChecker.get_resultchecker_cls(
35 resultchecker_ins = resultchecker_cls(cfg, context)
36 resultchecker_ins.key = cfg['key']
37 resultchecker_ins.setup()
38 self._result_checker_list.append(resultchecker_ins)
40 def __getitem__(self, item):
41 for obj in self._result_checker_list:
44 raise KeyError("No such result checker instance of key - %s" % item)
48 for obj in self._result_checker_list:
53 class BaseResultChecker(object):
55 resultchecker_cfgs = {}
57 def __init__(self, config, context):
58 if not BaseResultChecker.resultchecker_cfgs:
59 with open(resultchecker_conf_path) as stream:
60 BaseResultChecker.resultchecker_cfgs = yaml.load(stream)
61 self.actualResult = object()
62 self.expectedResult = object()
66 self._context = context
67 self.setup_done = False
70 def get_resultchecker_cls(type):
71 '''return resultchecker instance of specified type'''
72 resultchecker_type = type
73 for checker_cls in utils.itersubclasses(BaseResultChecker):
74 if resultchecker_type == checker_cls.__result_checker__type__:
76 raise RuntimeError("No such runner_type %s" % resultchecker_type)
78 def get_script_fullpath(self, path):
79 base_path = os.path.dirname(resultchecker_conf_path)
80 return os.path.join(base_path, path)
86 if(self.actualResult == self.expectedResult):