1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
10 '''A runner that runs a configurable number of times before it returns
14 import multiprocessing
19 from yardstick.benchmark.runners import base
21 LOG = logging.getLogger(__name__)
24 def _worker_process(queue, cls, method_name, context, scenario_args):
28 interval = context.get("interval", 1)
29 iterations = context.get("iterations", 1)
30 LOG.info("worker START, iterations %d times, class %s", iterations, cls)
32 context['runner'] = os.getpid()
34 benchmark = cls(context)
36 method = getattr(benchmark, method_name)
38 record_context = {"runner": context["runner"],
39 "host": context["host"]}
42 if "sla" in scenario_args:
43 sla_action = scenario_args["sla"].get("action", "assert")
47 LOG.debug("runner=%(runner)s seq=%(sequence)s START" %
48 {"runner": context["runner"], "sequence": sequence})
54 data = method(scenario_args)
55 except AssertionError as assertion:
56 # SLA validation failed in scenario, determine what to do now
57 if sla_action == "assert":
59 elif sla_action == "monitor":
60 LOG.warning("SLA validation failed: %s" % assertion.args)
61 errors = assertion.args
62 except Exception as e:
63 errors = traceback.format_exc()
69 'timestamp': time.time(),
75 queue.put({'context': record_context, 'sargs': scenario_args,
76 'benchmark': benchmark_output})
78 LOG.debug("runner=%(runner)s seq=%(sequence)s END" %
79 {"runner": context["runner"], "sequence": sequence})
83 if (errors and sla_action is None) or (sequence > iterations):
84 LOG.info("worker END")
90 class IterationRunner(base.Runner):
91 '''Run a scenario for a configurable number of times
93 If the scenario ends before the time has elapsed, it will be started again.
96 iterations - amount of times the scenario will be run for
100 interval - time to wait between each scenario invocation
105 __execution_type__ = 'Iteration'
107 def _run_benchmark(self, cls, method, scenario_args):
108 self.process = multiprocessing.Process(
109 target=_worker_process,
110 args=(self.result_queue, cls, method, self.config, scenario_args))