add setup/teardown to scenario base class and runners 52/652/1
authorHans Feldt <hans.feldt@ericsson.com>
Tue, 26 May 2015 09:56:24 +0000 (11:56 +0200)
committerHans Feldt <hans.feldt@ericsson.com>
Tue, 26 May 2015 10:14:35 +0000 (12:14 +0200)
Prepare for "service type" of scenarios that e.g. needs to start
a service in setup and shut it down in teardown.

In the runners, instantiation of the scenario is moved after the
"worker START" log to get a more logical sequence logged.

Change-Id: Idfaf5bb396eab9261e820291885b5a1dbc32f71e
JIRA: -
Signed-off-by: Hans Feldt <hans.feldt@ericsson.com>
yardstick/benchmark/runners/arithmetic.py
yardstick/benchmark/runners/duration.py
yardstick/benchmark/scenarios/base.py

index bac7efb..a3aceb3 100644 (file)
@@ -26,9 +26,6 @@ def _worker_process(queue, cls, method_name, context, scenario_args):
 
     sequence = 1
 
-    benchmark = cls(context)
-    method = getattr(benchmark, method_name)
-
     interval = context.get("interval", 1)
     arg_name = context.get('name')
     stop = context.get('stop')
@@ -41,6 +38,10 @@ def _worker_process(queue, cls, method_name, context, scenario_args):
     LOG.info("worker START, step(%s, %d, %d, %d), class %s",
              arg_name, start, stop, step, cls)
 
+    benchmark = cls(context)
+    benchmark.setup()
+    method = getattr(benchmark, method_name)
+
     record_context = {"runner": context["runner"],
                       "host": context["host"]}
 
@@ -91,6 +92,7 @@ def _worker_process(queue, cls, method_name, context, scenario_args):
         if errors:
             break
 
+    benchmark.teardown()
     LOG.info("worker END")
 
 
index 9917248..61d498f 100644 (file)
@@ -25,13 +25,15 @@ def _worker_process(queue, cls, method_name, context, scenario_args):
 
     sequence = 1
 
-    benchmark = cls(context)
-    method = getattr(benchmark, method_name)
     interval = context.get("interval", 1)
     duration = context.get("duration", 60)
+    LOG.info("worker START, duration %d sec, class %s", duration, cls)
+
     context['runner'] = os.getpid()
 
-    LOG.info("worker START, duration %d sec, class %s", duration, cls)
+    benchmark = cls(context)
+    benchmark.setup()
+    method = getattr(benchmark, method_name)
 
     record_context = {"runner": context["runner"],
                       "host": context["host"]}
@@ -81,7 +83,9 @@ def _worker_process(queue, cls, method_name, context, scenario_args):
 
         if (errors and sla_action is None) or (time.time() - start > duration):
             LOG.info("worker END")
-            return
+            break
+
+    benchmark.teardown()
 
 
 class DurationRunner(base.Runner):
index 540acca..e1e31fd 100644 (file)
@@ -15,7 +15,16 @@ import yardstick.common.utils as utils
 
 class Scenario(object):
 
+    def setup(self):
+        ''' default impl for scenario setup '''
+        pass
+
     def run(self, args):
+        ''' catcher for not implemented run methods in subclasses '''
+        raise RuntimeError("run method not implemented")
+
+    def teardown(self):
+        ''' default impl for scenario teardown '''
         pass
 
     @staticmethod