summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2022-01-19 11:54:17 +0000
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2022-01-20 07:23:33 +0000
commit3a370dbe49a9cfae415d5254c91840374330a7ff (patch)
tree6b09591ba0f0437df400f19fa2a0da1c2138aecd
parentd7966b32c11b772ca4a86b600154d79eeeed7f04 (diff)
Add PNF instantiation support
Issue-ID: INT-2047 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I55f124cfee3f8f8260c967cc24e52cd79e680e0b
-rw-r--r--onap_data_provider/resources/service_instance_resource.py53
-rw-r--r--onap_data_provider/schemas/infra_1_1.schema3
-rw-r--r--onap_data_provider/tag_handlers.py3
-rw-r--r--tests/test_service_instance_resource.py33
4 files changed, 65 insertions, 27 deletions
diff --git a/onap_data_provider/resources/service_instance_resource.py b/onap_data_provider/resources/service_instance_resource.py
index b89f9df..b9af670 100644
--- a/onap_data_provider/resources/service_instance_resource.py
+++ b/onap_data_provider/resources/service_instance_resource.py
@@ -15,7 +15,7 @@
limitations under the License.
"""
import logging
-from typing import Any, Dict
+from typing import Any, Dict, List
from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant # type: ignore
from onapsdk.aai.business import Customer, OwningEntity # type: ignore
@@ -27,6 +27,9 @@ from onapsdk.aai.business import ServiceInstance
from onapsdk.so.instantiation import ( # type: ignore
ServiceInstantiation,
SoService,
+ SoServicePnf,
+ SoServiceVfModule,
+ SoServiceVnf
)
from .resource import Resource
@@ -61,7 +64,7 @@ class ServiceInstanceResource(Resource):
raise AttributeError(
"Service not distrbuted - instance can't be created"
)
- if (cloud_region_id := self.data["cloud_region_id"]) is not None:
+ if (cloud_region_id := self.data.get("cloud_region_id")) is not None:
cloud_region: CloudRegion = CloudRegion.get_by_id(
cloud_owner=self.data["cloud_owner"],
cloud_region_id=cloud_region_id,
@@ -196,28 +199,32 @@ class ServiceInstanceResource(Resource):
SoService: SoService object
"""
+ vnfs: List[SoServiceVnf] = []
+ pnfs: List[SoServicePnf] = []
+ for xnf in self.data.get("instantiation_parameters", []):
+ if "vnf_name" in xnf:
+ vnfs.append(SoServiceVnf(
+ model_name=xnf["vnf_name"],
+ instance_name=xnf.get("instance_name", xnf["vnf_name"]),
+ parameters=xnf.get("parameters", {}),
+ vf_modules=[SoServiceVfModule(
+ model_name=vf_module["name"],
+ instance_name=vf_module.get("instance_name", vf_module["name"]),
+ parameters=vf_module.get("parameters", {})
+ ) for vf_module in xnf.get("vf_modules", [])]
+ ))
+ elif "pnf_name" in xnf:
+ pnfs.append(SoServicePnf(
+ model_name=xnf["pnf_name"],
+ instance_name=xnf.get("instance_name", xnf["pnf_name"]),
+ parameters=xnf.get("parameters", {})
+ ))
+ else:
+ logging.warning("Invalid content, xNF type not supported")
return SoService(
- subscription_service_type=self.data.get(
- "service_subscription_type", self.data["service_name"]
- ),
- vnfs=[
- {
- "model_name": vnf["vnf_name"],
- "vnf_name": vnf.get("instance_name", vnf["vnf_name"]),
- "parameters": vnf.get("parameters", {}),
- "vf_modules": [
- {
- "model_name": vf_module["name"],
- "vf_module_name": vf_module.get(
- "instance_name", vf_module["name"]
- ),
- "parameters": vf_module.get("parameters", {}),
- }
- for vf_module in vnf.get("vf_modules", [])
- ],
- }
- for vnf in self.data.get("instantiation_parameters", [])
- ],
+ subscription_service_type=self.service_subscription.service_type,
+ vnfs=vnfs,
+ pnfs=pnfs
)
@property
diff --git a/onap_data_provider/schemas/infra_1_1.schema b/onap_data_provider/schemas/infra_1_1.schema
index 9cb1f09..eac5dcb 100644
--- a/onap_data_provider/schemas/infra_1_1.schema
+++ b/onap_data_provider/schemas/infra_1_1.schema
@@ -429,14 +429,11 @@ properties:
required:
- service_instance_name
- service_name
- - cloud_region
- customer_id
- owning_entity
- project
- platform
- line_of_business
- - cloud_region_id
- - cloud_owner
- aai_service
owning-entities:
type: array
diff --git a/onap_data_provider/tag_handlers.py b/onap_data_provider/tag_handlers.py
index a6b4ba7..1f8a21a 100644
--- a/onap_data_provider/tag_handlers.py
+++ b/onap_data_provider/tag_handlers.py
@@ -14,10 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
-import yaml
import uuid
from typing import Any
+import yaml
+
def join(loader: yaml.SafeLoader, node: yaml.Node) -> str:
"""Concatinates the nodes fields for !join tag.
diff --git a/tests/test_service_instance_resource.py b/tests/test_service_instance_resource.py
index 69a9e57..662aa32 100644
--- a/tests/test_service_instance_resource.py
+++ b/tests/test_service_instance_resource.py
@@ -65,6 +65,21 @@ INSTANTIATION_PARAMETERS_DATA = {
]
}
+PNF_VNF_INSTANTIATION_PARAMETERS_DATA = {
+ "service_name": "service1",
+ "service_subscripion_type": "ss_1",
+ "instantiation_parameters": [
+ {
+ "vnf_name": "test_vnf",
+ "parameters": {"a": "b", "c": "d"}
+ },
+ {
+ "pnf_name": "test_pnf",
+ "instance_name": "test_pnf_instance"
+ }
+ ]
+}
+
@patch(
"onap_data_provider.resources.service_instance_resource.ServiceInstanceResource.service_instance",
@@ -139,3 +154,21 @@ def test_service_instance_resource_version_1_0_and_1_1(mock_aai_service_get_all)
si_resource_1_0 = ServiceInstanceResource(RESOURCE_DATA_1_1)
assert si_resource_1_0.aai_service is not None
mock_aai_service_get_all.assert_called_once()
+
+
+@patch("onap_data_provider.resources.service_instance_resource.ServiceInstanceResource.service_subscription", new_callable=PropertyMock)
+def test_test_service_instance_resource_vnf_and_pnf_instantiation(mock_service_subscription):
+ si_resource = ServiceInstanceResource(PNF_VNF_INSTANTIATION_PARAMETERS_DATA)
+
+ so_service = si_resource.so_service
+ assert len(so_service.vnfs) == 1
+ assert len(so_service.pnfs) == 1
+
+ vnf = so_service.vnfs[0]
+ assert vnf.instance_name == "test_vnf"
+ assert vnf.model_name == "test_vnf"
+ assert vnf.parameters == {"a": "b", "c": "d"}
+
+ pnf = so_service.pnfs[0]
+ assert pnf.instance_name == "test_pnf_instance"
+ assert pnf.model_name == "test_pnf"