aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcin Przybysz <marcin.przybysz@nokia.com>2020-12-09 07:57:06 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-09 07:57:06 +0000
commit072111083d22cb68a1679abbc8108430183846c4 (patch)
tree82b693b08c55136233f5710c4d03cdfae5f2543d
parent0d1b490d0eb95948354a18bfced173f4f0a5c516 (diff)
parente163051a31f9d6255a4bf34d379945a6a9c2ef37 (diff)
Merge "PNF onboarding step" into guilin
-rw-r--r--src/onaptests/steps/base.py1
-rw-r--r--src/onaptests/steps/onboard/pnf.py114
-rw-r--r--src/onaptests/steps/onboard/service.py99
3 files changed, 203 insertions, 11 deletions
diff --git a/src/onaptests/steps/base.py b/src/onaptests/steps/base.py
index 8d70405..9e1c991 100644
--- a/src/onaptests/steps/base.py
+++ b/src/onaptests/steps/base.py
@@ -29,7 +29,6 @@ class BaseStep(ABC):
except AttributeError:
pass
-
def __init__(self, cleanup: bool = False) -> None:
"""Step initialization.
diff --git a/src/onaptests/steps/onboard/pnf.py b/src/onaptests/steps/onboard/pnf.py
new file mode 100644
index 0000000..12f2561
--- /dev/null
+++ b/src/onaptests/steps/onboard/pnf.py
@@ -0,0 +1,114 @@
+"""PNF onboarding step module."""
+
+from onapsdk.configuration import settings
+from onapsdk.sdc.pnf import Pnf
+from onapsdk.sdc.vendor import Vendor
+from ..base import BaseStep, YamlTemplateBaseStep
+from .vendor import VendorOnboardStep
+
+
+class PnfOnboardStep(BaseStep):
+ """PNF onboard step."""
+
+ def __init__(self, cleanup: bool = False) -> None:
+ """Step initialization.
+
+ Substeps:
+ - VendorOnboardStep.
+
+ Args:
+ cleanup(bool, optional): Determines if cleanup action should be called.
+
+ """
+ super().__init__(cleanup=cleanup)
+ self.add_step(VendorOnboardStep(cleanup=cleanup))
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Onboard pnf in SDC."
+
+ @property
+ def component(self) -> str:
+ """Component name."""
+ return "SDC"
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ """Onboard PNF in SDC.
+
+ Use settings values:
+ - VENDOR_NAME,
+ - PNF_NAME,
+ - PNF_ARTIFACT_TYPE,
+ - PNF_ARTIFACT_NAME,
+ - PNF_ARTIFACT_LABEL,
+ - PNF_ARTIFACT_FILE_PATH
+
+ """
+ vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
+ pnf: Pnf = Pnf(name=settings.PNF_NAME, vendor=vendor)
+ pnf.create()
+ 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
+ )
+ pnf.onboard()
+
+
+class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep):
+ """PNF onboard using YAML template step."""
+
+ def __init__(self, cleanup: bool = False) -> None:
+ """Step initialization.
+
+ Substeps:
+ - VendorOnboardStep.
+
+ Args:
+ cleanup(bool, optional): Determines if cleanup action should be called.
+
+ """
+ super().__init__(cleanup=cleanup)
+ self.add_step(VendorOnboardStep(cleanup=cleanup))
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Onboard pnf using YAML template in SDC."
+
+ @property
+ def component(self) -> str:
+ """Component name."""
+ return "SDC"
+
+ @property
+ def yaml_template(self) -> dict:
+ """YAML template.
+
+ Get YAML template from parent using it's name.
+
+ Returns:
+ dict: YAML template
+
+ """
+ return self.parent.yaml_template[self.parent.service_name]
+
+ @YamlTemplateBaseStep.store_state
+ def execute(self):
+ """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"]:
+ pnf_obj: Pnf = Pnf(name=pnf["pnf_name"], vendor=vendor)
+ 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()
diff --git a/src/onaptests/steps/onboard/service.py b/src/onaptests/steps/onboard/service.py
index 3c8b183..8ec9165 100644
--- a/src/onaptests/steps/onboard/service.py
+++ b/src/onaptests/steps/onboard/service.py
@@ -1,11 +1,16 @@
+from typing import Any, Dict
from yaml import load
from onapsdk.configuration import settings
-from onapsdk.sdc.service import Service
+from onapsdk.sdc.component import Component
+from onapsdk.sdc.pnf import Pnf
+from onapsdk.sdc.properties import ComponentProperty
+from onapsdk.sdc.service import Service, ServiceInstantiationType
from onapsdk.sdc.vf import Vf
from onapsdk.sdc.vl import Vl
from ..base import BaseStep, YamlTemplateBaseStep
+from .pnf import PnfOnboardStep, YamlTemplatePnfOnboardStep
from .vf import VfOnboardStep, YamlTemplateVfOnboardStep
@@ -19,7 +24,10 @@ class ServiceOnboardStep(BaseStep):
- VfOnboardStep.
"""
super().__init__(cleanup=cleanup)
- self.add_step(VfOnboardStep(cleanup=cleanup))
+ if settings.VF_NAME != "":
+ self.add_step(VfOnboardStep(cleanup=cleanup))
+ if settings.PNF_NAME != "":
+ self.add_step(PnfOnboardStep(cleanup=cleanup))
@property
def description(self) -> str:
@@ -38,11 +46,13 @@ class ServiceOnboardStep(BaseStep):
Use settings values:
- VL_NAME,
- VF_NAME,
- - SERVICE_NAME.
+ - PNF_NAME,
+ - SERVICE_NAME,
+ - SERVICE_INSTANTIATION_TYPE.
"""
super().execute()
- service: Service = Service(name=settings.SERVICE_NAME)
+ service: Service = Service(name=settings.SERVICE_NAME, instantiation_type=settings.SERVICE_INSTANTIATION_TYPE)
service.create()
if settings.VL_NAME != "":
vl: Vl = Vl(name=settings.VL_NAME)
@@ -50,6 +60,9 @@ class ServiceOnboardStep(BaseStep):
if settings.VF_NAME != "":
vf: Vf = Vf(name=settings.VF_NAME)
service.add_resource(vf)
+ if settings.PNF_NAME != "":
+ pnf: Pnf = Pnf(name=settings.PNF_NAME)
+ service.add_resource(pnf)
service.checkin()
service.onboard()
@@ -65,7 +78,10 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep):
"""
super().__init__(cleanup=cleanup)
self._yaml_template: dict = None
- self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup))
+ if "vnfs" in self.yaml_template[self.service_name]:
+ self.add_step(YamlTemplateVfOnboardStep(cleanup=cleanup))
+ if "pnfs" in self.yaml_template[self.service_name]:
+ self.add_step(YamlTemplatePnfOnboardStep(cleanup=cleanup))
@property
def description(self) -> str:
@@ -106,15 +122,33 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep):
"""
if self.is_root:
return next(iter(self.yaml_template.keys()))
- else:
- return self.parent.service_name
+ return self.parent.service_name
@YamlTemplateBaseStep.store_state
def execute(self):
"""Onboard service."""
super().execute()
- service: Service = Service(name=settings.SERVICE_NAME)
+ if "instantiation_type" in self.yaml_template[self.service_name]:
+ instantiation_type: ServiceInstantiationType = ServiceInstantiationType(
+ self.yaml_template[self.service_name]["instantiation_type"])
+ else:
+ instantiation_type: ServiceInstantiationType = ServiceInstantiationType.A_LA_CARTE
+ service: Service = Service(name=settings.SERVICE_NAME, instantiation_type=instantiation_type)
service.create()
+ self.declare_resources(service)
+ self.assign_properties(service)
+ service.checkin()
+ service.onboard()
+
+ def declare_resources(self, service: Service) -> None:
+ """Declare resources.
+
+ Resources defined in YAML template are declared.
+
+ Args:
+ service (Service): Service object
+
+ """
if "networks" in self.yaml_template[self.service_name]:
for net in self.yaml_template[self.service_name]["networks"]:
vl: Vl = Vl(name=net['vl_name'])
@@ -123,5 +157,50 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep):
for vnf in self.yaml_template[self.service_name]["vnfs"]:
vf: Vf = Vf(name=vnf["vnf_name"])
service.add_resource(vf)
- service.checkin()
- service.onboard()
+ if "pnfs" in self.yaml_template[self.service_name]:
+ for pnf in self.yaml_template[self.service_name]["pnfs"]:
+ pnf_obj: Pnf = Pnf(name=pnf["pnf_name"])
+ service.add_resource(pnf_obj)
+
+ def assign_properties(self, service: Service) -> None:
+ """Assign components properties.
+
+ For each component set properties and it's value if are declared
+ in YAML template.
+
+ Args:
+ service (Service): Service object
+
+ """
+ if "networks" in self.yaml_template[self.service_name]:
+ for net in self.yaml_template[self.service_name]["networks"]:
+ if "properties" in net:
+ vl: Vl = Vl(name=net['vl_name'])
+ vl_component: Component = service.get_component(vl)
+ self.assign_properties_to_component(vl_component, net["properties"])
+ if "vnfs" in self.yaml_template[self.service_name]:
+ for vnf in self.yaml_template[self.service_name]["vnfs"]:
+ if "properties" in vnf:
+ vf: Vf = Vf(name=vnf["vnf_name"])
+ vf_component: Component = service.get_component(vf)
+ self.assign_properties_to_component(vf_component, vnf["properties"])
+ if "pnfs" in self.yaml_template[self.service_name]:
+ for pnf in self.yaml_template[self.service_name]["pnfs"]:
+ if "properties" in pnf:
+ pnf_obj: Pnf = Pnf(name=pnf["pnf_name"])
+ pnf_component: Component = service.get_component(pnf_obj)
+ self.assign_properties_to_component(pnf_component, pnf["properties"])
+
+ def assign_properties_to_component(self,
+ component: Component,
+ component_properties: Dict[str, Any]) -> None:
+ """Assign properties to component.
+
+ Args:
+ component (Component): Component to which properites are going to be assigned
+ component_properties (Dict[str, Any]): Properties dictionary
+
+ """
+ for property_name, property_value in component_properties.items():
+ prop: ComponentProperty = component.get_property(property_name)
+ prop.value = property_value