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, context, scenario_args):
29 interval = context.get("interval", 1)
30 arg_name = context.get('scenario_option_name')
31 sequence_values = context.get('sequence')
33 if 'options' not in scenario_args:
34 scenario_args['options'] = {}
36 options = scenario_args['options']
38 context['runner'] = os.getpid()
40 LOG.info("worker START, sequence_values(%s, %s), class %s",
41 arg_name, sequence_values, cls)
43 benchmark = cls(context)
45 method = getattr(benchmark, method_name)
47 record_context = {"runner": context["runner"],
48 "host": context["host"]}
51 if "sla" in scenario_args:
52 sla_action = scenario_args["sla"].get("action", "assert")
54 for value in sequence_values:
55 options[arg_name] = value
57 LOG.debug("runner=%(runner)s seq=%(sequence)s START" %
58 {"runner": context["runner"], "sequence": sequence})
64 data = method(scenario_args)
65 except AssertionError as assertion:
66 # SLA validation failed in scenario, determine what to do now
67 if sla_action == "assert":
69 elif sla_action == "monitor":
70 LOG.warning("SLA validation failed: %s" % assertion.args)
71 errors = assertion.args
72 except Exception as e:
73 errors = traceback.format_exc()
79 'timestamp': time.time(),
85 queue.put({'context': record_context, 'sargs:': scenario_args,
86 'benchmark': benchmark_output})
88 LOG.debug("runner=%(runner)s seq=%(sequence)s END" %
89 {"runner": context["runner"], "sequence": sequence})
97 LOG.info("worker END")
100 class SequenceRunner(base.Runner):
101 '''Run a scenario by changing an input value defined in a list
104 interval - time to wait between each scenario invocation
108 scenario_option_name - name of the option that is increased each invocation
112 sequence - list of values which are executed in their respective scenarios
118 __execution_type__ = 'Sequence'
120 def _run_benchmark(self, cls, method, scenario_args):
121 self.process = multiprocessing.Process(
122 target=_worker_process,
123 args=(self.result_queue, cls, method, self.config, scenario_args))