diff options
author | 2020-10-07 09:02:51 +0000 | |
---|---|---|
committer | 2020-10-07 09:02:51 +0000 | |
commit | d1d44781c7d03c8794dd626184f77d9836264212 (patch) | |
tree | c4fd34da2631a3a775612946841bd7149b664f8c /src/onaptests/steps/base.py | |
parent | 9cd3c4fef7b7e980321486bfd1a86366a2221a16 (diff) | |
parent | 84a44a0cf70e2e55a13e4e994836ee074b7039aa (diff) |
Merge "Collect steps execution result"
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. |