Prevent cleanup of parent when substep has failed 93/137193/1
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 8 Feb 2024 19:18:28 +0000 (20:18 +0100)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 8 Feb 2024 19:23:24 +0000 (20:23 +0100)
Prevent cleanup of parent when substep has failed

Issue-ID: TEST-402
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I2ed0aaaab9e43fef56685958b03fd796df25bc3b

src/onaptests/steps/base.py

index d788fd4..00229ba 100644 (file)
@@ -46,6 +46,7 @@ class StoreStateHandler(ABC):
                     self._start_cleanup_time = time.time()
                     try:
                         if (self._cleanup and self._state_execute and
+                                (not self.has_substeps or self._substeps_executed) and
                                 (self._is_validation_only or
                                     self.check_preconditions(cleanup=True))):
                             self._log_execution_state("START", cleanup)
@@ -160,6 +161,7 @@ class BaseStep(StoreStateHandler, ABC):
         self._state_clean: bool = False
         self._nesting_level: int = 0
         self._break_on_error: bool = break_on_error
+        self._substeps_executed: bool = False
         self._is_validation_only = settings.IF_VALIDATION
         self._is_force_cleanup = os.environ.get(IF_FORCE_CLEANUP) is not None
 
@@ -192,6 +194,18 @@ class BaseStep(StoreStateHandler, ABC):
         """
         return self._parent
 
+    @property
+    def has_substeps(self) -> bool:
+        """Has step substeps.
+
+        If sdc has substeps.
+
+        Returns:
+            bool: True if step has substeps
+
+        """
+        return len(self._steps) > 0
+
     @property
     def is_executed(self) -> bool:
         """Is step executed.
@@ -348,6 +362,7 @@ class BaseStep(StoreStateHandler, ABC):
             if substep_error and self._break_on_error:
                 raise SubstepExecutionException("Cannot continue due to failed substeps")
             self._log_execution_state("CONTINUE")
+        self._substeps_executed = True
         self._start_execution_time = time.time()
 
     def _cleanup_substeps(self) -> None: