1 # Copyright 2014: Mirantis Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # yardstick comment: this is a modified copy of
17 # rally/rally/benchmark/runners/constant.py
19 '''A runner that runs a configurable number of times before it returns
23 import multiprocessing
28 from yardstick.benchmark.runners import base
30 LOG = logging.getLogger(__name__)
33 def _worker_process(queue, cls, method_name, scenario_cfg,
34 context_cfg, aborted):
38 runner_cfg = scenario_cfg['runner']
40 interval = runner_cfg.get("interval", 1)
41 iterations = runner_cfg.get("iterations", 1)
42 run_step = runner_cfg.get("run_step", "setup,run,teardown")
43 LOG.info("worker START, iterations %d times, class %s", iterations, cls)
45 runner_cfg['runner_id'] = os.getpid()
47 benchmark = cls(scenario_cfg, context_cfg)
48 if "setup" in run_step:
51 method = getattr(benchmark, method_name)
53 queue.put({'runner_id': runner_cfg['runner_id'],
54 'scenario_cfg': scenario_cfg,
55 'context_cfg': context_cfg})
58 if "sla" in scenario_cfg:
59 sla_action = scenario_cfg["sla"].get("action", "assert")
63 LOG.debug("runner=%(runner)s seq=%(sequence)s START" %
64 {"runner": runner_cfg["runner_id"],
65 "sequence": sequence})
72 except AssertionError as assertion:
73 # SLA validation failed in scenario, determine what to do now
74 if sla_action == "assert":
76 elif sla_action == "monitor":
77 LOG.warning("SLA validation failed: %s" % assertion.args)
78 errors = assertion.args
79 except Exception as e:
80 errors = traceback.format_exc()
86 'timestamp': time.time(),
92 record = {'runner_id': runner_cfg['runner_id'],
93 'benchmark': benchmark_output}
97 LOG.debug("runner=%(runner)s seq=%(sequence)s END" %
98 {"runner": runner_cfg["runner_id"],
99 "sequence": sequence})
103 if (errors and sla_action is None) or \
104 (sequence > iterations or aborted.is_set()):
105 LOG.info("worker END")
107 if "teardown" in run_step:
111 class IterationRunner(base.Runner):
112 '''Run a scenario for a configurable number of times
114 If the scenario ends before the time has elapsed, it will be started again.
117 iterations - amount of times the scenario will be run for
121 interval - time to wait between each scenario invocation
126 __execution_type__ = 'Iteration'
128 def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
129 self.process = multiprocessing.Process(
130 target=_worker_process,
131 args=(self.result_queue, cls, method, scenario_cfg,
132 context_cfg, self.aborted))