Make "Scenario" class abstract 35/53535/6
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Mon, 12 Mar 2018 12:44:52 +0000 (12:44 +0000)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 21 Mar 2018 09:15:44 +0000 (09:15 +0000)
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>
yardstick/benchmark/scenarios/base.py
yardstick/tests/unit/benchmark/scenarios/test_base.py

index 10a7288..3b88ade 100644 (file)
@@ -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:
index 9853385..6e2cff4 100644 (file)
@@ -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):