summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-12 12:44:52 +0000
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-21 09:15:44 +0000
commitc17d65bc5f620328079a6905ebcdd73138685d5f (patch)
tree7cca65cd80e0f0690935ab2f84c9b7e3116a0a01
parentdb951243d3d036fa7989bbd388e869eb89b247e8 (diff)
Make "Scenario" class abstract
All scenario child classes must implement "run" method. JIRA: YARDSTICK-1065 Change-Id: I35b78e380620967b49cd8cd23777a1aee6dfd140 Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
-rw-r--r--yardstick/benchmark/scenarios/base.py21
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/test_base.py5
2 files changed, 18 insertions, 8 deletions
diff --git a/yardstick/benchmark/scenarios/base.py b/yardstick/benchmark/scenarios/base.py
index 10a728828..3b88ade7d 100644
--- a/yardstick/benchmark/scenarios/base.py
+++ b/yardstick/benchmark/scenarios/base.py
@@ -13,9 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
-# yardstick comment: this is a modified copy of
-# rally/rally/benchmark/scenarios/base.py
+import abc
+import six
from stevedore import extension
import yardstick.common.utils as utils
@@ -37,18 +37,19 @@ def _iter_scenario_classes(scenario_type=None):
yield scenario
+@six.add_metaclass(abc.ABCMeta)
class Scenario(object):
def setup(self):
- """ default impl for scenario setup """
+ """Default setup implementation for Scenario classes"""
pass
+ @abc.abstractmethod
def run(self, *args):
- """ catcher for not implemented run methods in subclasses """
- raise RuntimeError("run method not implemented")
+ """Entry point for scenario classes, called from runner worker"""
def teardown(self):
- """ default impl for scenario teardown """
+ """Default teardown implementation for Scenario classes"""
pass
@staticmethod
@@ -88,10 +89,14 @@ class Scenario(object):
"""
return cls.__doc__.splitlines()[0] if cls.__doc__ else str(None)
- def _push_to_outputs(self, keys, values):
+ @staticmethod
+ def _push_to_outputs(keys, values):
+ """Return a dictionary given the keys and the values"""
return dict(zip(keys, values))
- def _change_obj_to_dict(self, obj):
+ @staticmethod
+ def _change_obj_to_dict(obj):
+ """Return a dictionary from the __dict__ attribute of an object"""
dic = {}
for k, v in vars(obj).items():
try:
diff --git a/yardstick/tests/unit/benchmark/scenarios/test_base.py b/yardstick/tests/unit/benchmark/scenarios/test_base.py
index 985338532..6e2cff425 100644
--- a/yardstick/tests/unit/benchmark/scenarios/test_base.py
+++ b/yardstick/tests/unit/benchmark/scenarios/test_base.py
@@ -85,6 +85,11 @@ class ScenarioTestCase(ut_base.BaseUnitTestCase):
self.assertEqual('No such scenario type %s' % wrong_scenario_name,
str(exc.exception))
+ def test_scenario_abstract_class(self):
+ # pylint: disable=abstract-class-instantiated
+ with self.assertRaises(TypeError):
+ base.Scenario()
+
class IterScenarioClassesTestCase(ut_base.BaseUnitTestCase):