diff options
author | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2024-02-02 15:11:46 +0100 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2024-02-02 15:11:46 +0100 |
commit | 63e4bc52ae39ba58a2e2cc0c703c656bf52de414 (patch) | |
tree | 093f777139d3f2a74723a180142fa4b8e9095469 | |
parent | 440df5e3af8446ddaf1e7ab9ed5abbbe439f9a06 (diff) |
Execution base method is not required to be run.
Issue-ID: TEST-402
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I3659aa2e09dd7c51f756bfdafb67d11b5114af2e
-rw-r--r-- | pylama.ini | 2 | ||||
-rw-r--r-- | src/onaptests/scenario/scenario_base.py | 1 | ||||
-rw-r--r-- | src/onaptests/steps/base.py | 34 |
3 files changed, 27 insertions, 10 deletions
@@ -5,7 +5,7 @@ linters = pylint,pycodestyle,pyflakes,mccabe max_line_length = 100 [pylama:pylint] -known_third_party=onaptests,onapsdk +known_third_party=onapsdk disable = fixme, logging-fstring-interpolation, diff --git a/src/onaptests/scenario/scenario_base.py b/src/onaptests/scenario/scenario_base.py index f19352a..ca6d898 100644 --- a/src/onaptests/scenario/scenario_base.py +++ b/src/onaptests/scenario/scenario_base.py @@ -70,6 +70,7 @@ class ScenarioBase(testcase.TestCase): """Validate implementation of the scenario.""" self._validate_service_details() + self.test.validate_step_implementation() self.test.validate_execution() self.test.validate_cleanup() diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py index 197afac..d788fd4 100644 --- a/src/onaptests/steps/base.py +++ b/src/onaptests/steps/base.py @@ -15,7 +15,6 @@ from onaptests.steps.reports_collection import (Report, ReportsCollection, ReportStepStatus) from onaptests.utils.exceptions import (OnapTestException, OnapTestExceptionGroup, - SkipExecutionException, SubstepExecutionException, SubstepExecutionExceptionGroup, TestConfigurationException) @@ -35,7 +34,7 @@ class StoreStateHandler(ABC): @functools.wraps(fun) def wrapper(self, *args, **kwargs): if (cleanup and self._state_clean) or (not cleanup and self._state_execute): - raise RuntimeError(f"Sate of {self._step_title(cleanup)} already stored") + raise RuntimeError("%s step executed twice" % self._step_title(cleanup)) if cleanup: self._state_clean = True else: @@ -68,14 +67,13 @@ class StoreStateHandler(ABC): else: if self._is_validation_only or self.check_preconditions(): self._log_execution_state("START", cleanup) - fun(self, *args, **kwargs) + self._execute_substeps() + if not self._is_validation_only: + fun(self, *args, **kwargs) execution_status = ReportStepStatus.PASS self._executed = True else: execution_status = ReportStepStatus.NOT_EXECUTED - except SkipExecutionException: - execution_status = ReportStepStatus.PASS - self._executed = True except SubstepExecutionException as substep_exc: if not cleanup: execution_status = ReportStepStatus.NOT_EXECUTED @@ -113,6 +111,7 @@ class StoreStateHandler(ABC): step_execution_duration=time.time() - self._start_execution_time, step_component=self.component ) + wrapper._is_wrapped = True return wrapper @@ -329,7 +328,7 @@ class BaseStep(StoreStateHandler, ABC): """ return True - def execute(self) -> None: + def _execute_substeps(self) -> None: """Step's action execution. Run all substeps action before it's own action. @@ -350,8 +349,6 @@ class BaseStep(StoreStateHandler, ABC): raise SubstepExecutionException("Cannot continue due to failed substeps") self._log_execution_state("CONTINUE") self._start_execution_time = time.time() - if self._is_validation_only: - raise SkipExecutionException() def _cleanup_substeps(self) -> None: """Substeps' cleanup. @@ -377,6 +374,13 @@ class BaseStep(StoreStateHandler, ABC): raise exceptions_to_raise[0] raise SubstepExecutionExceptionGroup("Substep Exceptions", exceptions_to_raise) + def execute(self) -> None: + """Step's execute. + + Must be implemented in the steps with store_state decorator + + """ + def cleanup(self) -> None: """Step's cleanup. @@ -400,6 +404,18 @@ class BaseStep(StoreStateHandler, ABC): onap_proxy['https'] = sock_http Customer.set_proxy(onap_proxy) + def validate_step_implementation(self): + """Validate is step addes store_state decorators.""" + + if not getattr(self.execute, "_is_wrapped", False): + raise TestConfigurationException( + f"{self._step_title()} - store_state decorator not present in execute() method") + if self._cleanup and not getattr(self.cleanup, "_is_wrapped", False): + raise TestConfigurationException( + f"{self._step_title()} - store_state decorator not present in cleanup() method") + for step in self._steps: + step.validate_step_implementation() + def validate_execution(self): """Validate if each step was executed by decorator.""" |