diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2020-11-03 15:25:58 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2020-11-04 17:23:40 +0000 |
commit | eeeb7190de7185c9994e460cc0472e8817ab68aa (patch) | |
tree | a6385b3748f32b583b326abf016c1b8628bac254 /src/onaptests/steps/base.py | |
parent | 31dc9d07a9bd5c98304ae7d58e995321d3e1507f (diff) |
Integration tests report enrichment
Improve the step description for better reporting
Add duration step in pythonsdk-test reporting
Issue-ID: TEST-271
Issue-ID: TEST-272
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I6d46cb38ae236bc578eb15982c2c0b8f2b0c0791
Diffstat (limited to 'src/onaptests/steps/base.py')
-rw-r--r-- | src/onaptests/steps/base.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py index 57217fb..8d70405 100644 --- a/src/onaptests/steps/base.py +++ b/src/onaptests/steps/base.py @@ -1,12 +1,13 @@ import logging import logging.config +import time from abc import ABC, abstractmethod from typing import List from onapsdk.configuration import settings from onapsdk.aai.business import Customer -from .reports_collection import ReportsCollection +from .reports_collection import Report, ReportsCollection, ReportStepStatus class BaseStep(ABC): @@ -93,16 +94,50 @@ class BaseStep(ABC): """Step name.""" return self.__class__.__name__ + @property + @abstractmethod + def description(self) -> str: + """Step description. + + Used for reports + + Returns: + str: Step description + + """ + + @property + @abstractmethod + def component(self) -> str: + """Component name. + + Name of component which step is related with. + Most is the name of ONAP component. + + Returns: + str: Component name + + """ + @classmethod def store_state(cls, fun): def wrapper(self, *args, **kwargs): try: + start_time: float = time.time() ret = fun(self, *args, **kwargs) - self.reports_collection.put({self.name: "PASS"}) + execution_status: ReportStepStatus = ReportStepStatus.PASS return ret except Exception: - self.reports_collection.put({self.name: "FAIL"}) + execution_status: ReportStepStatus = ReportStepStatus.FAIL raise + finally: + self.reports_collection.put( + Report( + step_description=f"[{self.component}] {self.name}: {self.description}", + step_execution_status=execution_status, + step_execution_duration=time.time() - start_time + ) + ) return wrapper def execute(self) -> None: |