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 every run changes a specified input value to the scenario.
20 The input value in the sequence is specified in a list in the input file.
23 from __future__ import absolute_import
26 import multiprocessing
32 from yardstick.benchmark.runners import base
34 LOG = logging.getLogger(__name__)
37 def _worker_process(queue, cls, method_name, scenario_cfg,
38 context_cfg, aborted, output_queue):
42 runner_cfg = scenario_cfg['runner']
44 interval = runner_cfg.get("interval", 1)
45 arg_name = runner_cfg.get('scenario_option_name')
46 sequence_values = runner_cfg.get('sequence')
48 if 'options' not in scenario_cfg:
49 scenario_cfg['options'] = {}
51 options = scenario_cfg['options']
53 runner_cfg['runner_id'] = os.getpid()
55 LOG.info("worker START, sequence_values(%s, %s), class %s",
56 arg_name, sequence_values, cls)
58 benchmark = cls(scenario_cfg, context_cfg)
60 method = getattr(benchmark, method_name)
63 if "sla" in scenario_cfg:
64 sla_action = scenario_cfg["sla"].get("action", "assert")
66 for value in sequence_values:
67 options[arg_name] = value
69 LOG.debug("runner=%(runner)s seq=%(sequence)s START",
70 {"runner": runner_cfg["runner_id"], "sequence": sequence})
77 except AssertionError as assertion:
78 # SLA validation failed in scenario, determine what to do now
79 if sla_action == "assert":
81 elif sla_action == "monitor":
82 LOG.warning("SLA validation failed: %s", assertion.args)
83 errors = assertion.args
84 except Exception as e:
85 errors = traceback.format_exc()
89 output_queue.put(result)
94 'timestamp': time.time(),
100 queue.put(benchmark_output)
102 LOG.debug("runner=%(runner)s seq=%(sequence)s END",
103 {"runner": runner_cfg["runner_id"], "sequence": sequence})
107 if (errors and sla_action is None) or aborted.is_set():
113 # catch any exception in teardown and convert to simple exception
114 # never pass exceptions back to multiprocessing, because some exceptions can
116 # https://bugs.python.org/issue9400
119 LOG.info("worker END")
120 LOG.debug("queue.qsize() = %s", queue.qsize())
121 LOG.debug("output_queue.qsize() = %s", output_queue.qsize())
124 class SequenceRunner(base.Runner):
125 """Run a scenario by changing an input value defined in a list
128 interval - time to wait between each scenario invocation
132 scenario_option_name - name of the option that is increased each invocation
136 sequence - list of values which are executed in their respective scenarios
142 __execution_type__ = 'Sequence'
144 def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
145 name = "{}-{}-{}".format(self.__execution_type__, scenario_cfg.get("type"), os.getpid())
146 self.process = multiprocessing.Process(
148 target=_worker_process,
149 args=(self.result_queue, cls, method, scenario_cfg,
150 context_cfg, self.aborted, self.output_queue))