aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/scenario/scenario_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/onaptests/scenario/scenario_base.py')
-rw-r--r--src/onaptests/scenario/scenario_base.py68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/onaptests/scenario/scenario_base.py b/src/onaptests/scenario/scenario_base.py
index 6fea811..179bea8 100644
--- a/src/onaptests/scenario/scenario_base.py
+++ b/src/onaptests/scenario/scenario_base.py
@@ -1,6 +1,10 @@
import logging
+import time
from onapsdk.configuration import settings
+from onapsdk.exceptions import SDKException
+from onaptests.steps.base import BaseStep, YamlTemplateBaseStep
+from onaptests.utils.exceptions import OnapTestException
from xtesting.core import testcase
@@ -13,8 +17,68 @@ class ScenarioBase(testcase.TestCase):
"""Init base scenario."""
if "case_name" not in kwargs:
kwargs["case_name"] = case_name_override
- self.__logger.info("Global Configuration:")
+ self.scenario_name = kwargs["case_name"].replace("_", " ")
+ self.scenario_name = str.title(self.scenario_name)
+
+ self.__logger.info("%s Global Configuration:", self.scenario_name)
for val in settings._settings:
self.__logger.info("%s: %s", val, settings._settings[val])
+
+ self.__logger.debug("%s init started", self.scenario_name)
super().__init__(**kwargs)
- self.__logger.debug("%s init started", kwargs["case_name"])
+ self.general_exception = None
+
+ def run(self):
+ """Run scenario and cleanup resources afterwards"""
+ self.start_time = time.time()
+ try:
+ for test_phase in (self.test.execute, self.test.cleanup):
+ phase_name = test_phase.__name__
+ try:
+ if (phase_name == "cleanup" and settings.CLEANUP_FLAG and
+ settings.CLEANUP_ACTIVITY_TIMER > 0):
+ time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
+ self.__logger.info("%s %s Phase Started",
+ self.scenario_name, phase_name.title())
+ test_phase()
+ self.result += 50
+ except OnapTestException as exc:
+ self.__logger.exception("%s on %s", exc.error_message, phase_name)
+ except SDKException:
+ self.__logger.exception("SDK Exception on %s", phase_name)
+ except Exception as e:
+ self.__logger.exception("General Exception on %s", phase_name)
+ if self.general_exception:
+ e = ExceptionGroup("General Exceptions", [self.general_exception, e]) # noqa
+ self.general_exception = e
+ finally:
+ self.stop_time = time.time()
+ self.__logger.info(f"{self.scenario_name} Execution {self.result}% Completed")
+ if self.general_exception:
+ raise self.general_exception
+
+ def clean(self):
+ """Clean Additional resources if needed."""
+ self.__logger.info("Generate %s Test report", self.scenario_name)
+ self.test.reports_collection.generate_report()
+
+ def validate_execution(self):
+ self.test.validate_execution()
+
+
+class BaseScenarioStep(BaseStep):
+
+ def __init__(self, cleanup=False):
+ """Initialize BaseScenarioStep step."""
+ super().__init__(cleanup=cleanup)
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ super().execute()
+
+
+class YamlTemplateBaseScenarioStep(YamlTemplateBaseStep, BaseScenarioStep):
+
+ def __init__(self, cleanup=False):
+ """Initialize YamlTemplateBaseScenarioStep step."""
+ super().__init__(cleanup=cleanup)