diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-08-19 12:28:38 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-08-19 12:28:38 +0000 |
commit | f49984630031265bac0a34ee32506dfc8538d4db (patch) | |
tree | 2205e899f33b82271a75d52c096c88a487334b4c /src/onaptests/steps | |
parent | e8c09bbe5a1fd278718ef772c521057ccc3a23d0 (diff) | |
parent | 0e2af06b54eaf80c48b71e88afce16d5a1117a7a (diff) |
Merge "[TEST] Additional cleanup before MSB K8S instance creation"
Diffstat (limited to 'src/onaptests/steps')
-rw-r--r-- | src/onaptests/steps/instantiate/msb_k8s.py | 38 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/msb_k8s.py | 14 |
2 files changed, 42 insertions, 10 deletions
diff --git a/src/onaptests/steps/instantiate/msb_k8s.py b/src/onaptests/steps/instantiate/msb_k8s.py index e6186f5..ba1b732 100644 --- a/src/onaptests/steps/instantiate/msb_k8s.py +++ b/src/onaptests/steps/instantiate/msb_k8s.py @@ -1,4 +1,6 @@ """MSB k8s instantiation module.""" +import time + from onapsdk.configuration import settings from onapsdk.msb.k8s import Instance @@ -6,6 +8,35 @@ from onaptests.steps.base import BaseStep from onaptests.steps.onboard.msb_k8s import CreateProfileStep +class InstancesCleanup(BaseStep): + """Delete old instances which were not cleaned up properly.""" + + @property + def description(self) -> str: + """Step description.""" + return ("Delete old instances which were created using same MSB_K8S_RESOURCE_NAME_PREFIX" + " and were not cleaned up.") + + @property + def component(self) -> str: + """Component name.""" + return "K8S plugin" + + @BaseStep.store_state + def execute(self) -> None: + """Create instance using MSB K8S plugin.""" + super().execute() + self._logger.debug("Delete all instances which are created using definition with same prefix ") + any_deleted: bool = False + for instance in Instance.get_all(): + if instance.request.profile_name.startswith(settings.MSB_K8S_RESOURCE_NAME_PREFIX): + self._logger.debug("Delete %s instance", instance.instance_id) + instance.delete() + any_deleted = True + if any_deleted: + time.sleep(settings.MSB_K8S_CLEANUP_WAIT_TIME) # Give it some time to delete k8s resources (pods, services, deployments...) + + class CreateInstanceStep(BaseStep): """Create MSB k8s instance step.""" @@ -16,6 +47,7 @@ class CreateInstanceStep(BaseStep): - CreateProfileStep. """ super().__init__(cleanup=cleanup) + self.add_step(InstancesCleanup()) self.add_step(CreateProfileStep(cleanup=cleanup)) self.instance: Instance = None @@ -34,9 +66,9 @@ class CreateInstanceStep(BaseStep): """Create instance using MSB K8S plugin.""" super().execute() self.instance = Instance.create(cloud_region_id=settings.CLOUD_REGION_ID, - profile_name=settings.PNF_PROFILE_NAME, - rb_name=settings.PNF_RB_NAME, - rb_version=settings.PNF_RB_VERSION) + profile_name=settings.MSB_K8S_PROFILE_NAME, + rb_name=settings.MSB_K8S_RB_NAME, + rb_version=settings.MSB_K8S_RB_VERSION) @BaseStep.store_state(cleanup=True) def cleanup(self) -> None: diff --git a/src/onaptests/steps/onboard/msb_k8s.py b/src/onaptests/steps/onboard/msb_k8s.py index cad471b..1d2aa82 100644 --- a/src/onaptests/steps/onboard/msb_k8s.py +++ b/src/onaptests/steps/onboard/msb_k8s.py @@ -36,9 +36,9 @@ class CreateDefinitionStep(BaseStep): def execute(self) -> None: """Create definition.""" super().execute() - with open(settings.PNF_DEFINITION_ATRIFACT_FILE_PATH, "rb") as definition_file: - self.definition = Definition.create(rb_name=settings.PNF_RB_NAME, - rb_version=settings.PNF_RB_VERSION) + with open(settings.MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH, "rb") as definition_file: + self.definition = Definition.create(rb_name=settings.MSB_K8S_RB_NAME, + rb_version=settings.MSB_K8S_RB_VERSION) self.definition.upload_artifact(definition_file.read()) @@ -70,10 +70,10 @@ class CreateProfileStep(BaseStep): """Create profile.""" super().execute() definition: Definition = Definition.get_definition_by_name_version(\ - rb_name=settings.PNF_RB_NAME, - rb_version=settings.PNF_RB_VERSION) - with open(settings.PNF_PROFILE_ARTIFACT_FILE_PATH, "rb") as profile_file: - self.profile = definition.create_profile(profile_name=settings.PNF_PROFILE_NAME, + rb_name=settings.MSB_K8S_RB_NAME, + rb_version=settings.MSB_K8S_RB_VERSION) + with open(settings.MSB_K8S_PROFILE_ARTIFACT_FILE_PATH, "rb") as profile_file: + self.profile = definition.create_profile(profile_name=settings.MSB_K8S_PROFILE_NAME, namespace=settings.K8S_NAMESPACE, kubernetes_version=settings.K8S_VERSION) self.profile.upload_artifact(profile_file.read()) |