diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-01-31 08:30:41 +0100 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2024-02-02 08:30:15 +0100 |
commit | 440df5e3af8446ddaf1e7ab9ed5abbbe439f9a06 (patch) | |
tree | 13ee8f0a3839b18eff32a1bcab25a6c5baf00364 /src/onaptests/steps/onboard/pnf.py | |
parent | 6a3e189d7fac6ec562f8785c71ed87663ef0c311 (diff) |
Refactor tests to use SDC v2 onapsdk module
Refactored SDC allows to archive and delete SDC resources
Remove unmaintained test basic_clamp
Issue-ID: TEST-404
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I11e4be6f4567098b20733879e393c689766a9c6e
Diffstat (limited to 'src/onaptests/steps/onboard/pnf.py')
-rw-r--r-- | src/onaptests/steps/onboard/pnf.py | 70 |
1 files changed, 48 insertions, 22 deletions
diff --git a/src/onaptests/steps/onboard/pnf.py b/src/onaptests/steps/onboard/pnf.py index 9b8119a..2f538ec 100644 --- a/src/onaptests/steps/onboard/pnf.py +++ b/src/onaptests/steps/onboard/pnf.py @@ -1,10 +1,16 @@ """PNF onboarding step module.""" +import time +from pathlib import Path + from onapsdk.configuration import settings -from onapsdk.sdc.pnf import Pnf +from onapsdk.exceptions import ResourceNotFound +from onapsdk.sdc2.pnf import Pnf +from onapsdk.sdc2.sdc_resource import LifecycleOperation, LifecycleState from onapsdk.sdc.vendor import Vendor from onapsdk.sdc.vsp import Vsp +from onaptests.utils.resources import get_resource_location from ..base import BaseStep, YamlTemplateBaseStep from .vsp import VspOnboardStep, YamlTemplateVspOnboardStep @@ -56,24 +62,29 @@ class PnfOnboardStep(BaseStep): """ super().execute() - vendor: Vendor = Vendor(name=settings.VENDOR_NAME) - pnf: Pnf = Pnf(name=settings.PNF_NAME, vendor=vendor) - if not pnf.created(): - pnf.create() + try: + pnf: Pnf = Pnf.get_by_name(name=settings.PNF_NAME) + if pnf.lifecycle_state == LifecycleState.CERTIFIED: + return + except ResourceNotFound: + vsp: Vsp = Vsp(name=settings.VSP_NAME) + pnf = Pnf.create(settings.PNF_NAME, vsp=vsp, vendor=vsp.vendor) pnf.add_deployment_artifact( artifact_type=settings.PNF_ARTIFACT_TYPE, artifact_name=settings.PNF_ARTIFACT_NAME, artifact_label=settings.PNF_ARTIFACT_LABEL, - artifact=settings.PNF_ARTIFACT_FILE_PATH + artifact_file_path=settings.PNF_ARTIFACT_FILE_PATH ) - pnf.onboard() + pnf.lifecycle_operation(LifecycleOperation.CERTIFY) @BaseStep.store_state(cleanup=True) def cleanup(self): - pnf: Pnf = Pnf(name=settings.PNF_NAME) - if pnf.exists(): + try: + pnf = Pnf.get_by_name(settings.PNF_NAME) pnf.archive() pnf.delete() + except ResourceNotFound: + self._logger.warning("VF not created") super().cleanup() @@ -131,29 +142,44 @@ class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep): """Onboard PNFs from YAML template.""" super().execute() if "pnfs" in self.yaml_template: - vendor: Vendor = Vendor(name=settings.VENDOR_NAME) for pnf in self.yaml_template["pnfs"]: if "heat_files_to_upload" in pnf: vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP") else: vsp = None - pnf_obj: Pnf = Pnf(name=pnf["pnf_name"], vendor=vendor, vsp=vsp) - if not pnf_obj.created(): - pnf_obj.create() - pnf_obj.add_deployment_artifact( - artifact_type=pnf["pnf_artifact_type"], - artifact_name=pnf["pnf_artifact_name"], - artifact_label=pnf["pnf_artifact_label"], - artifact=pnf["pnf_artifact_file_path"] - ) - pnf_obj.onboard() + try: + pnf_obj: Pnf = Pnf.get_by_name(name=pnf["pnf_name"]) + if pnf_obj.lifecycle_state == LifecycleState.CERTIFIED: + self._logger.info("PNF already created") + return + except ResourceNotFound: + pnf_obj: Pnf = Pnf.create(name=pnf["pnf_name"], + vsp=vsp, + vendor=Vendor(name=pnf["pnf_name"])) + if all(x in pnf for x in ["pnf_artifact_type", + "pnf_artifact_name", + "pnf_artifact_label", + "pnf_artifact_file_path"]): + artifact_file_path: Path = Path(pnf["pnf_artifact_file_path"]) + if not artifact_file_path.exists(): + artifact_file_path = Path(get_resource_location(artifact_file_path)) + pnf_obj.add_deployment_artifact( + artifact_type=pnf["pnf_artifact_type"], + artifact_name=pnf["pnf_artifact_name"], + artifact_label=pnf["pnf_artifact_label"], + artifact_file_path=str(artifact_file_path) + ) + time.sleep(10) + pnf_obj.lifecycle_operation(LifecycleOperation.CERTIFY) @YamlTemplateBaseStep.store_state(cleanup=True) def cleanup(self): if "pnfs" in self.yaml_template: for pnf in self.yaml_template["pnfs"]: - pnf_obj: Pnf = Pnf(name=pnf["pnf_name"]) - if pnf_obj.exists(): + try: + pnf_obj: Pnf = Pnf.get_by_name(name=pnf["pnf_name"]) pnf_obj.archive() pnf_obj.delete() + except ResourceNotFound: + self._logger.warning(f"PNF {pnf['pnf_name']} does not exist") super().cleanup() |