aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2024-02-06 21:46:29 +0100
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2024-02-07 12:56:53 +0100
commit6dc28a85e25b81bada36a1c21ba501e81a1e02c8 (patch)
treecfb4754f6c340fd924df3a18267df79653caa78e
parent1404b9e8f3da4181da66f957b2a99a5c4430544e (diff)
Make archive optional on cleanup
If sdc element was not onboarded properly it cannot be archived but still can be deleted Issue-ID: TEST-404 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: I80836c7bd7735de86c09ebc0ef0b6ea4a21c78fb
-rw-r--r--src/onaptests/steps/onboard/pnf.py7
-rw-r--r--src/onaptests/steps/onboard/service.py11
-rw-r--r--src/onaptests/steps/onboard/vendor.py21
-rw-r--r--src/onaptests/steps/onboard/vf.py8
-rw-r--r--src/onaptests/steps/onboard/vsp.py21
5 files changed, 41 insertions, 27 deletions
diff --git a/src/onaptests/steps/onboard/pnf.py b/src/onaptests/steps/onboard/pnf.py
index 2f538ec..c7dde5f 100644
--- a/src/onaptests/steps/onboard/pnf.py
+++ b/src/onaptests/steps/onboard/pnf.py
@@ -11,6 +11,7 @@ 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
@@ -81,7 +82,8 @@ class PnfOnboardStep(BaseStep):
def cleanup(self):
try:
pnf = Pnf.get_by_name(settings.PNF_NAME)
- pnf.archive()
+ if pnf.lifecycle_state == LifecycleState.CERTIFIED:
+ pnf.archive()
pnf.delete()
except ResourceNotFound:
self._logger.warning("VF not created")
@@ -178,7 +180,8 @@ class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep):
for pnf in self.yaml_template["pnfs"]:
try:
pnf_obj: Pnf = Pnf.get_by_name(name=pnf["pnf_name"])
- pnf_obj.archive()
+ if pnf_obj.lifecycle_state == LifecycleState.CERTIFIED:
+ pnf_obj.archive()
pnf_obj.delete()
except ResourceNotFound:
self._logger.warning(f"PNF {pnf['pnf_name']} does not exist")
diff --git a/src/onaptests/steps/onboard/service.py b/src/onaptests/steps/onboard/service.py
index a9a3b14..cb2e59d 100644
--- a/src/onaptests/steps/onboard/service.py
+++ b/src/onaptests/steps/onboard/service.py
@@ -1,14 +1,15 @@
from typing import Any, Dict
-from yaml import SafeLoader, load
from onapsdk.configuration import settings
from onapsdk.exceptions import ResourceNotFound
+from onapsdk.sdc2.component_instance import (ComponentInstance,
+ ComponentInstanceInput)
from onapsdk.sdc2.pnf import Pnf
-from onapsdk.sdc2.component_instance import ComponentInstance, ComponentInstanceInput
from onapsdk.sdc2.sdc_resource import LifecycleOperation, LifecycleState
from onapsdk.sdc2.service import Service, ServiceInstantiationType
from onapsdk.sdc2.vf import Vf
from onapsdk.sdc2.vl import Vl
+from yaml import SafeLoader, load
from ..base import BaseStep, YamlTemplateBaseStep
from .pnf import PnfOnboardStep, YamlTemplatePnfOnboardStep
@@ -85,7 +86,8 @@ class ServiceOnboardStep(BaseStep):
"""Cleanup service onboard step."""
try:
service: Service = Service.get_by_name(name=settings.SERVICE_NAME)
- service.archive()
+ if service.lifecycle_state == LifecycleState.CERTIFIED:
+ service.archive()
service.delete()
except ResourceNotFound:
self._logger.info(f"Service {settings.SERVICE_NAME} not found")
@@ -252,7 +254,8 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep):
"""Cleanup service onboard step."""
try:
service: Service = Service.get_by_name(name=self.service_name)
- service.archive()
+ if service.lifecycle_state == LifecycleState.CERTIFIED:
+ service.archive()
service.delete()
except ResourceNotFound:
self._logger.info(f"Service {self.service_name} not found")
diff --git a/src/onaptests/steps/onboard/vendor.py b/src/onaptests/steps/onboard/vendor.py
index 5be358b..6ea05cd 100644
--- a/src/onaptests/steps/onboard/vendor.py
+++ b/src/onaptests/steps/onboard/vendor.py
@@ -1,3 +1,4 @@
+import onapsdk.constants as const
from onapsdk.configuration import settings
from onapsdk.sdc.vendor import Vendor
@@ -44,7 +45,8 @@ class VendorOnboardStep(BaseStep):
def cleanup(self) -> None:
vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
if vendor.exists():
- vendor.archive()
+ if vendor.status == const.CERTIFIED:
+ vendor.archive()
vendor.delete()
super().cleanup()
@@ -116,18 +118,19 @@ class YamlTemplateVendorOnboardStep(YamlTemplateBaseStep):
vendor: Vendor = Vendor(name=f"{pnf['pnf_name']}")
vendor.onboard()
+ def _cleanup_vendor(self, name):
+ vendor: Vendor = Vendor(name=name)
+ if vendor.exists():
+ if vendor.status == const.CERTIFIED:
+ vendor.archive()
+ vendor.delete()
+
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
if "vnfs" in self.yaml_template:
for vnf in self.yaml_template["vnfs"]:
- vendor: Vendor = Vendor(name=f"{vnf['vnf_name']}")
- if vendor.exists():
- vendor.archive()
- vendor.delete()
+ self._cleanup_vendor(f"{vnf['vnf_name']}")
elif "pnfs" in self.yaml_template:
for pnf in self.yaml_template["pnfs"]:
- vendor: Vendor = Vendor(name=f"{pnf['pnf_name']}")
- if vendor.exists():
- vendor.archive()
- vendor.delete()
+ self._cleanup_vendor(f"{pnf['pnf_name']}")
super().cleanup()
diff --git a/src/onaptests/steps/onboard/vf.py b/src/onaptests/steps/onboard/vf.py
index 3e286d9..08fe1f3 100644
--- a/src/onaptests/steps/onboard/vf.py
+++ b/src/onaptests/steps/onboard/vf.py
@@ -3,8 +3,8 @@ from pathlib import Path
from onapsdk.configuration import settings
from onapsdk.exceptions import ResourceNotFound
-from onapsdk.sdc2.vf import Vf
from onapsdk.sdc2.sdc_resource import LifecycleOperation, LifecycleState
+from onapsdk.sdc2.vf import Vf
from onapsdk.sdc.vsp import Vsp
from onaptests.utils.resources import get_resource_location
@@ -65,7 +65,8 @@ class VfOnboardStep(BaseStep):
def cleanup(self):
try:
vf = Vf.get_by_name(settings.VF_NAME)
- vf.archive()
+ if vf.lifecycle_state == LifecycleState.CERTIFIED:
+ vf.archive()
vf.delete()
except ResourceNotFound:
self._logger.warning("VF not created")
@@ -163,7 +164,8 @@ class YamlTemplateVfOnboardStep(YamlTemplateBaseStep):
for vnf in self.yaml_template["vnfs"]:
try:
vf_obj: Vf = Vf.get_by_name(name=vnf["vnf_name"])
- vf_obj.archive()
+ if vf_obj.lifecycle_state == LifecycleState.CERTIFIED:
+ vf_obj.archive()
vf_obj.delete()
except ResourceNotFound:
self._logger.warning(f"VF {vnf['vnf_name']} does not exist")
diff --git a/src/onaptests/steps/onboard/vsp.py b/src/onaptests/steps/onboard/vsp.py
index 4d279c8..75c6c5e 100644
--- a/src/onaptests/steps/onboard/vsp.py
+++ b/src/onaptests/steps/onboard/vsp.py
@@ -1,3 +1,4 @@
+import onapsdk.constants as const
from onapsdk.configuration import settings
from onapsdk.sdc.vendor import Vendor
from onapsdk.sdc.vsp import Vsp
@@ -59,7 +60,8 @@ class VspOnboardStep(BaseStep):
def cleanup(self):
vsp: Vsp = Vsp(name=settings.VSP_NAME)
if vsp.exists():
- vsp.archive()
+ if vsp.status == const.CERTIFIED:
+ vsp.archive()
vsp.delete()
super().cleanup()
@@ -143,18 +145,19 @@ class YamlTemplateVspOnboardStep(YamlTemplateBaseStep):
package=package)
vsp.onboard()
+ def _cleanup_vsp(self, name):
+ vsp: Vsp = Vsp(name=name)
+ if vsp.exists():
+ if vsp.status == const.CERTIFIED:
+ vsp.archive()
+ vsp.delete()
+
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
if "vnfs" in self.yaml_template:
for vnf in self.yaml_template["vnfs"]:
- vsp: Vsp = Vsp(name=f"{vnf['vnf_name']}_VSP")
- if vsp.exists():
- vsp.archive()
- vsp.delete()
+ self._cleanup_vsp(f"{vnf['vnf_name']}_VSP")
elif "pnfs" in self.yaml_template:
for pnf in self.yaml_template["pnfs"]:
- vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP")
- if vsp.exists():
- vsp.archive()
- vsp.delete()
+ self._cleanup_vsp(f"{pnf['pnf_name']}_VSP")
super().cleanup()