diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2020-10-06 09:56:13 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2020-10-06 10:25:28 +0000 |
commit | 84a44a0cf70e2e55a13e4e994836ee074b7039aa (patch) | |
tree | 4a5cd2706061e5147381f87874197777448d85ca /src/onaptests/steps/base.py | |
parent | c166b498dd792bafc22672d56c15abc5714898ab (diff) |
Collect steps execution result
Create a decorator to collect step execution result and store them in storage class.
Storage class prepare a dictionary with step class name and execution result.
Issue-ID: INT-1733
Change-Id: I9c4030a0740085a9acca461c1581683c469ecbcf
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Diffstat (limited to 'src/onaptests/steps/base.py')
-rw-r--r-- | src/onaptests/steps/base.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py index 5407a85..57217fb 100644 --- a/src/onaptests/steps/base.py +++ b/src/onaptests/steps/base.py @@ -6,6 +6,9 @@ from typing import List from onapsdk.configuration import settings from onapsdk.aai.business import Customer +from .reports_collection import ReportsCollection + + class BaseStep(ABC): """Base step class.""" @@ -36,6 +39,7 @@ class BaseStep(ABC): self._steps: List["BaseStep"] = [] self._cleanup: bool = cleanup self._parent: "BaseStep" = None + self._reports_collection: ReportsCollection = None def add_step(self, step: "BaseStep") -> None: """Add substep. @@ -68,6 +72,39 @@ class BaseStep(ABC): """ return self._parent is None + @property + def reports_collection(self) -> ReportsCollection: + """Collection to store step reports. + + Store there if step result is "PASS" or "FAIL" + + Returns: + Queue: Thread safe collection to store reports + + """ + if not self.is_root: + return self.parent.reports_collection + if not self._reports_collection: + self._reports_collection = ReportsCollection() + return self._reports_collection + + @property + def name(self) -> str: + """Step name.""" + return self.__class__.__name__ + + @classmethod + def store_state(cls, fun): + def wrapper(self, *args, **kwargs): + try: + ret = fun(self, *args, **kwargs) + self.reports_collection.put({self.name: "PASS"}) + return ret + except Exception: + self.reports_collection.put({self.name: "FAIL"}) + raise + return wrapper + def execute(self) -> None: """Step's action. |