diff options
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | src/onaptests/configuration/pnf_macro_settings.py | 12 | ||||
-rw-r--r-- | src/onaptests/steps/base.py | 4 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/k8s_profile_create.py | 4 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/msb_k8s.py | 38 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/service_ala_carte.py | 2 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/service_macro.py | 2 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/vf_module_ala_carte.py | 2 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/vl_ala_carte.py | 2 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/vnf_ala_carte.py | 2 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/msb_k8s.py | 14 |
11 files changed, 59 insertions, 25 deletions
diff --git a/requirements.txt b/requirements.txt index 0abd52a..1c0d5f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ xtesting openstacksdk -onapsdk==7.5.1 +onapsdk==8.1.2 jinja2 kubernetes avionix==0.4.4
\ No newline at end of file diff --git a/src/onaptests/configuration/pnf_macro_settings.py b/src/onaptests/configuration/pnf_macro_settings.py index d9ccb1b..c385847 100644 --- a/src/onaptests/configuration/pnf_macro_settings.py +++ b/src/onaptests/configuration/pnf_macro_settings.py @@ -33,13 +33,15 @@ PLATFORM = "pnf_macro_platform" INSTANTIATION_TIMEOUT = 600 -PNF_DEFINITION_ATRIFACT_FILE_PATH = Path(Path(__file__).parent.parent, +MSB_K8S_CLEANUP_WAIT_TIME = 60 +MSB_K8S_DEFINITION_ATRIFACT_FILE_PATH = Path(Path(__file__).parent.parent, "templates/artifacts/pnf-simulator.tar.gz") -PNF_RB_NAME = f"pnf-cnf-rb-{str(uuid4())}" -PNF_RB_VERSION = "v1" -PNF_PROFILE_ARTIFACT_FILE_PATH = Path(Path(__file__).parent.parent, +MSB_K8S_RESOURCE_NAME_PREFIX = "pnf-cnf" +MSB_K8S_RB_NAME = f"{MSB_K8S_RESOURCE_NAME_PREFIX}-rb-{str(uuid4())}" +MSB_K8S_RB_VERSION = "v1" +MSB_K8S_PROFILE_ARTIFACT_FILE_PATH = Path(Path(__file__).parent.parent, "templates/artifacts/profile.tar.gz") -PNF_PROFILE_NAME = f"pnf-cnf-profile-{str(uuid4())}" +MSB_K8S_PROFILE_NAME = f"{MSB_K8S_RESOURCE_NAME_PREFIX}-profile-{str(uuid4())}" K8S_VERSION = "1.0" K8S_CONFIG = str(Path(Path(__file__).parent.parent, "templates/artifacts/config")) diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py index 6d43fbc..744fc7b 100644 --- a/src/onaptests/steps/base.py +++ b/src/onaptests/steps/base.py @@ -126,8 +126,8 @@ class BaseStep(ABC): if self._cleanup: if self._cleanup_report: yield self._cleanup_report - for step in self._steps: - yield from step.cleanup_reports + for step in self._steps: + yield from step.cleanup_reports @property def name(self) -> str: diff --git a/src/onaptests/steps/instantiate/k8s_profile_create.py b/src/onaptests/steps/instantiate/k8s_profile_create.py index d555d46..fab61a4 100644 --- a/src/onaptests/steps/instantiate/k8s_profile_create.py +++ b/src/onaptests/steps/instantiate/k8s_profile_create.py @@ -125,7 +125,7 @@ class K8SProfileStep(BaseStep): # Define profile (rb_profile) for resource bundle definition # Retrieve resource bundle definition (rbdef) corresponding to vf module rbdef_name = vf_module.metadata["vfModuleModelInvariantUUID"] - rbdef_version = vf_module.metadata["vfModuleModelUUID"] + rbdef_version = vf_module.metadata["vfModuleModelCustomizationUUID"] rbdef = Definition.get_definition_by_name_version(rbdef_name, rbdef_version) # Get k8s profile name from yaml service template vnf_parameters = self.get_vnf_parameters(vnf_instance.vnf.name) @@ -161,7 +161,7 @@ class K8SProfileStep(BaseStep): for vf_module in vnf_instance.vnf.vf_modules: # Retrieve resource bundle definition (rbdef) corresponding to vf module rbdef_name = vf_module.metadata["vfModuleModelInvariantUUID"] - rbdef_version = vf_module.metadata["vfModuleModelUUID"] + rbdef_version = vf_module.metadata["vfModuleModelCustomizationUUID"] rbdef = Definition.get_definition_by_name_version(rbdef_name, rbdef_version) # Get k8s profile name from yaml service template vnf_parameters = self.get_vnf_parameters(vnf_instance.vnf.name) 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/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py index 858db2d..8ce2871 100644 --- a/src/onaptests/steps/instantiate/service_ala_carte.py +++ b/src/onaptests/steps/instantiate/service_ala_carte.py @@ -251,7 +251,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep): Exception: Service cleaning failed """ - service_deletion = self._service_instance.delete() + service_deletion = self._service_instance.delete(a_la_carte=True) try: service_deletion.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT) except TimeoutError: diff --git a/src/onaptests/steps/instantiate/service_macro.py b/src/onaptests/steps/instantiate/service_macro.py index 1264dd8..7ed4952 100644 --- a/src/onaptests/steps/instantiate/service_macro.py +++ b/src/onaptests/steps/instantiate/service_macro.py @@ -214,7 +214,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep): """ if self._service_instance: - service_deletion = self._service_instance.delete() + service_deletion = self._service_instance.delete(a_la_carte=False) try: service_deletion.wait_for_finish(timeout=settings.ORCHESTRATION_REQUEST_TIMEOUT) except TimeoutError: diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py index ee20bc6..65559ca 100644 --- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py +++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py @@ -166,7 +166,7 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep): for vf_module in vnf_instance.vf_modules: self._logger.info("Delete VF Module %s", vf_module.name) - vf_module_deletion = vf_module.delete() + vf_module_deletion = vf_module.delete(a_la_carte=True) try: vf_module_deletion.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT) diff --git a/src/onaptests/steps/instantiate/vl_ala_carte.py b/src/onaptests/steps/instantiate/vl_ala_carte.py index fd040aa..75dcdb9 100644 --- a/src/onaptests/steps/instantiate/vl_ala_carte.py +++ b/src/onaptests/steps/instantiate/vl_ala_carte.py @@ -159,7 +159,7 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep): if settings.CLEANUP_FLAG: for net_instance in self._service_instance.network_instances: self._logger.info("Start network deletion %s",net_instance.name) - net_deletion = net_instance.delete() + net_deletion = net_instance.delete(a_la_carte=True) try: net_deletion.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT) if net_deletion.failed: diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py index 9dc062a..c97add5 100644 --- a/src/onaptests/steps/instantiate/vnf_ala_carte.py +++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py @@ -135,7 +135,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep): """ for vnf_instance in self._service_instance.vnf_instances: - vnf_deletion = vnf_instance.delete() + vnf_deletion = vnf_instance.delete(a_la_carte=True) try: vnf_deletion.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT) 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()) |