1 ##############################################################################
2 # Copyright (c) 2015 Ericsson AB 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 every run changes a specified input value to the scenario.
11 The input value in the sequence is specified in a list in the input file.
15 import multiprocessing
20 from yardstick.benchmark.runners import base
22 LOG = logging.getLogger(__name__)
25 def _worker_process(queue, cls, method_name, scenario_cfg, context_cfg):
29 runner_cfg = scenario_cfg['runner']
31 interval = runner_cfg.get("interval", 1)
32 arg_name = runner_cfg.get('scenario_option_name')
33 sequence_values = runner_cfg.get('sequence')
35 if 'options' not in scenario_cfg:
36 scenario_cfg['options'] = {}
38 options = scenario_cfg['options']
40 runner_cfg['runner_id'] = os.getpid()
42 LOG.info("worker START, sequence_values(%s, %s), class %s",
43 arg_name, sequence_values, cls)
45 benchmark = cls(scenario_cfg, context_cfg)
47 method = getattr(benchmark, method_name)
49 queue.put({'runner_id': runner_cfg['runner_id'],
50 'scenario_cfg': scenario_cfg,
51 'context_cfg': context_cfg})
54 if "sla" in scenario_cfg:
55 sla_action = scenario_cfg["sla"].get("action", "assert")
57 for value in sequence_values:
58 options[arg_name] = value
60 LOG.debug("runner=%(runner)s seq=%(sequence)s START" %
61 {"runner": runner_cfg["runner_id"], "sequence": sequence})
68 except AssertionError as assertion:
69 # SLA validation failed in scenario, determine what to do now
70 if sla_action == "assert":
72 elif sla_action == "monitor":
73 LOG.warning("SLA validation failed: %s" % assertion.args)
74 errors = assertion.args
75 except Exception as e:
76 errors = traceback.format_exc()
82 'timestamp': time.time(),
88 record = {'runner_id': runner_cfg['runner_id'],
89 'benchmark': benchmark_output}
93 LOG.debug("runner=%(runner)s seq=%(sequence)s END" %
94 {"runner": runner_cfg["runner_id"], "sequence": sequence})
102 LOG.info("worker END")
105 class SequenceRunner(base.Runner):
106 '''Run a scenario by changing an input value defined in a list
109 interval - time to wait between each scenario invocation
113 scenario_option_name - name of the option that is increased each invocation
117 sequence - list of values which are executed in their respective scenarios
123 __execution_type__ = 'Sequence'
125 def _run_benchmark(self, cls, method, scenario_cfg, context_cfg):
126 self.process = multiprocessing.Process(
127 target=_worker_process,
128 args=(self.result_queue, cls, method, scenario_cfg, context_cfg))