diff options
author | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2023-07-27 14:59:15 +0000 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> | 2023-08-05 17:11:09 +0000 |
commit | 4bccbde3060931c8fcf61fbf8b61db4a85b3200e (patch) | |
tree | f3e58c61d142d84e96718215355c1ce6913b57c9 /src/onaptests/steps/onboard/service.py | |
parent | 2ffd98c9d0b85b7c6c6b0bf61cd9e848234914ce (diff) |
Change cleanup process of tests
Issue-ID: TEST-402
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: Iffe3aeaa4eab6adcabc94d143d1f94a684cd4657
Diffstat (limited to 'src/onaptests/steps/onboard/service.py')
-rw-r--r-- | src/onaptests/steps/onboard/service.py | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/onaptests/steps/onboard/service.py b/src/onaptests/steps/onboard/service.py index c0bec0d..be0f6fd 100644 --- a/src/onaptests/steps/onboard/service.py +++ b/src/onaptests/steps/onboard/service.py @@ -20,17 +20,17 @@ from .vf import VfOnboardStep, YamlTemplateVfOnboardStep class ServiceOnboardStep(BaseStep): """Service onboard step.""" - def __init__(self, cleanup=False): + def __init__(self): """Initialize step. Substeps: - VfOnboardStep. """ - super().__init__(cleanup=cleanup) + super().__init__(cleanup=settings.CLEANUP_FLAG) if settings.VF_NAME != "": - self.add_step(VfOnboardStep(cleanup=cleanup)) + self.add_step(VfOnboardStep()) if settings.PNF_NAME != "": - self.add_step(PnfOnboardStep(cleanup=cleanup)) + self.add_step(PnfOnboardStep()) @property def description(self) -> str: @@ -42,6 +42,13 @@ class ServiceOnboardStep(BaseStep): """Component name.""" return "SDC" + def check_preconditions(self, cleanup=False) -> bool: + if not super().check_preconditions(cleanup): + return False + if cleanup: + return settings.SDC_CLEANUP + return True + @BaseStep.store_state def execute(self): """Onboard service. @@ -97,19 +104,19 @@ class ServiceOnboardStep(BaseStep): class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): """Service onboard using YAML template step.""" - def __init__(self, cleanup=False): + def __init__(self): """Initialize step. Substeps: - YamlTemplateVfOnboardStep. """ - super().__init__(cleanup=cleanup) + super().__init__(cleanup=settings.CLEANUP_FLAG) self._yaml_template: dict = None self._model_yaml_template: dict = None if "vnfs" in self.yaml_template[self.service_name]: - self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup)) + self.add_step(YamlTemplateVfOnboardStep()) if "pnfs" in self.yaml_template[self.service_name]: - self.add_step(YamlTemplatePnfOnboardStep(cleanup=cleanup)) + self.add_step(YamlTemplatePnfOnboardStep()) @property def description(self) -> str: @@ -121,6 +128,13 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): """Component name.""" return "SDC" + def check_preconditions(self, cleanup=False) -> bool: + if not super().check_preconditions(cleanup): + return False + if cleanup: + return settings.SDC_CLEANUP + return True + @property def yaml_template(self) -> dict: """Step YAML template. @@ -153,7 +167,7 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): if self.is_root: if not self._model_yaml_template: with open(settings.MODEL_YAML_TEMPLATE, "r") as model_yaml_template: - self._model_yaml_template: dict = load(model_yaml_template) + self._model_yaml_template: dict = load(model_yaml_template, SafeLoader) return self._model_yaml_template return self.parent.model_yaml_template @@ -269,9 +283,8 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): @YamlTemplateBaseStep.store_state(cleanup=True) def cleanup(self) -> None: """Cleanup service onboard step.""" - if settings.SDC_CLEANUP: - service: Service = Service(name=self.service_name) - if service.exists(): - service.archive() - service.delete() - super().cleanup() + service: Service = Service(name=self.service_name) + if service.exists(): + service.archive() + service.delete() + super().cleanup() |