aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-12 14:14:57 +0000
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-21 09:15:44 +0000
commitbf892d9cf62b6bc64ea76d8b69a8fe3751cabd75 (patch)
treebbdfc7be2b8888cc6c0c5f6a5381720253e74548
parentc17d65bc5f620328079a6905ebcdd73138685d5f (diff)
Add "Scenario" class wait methods for runners
"Duration" and "Iteration" runners execute a passive wait during the execution of the work process. This wait time is done at the end of the scenario "run" method execution. This patch adds a pre-run and post-run wait period, which will depends on the Scenario executed. The wait time will be always the same, but the execution order (pre-wait time, run method, post-wait time) will depends on the Scenario. By default, any Scenario will execute the "run" method and them will wait the specified time. NetworkServicesTestCase Scenario will wait the specified time and them will execute the "run" method to retrieve the KPIs. JIRA: YARDSTICK-1067 Change-Id: I6ad6bfc6978815b6b2d4df63f2ac2f8815fb5b8a Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
-rw-r--r--yardstick/benchmark/runners/duration.py6
-rw-r--r--yardstick/benchmark/runners/iteration.py6
-rw-r--r--yardstick/benchmark/scenarios/base.py9
-rw-r--r--yardstick/benchmark/scenarios/networking/vnf_generic.py9
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/test_base.py25
5 files changed, 51 insertions, 4 deletions
diff --git a/yardstick/benchmark/runners/duration.py b/yardstick/benchmark/runners/duration.py
index fbf72a74c..60b0348c3 100644
--- a/yardstick/benchmark/runners/duration.py
+++ b/yardstick/benchmark/runners/duration.py
@@ -66,6 +66,8 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
data = {}
errors = ""
+ benchmark.pre_run_wait_time(interval)
+
try:
result = method(data)
except AssertionError as assertion:
@@ -77,7 +79,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
errors = assertion.args
# catch all exceptions because with multiprocessing we can have un-picklable exception
# problems https://bugs.python.org/issue9400
- except Exception:
+ except Exception: # pylint: disable=broad-except
errors = traceback.format_exc()
LOG.exception("")
else:
@@ -86,7 +88,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
# if we do timeout we don't care about dropping individual KPIs
output_queue.put(result, True, QUEUE_PUT_TIMEOUT)
- time.sleep(interval)
+ benchmark.post_run_wait_time(interval)
benchmark_output = {
'timestamp': time.time(),
diff --git a/yardstick/benchmark/runners/iteration.py b/yardstick/benchmark/runners/iteration.py
index cb0424377..20d6da054 100644
--- a/yardstick/benchmark/runners/iteration.py
+++ b/yardstick/benchmark/runners/iteration.py
@@ -71,6 +71,8 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
data = {}
errors = ""
+ benchmark.pre_run_wait_time(interval)
+
try:
result = method(data)
except AssertionError as assertion:
@@ -90,7 +92,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
scenario_cfg['options']['rate'] -= delta
sequence = 1
continue
- except Exception:
+ except Exception: # pylint: disable=broad-except
errors = traceback.format_exc()
LOG.exception("")
else:
@@ -99,7 +101,7 @@ def _worker_process(queue, cls, method_name, scenario_cfg,
# if we do timeout we don't care about dropping individual KPIs
output_queue.put(result, True, QUEUE_PUT_TIMEOUT)
- time.sleep(interval)
+ benchmark.post_run_wait_time(interval)
benchmark_output = {
'timestamp': time.time(),
diff --git a/yardstick/benchmark/scenarios/base.py b/yardstick/benchmark/scenarios/base.py
index 3b88ade7d..58a02805c 100644
--- a/yardstick/benchmark/scenarios/base.py
+++ b/yardstick/benchmark/scenarios/base.py
@@ -14,6 +14,7 @@
# under the License.
import abc
+import time
import six
from stevedore import extension
@@ -52,6 +53,14 @@ class Scenario(object):
"""Default teardown implementation for Scenario classes"""
pass
+ def pre_run_wait_time(self, time_seconds):
+ """Time waited before executing the run method"""
+ pass
+
+ def post_run_wait_time(self, time_seconds):
+ """Time waited after executing the run method"""
+ time.sleep(time_seconds)
+
@staticmethod
def get_types():
"""return a list of known runner type (class) names"""
diff --git a/yardstick/benchmark/scenarios/networking/vnf_generic.py b/yardstick/benchmark/scenarios/networking/vnf_generic.py
index 0e4785294..be2fa3f3b 100644
--- a/yardstick/benchmark/scenarios/networking/vnf_generic.py
+++ b/yardstick/benchmark/scenarios/networking/vnf_generic.py
@@ -14,6 +14,7 @@
import copy
import logging
+import time
import ipaddress
from itertools import chain
@@ -484,3 +485,11 @@ class NetworkServiceTestCase(scenario_base.Scenario):
# https://bugs.python.org/issue9400
LOG.exception("")
raise RuntimeError("Error in teardown")
+
+ def pre_run_wait_time(self, time_seconds):
+ """Time waited before executing the run method"""
+ time.sleep(time_seconds)
+
+ def post_run_wait_time(self, time_seconds):
+ """Time waited after executing the run method"""
+ pass
diff --git a/yardstick/tests/unit/benchmark/scenarios/test_base.py b/yardstick/tests/unit/benchmark/scenarios/test_base.py
index 6e2cff425..284a71cc8 100644
--- a/yardstick/tests/unit/benchmark/scenarios/test_base.py
+++ b/yardstick/tests/unit/benchmark/scenarios/test_base.py
@@ -13,10 +13,21 @@
# License for the specific language governing permissions and limitations
# under the License.
+import time
+
+import mock
+
from yardstick.benchmark.scenarios import base
from yardstick.tests.unit import base as ut_base
+class _TestScenario(base.Scenario):
+ __scenario_type__ = 'Test Scenario'
+
+ def run(self):
+ pass
+
+
class ScenarioTestCase(ut_base.BaseUnitTestCase):
def test_get_scenario_type(self):
@@ -90,6 +101,20 @@ class ScenarioTestCase(ut_base.BaseUnitTestCase):
with self.assertRaises(TypeError):
base.Scenario()
+ @mock.patch.object(time, 'sleep')
+ def test_pre_run_wait_time(self, mock_sleep):
+ """Ensure default behaviour (backwards compatibility): no wait time"""
+ test_scenario = _TestScenario()
+ test_scenario.pre_run_wait_time(mock.ANY)
+ mock_sleep.assert_not_called()
+
+ @mock.patch.object(time, 'sleep')
+ def test_post_run_wait_time(self, mock_sleep):
+ """Ensure default behaviour (backwards compatibility): wait time"""
+ test_scenario = _TestScenario()
+ test_scenario.post_run_wait_time(100)
+ mock_sleep.assert_called_once_with(100)
+
class IterScenarioClassesTestCase(ut_base.BaseUnitTestCase):