diff options
author | 2020-07-16 19:16:42 +0200 | |
---|---|---|
committer | 2020-08-24 17:39:38 +0000 | |
commit | f9b0c349a5c83f9278f6b115d334598201d9d7e6 (patch) | |
tree | 474e0928dda4a7fd8340f27ab72bb5bee7683fce /src/onaptests/steps/base.py | |
parent | 9d674116f24285d68a80597202d393b74ac544ce (diff) |
First proposal for the structure for pythonsdk based scenarios
Issue-ID: TEST-240
Change-Id: Ic989b26442b868363af7b3872bff49dd70d78be0
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 | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py new file mode 100644 index 0000000..b32e6d3 --- /dev/null +++ b/src/onaptests/steps/base.py @@ -0,0 +1,84 @@ +from abc import ABC, abstractmethod +from typing import List + + +class BaseStep(ABC): + """Base step class.""" + + def __init__(self, cleanup: bool = False) -> None: + """Step initialization. + + Args: + cleanup(bool, optional): Determines if cleanup action should be called. + + """ + self._steps: List["BaseStep"] = [] + self._cleanup: bool = cleanup + self._parent: "BaseStep" = None + + def add_step(self, step: "BaseStep") -> None: + """Add substep. + + Add substep and mark step as a substep parent. + + Args: + step (BaseStep): Step object + """ + self._steps.append(step) + step._parent: "BaseStep" = self + + @property + def parent(self) -> "BaseStep": + """Step parent. + + If parent is not set the step is a root one. + """ + return self._parent + + @property + def is_root(self) -> bool: + """Is a root step. + + Step is a root if has no parent + + Returns: + bool: True if step is a root step, False otherwise + + """ + return self._parent is None + + def execute(self) -> None: + """Step's action. + + Run all substeps action before it's own action. + Override this method and remember to call `super().action()` before. + + """ + for step in self._steps: + step.execute() + + def cleanup(self) -> None: + """Step's cleanup. + + Not all steps has to have cleanup method + + """ + if self._cleanup: + for step in self._steps: + step.cleanup() + + +class YamlTemplateBaseStep(BaseStep, ABC): + """Base YAML template step.""" + + @property + @abstractmethod + def yaml_template(self) -> dict: + """YAML template abstract property. + + Every YAML template step need to implement that property. + + Returns: + dict: YAML template + + """ |