diff options
author | Micha? Jagie??o <michal.jagiello@t-mobile.pl> | 2023-10-19 09:16:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-10-19 09:16:45 +0000 |
commit | 4ec44fb58de5c05ecf1735e47af3eebf621eef7f (patch) | |
tree | c341e3db4b14f9f50c99bc11589eb63314a09130 | |
parent | 302843649277556deb8fb885213283f866e90ae8 (diff) | |
parent | a02a458f87329d4d5240b98fdc35f603077948e7 (diff) |
Merge "modify pnf in service(so) patch update"
-rw-r--r-- | src/onapsdk/so/modification.py | 70 | ||||
-rw-r--r-- | src/onapsdk/so/templates/modify_pnf.json.j2 | 94 | ||||
-rw-r--r-- | tests/test_so_pnf_modify.py | 35 |
3 files changed, 199 insertions, 0 deletions
diff --git a/src/onapsdk/so/modification.py b/src/onapsdk/so/modification.py new file mode 100644 index 0000000..0eb725e --- /dev/null +++ b/src/onapsdk/so/modification.py @@ -0,0 +1,70 @@ +"""Modification of the PNF module.""" + +from abc import ABC +from typing import TYPE_CHECKING +from onapsdk.aai.business.owning_entity import OwningEntity +from onapsdk.onap_service import OnapService +from onapsdk.so.so_element import OrchestrationRequest +from onapsdk.utils.headers_creator import headers_so_creator +from onapsdk.utils.jinja import jinja_env +from onapsdk.configuration import settings + +if TYPE_CHECKING: + from onapsdk.aai.business.service import ServiceInstance + from onapsdk.aai.business import PnfInstance as Pnf + + +class PnfModificationRequest(OrchestrationRequest, ABC): + """PNF Modification class.""" + + @classmethod + def send_request(cls, + pnf_object: "Pnf", + sdc_service: "Service", + aai_service_instance: "ServiceInstance") -> "PnfModificationRequest": + """Send request to SO to modify PNF instance. + + Args: + pnf_object: pnf object for pnf id + sdc_service: service for modify pnf + aai_service_instance: Service object from aai sdc + + Returns: + PnfModificationRequest: modify request object + + """ + owning_entity_id = None + project = settings.PROJECT + line_of_business = settings.LOB + platform = settings.PLATFORM + + for rel in aai_service_instance.relationships: + if rel.related_to == "owning-entity": + owning_entity_id = rel.relationship_data.pop().get("relationship-value") + if rel.related_to == "project": + project = rel.relationship_data.pop().get("relationship-value") + + owning_entity = OwningEntity.get_by_owning_entity_id( + owning_entity_id=owning_entity_id) + + cls._logger.debug("PNF %s modify request", pnf_object.pnf_id) + response = cls.send_message_json("PUT", + f"Create {pnf_object.pnf_id} PNF modification request", + (f"{cls.base_url}/onap/so/infra/" + f"serviceInstantiation/{cls.api_version}/" + "serviceInstances/" + f"{aai_service_instance.instance_id}/" + f"pnfs/{pnf_object.pnf_id}"), + data=jinja_env(). + get_template("modify_pnf.json.j2"). + render( + platform_name=platform, + service=sdc_service, + project=project, + owning_entity=owning_entity, + line_of_business=line_of_business, + service_instance=aai_service_instance + ), + headers=headers_so_creator(OnapService.headers)) + + return cls(request_id=response["requestReferences"]["requestId"]) diff --git a/src/onapsdk/so/templates/modify_pnf.json.j2 b/src/onapsdk/so/templates/modify_pnf.json.j2 new file mode 100644 index 0000000..898e549 --- /dev/null +++ b/src/onapsdk/so/templates/modify_pnf.json.j2 @@ -0,0 +1,94 @@ +{ + "requestDetails": { + "modelInfo": { + "modelInvariantId": "{{ service.unique_uuid }}", + "modelType": "service", + "modelName": "{{ service.name }}", + "modelVersion": "1.0", + "modelVersionId": "{{ service.identifier }}", + "modelUuid": "{{ service.identifier }}" + }, + "requestInfo": { + "productFamilyId": "5G", + "source": "VID", + "instanceName": "{{ service_instance.instance_name }}", + "suppressRollback": false, + "requestorId": "NBI" + }, + "subscriberInfo": { + "globalSubscriberId": "{{ service_instance.service_subscription.customer.global_customer_id }}" + }, + "requestParameters": { + "subscriptionServiceType": "{{ service.name }}", + "userParams": [ + { + "service": { + "modelInfo": { + "modelVersionId": "{{ service.identifier }}", + "modelName": "{{ service.name }}", + "modelType": "service" + }, + "instanceName": "{{ service_instance.instance_name }}", + "instanceParams": [], + "resources": { + {% block pnfs %} + {% if service.pnfs %} + "pnfs": [ + {% for pnf in service.pnfs %} + { + "modelInfo": { + "modelType": "pnf", + "modelInvariantId": "{{ pnf.model_invariant_id }}", + "modelVersionId": "{{ pnf.model_version_id }}", + "modelName": "{{ service.name }}", + "modelVersion": "1.0", + "modelCustomizationId": "{{ pnf.model_customization_id }}", + "modelCustomizationName": "{{ pnf.name }}" + }, + "platform": { + "platformName": "{{ platform_name }}" + }, + "lineOfBusiness": { + "lineOfBusinessName": "{{ line_of_business }}" + }, + "pnfRegistrationFields": { + "modelNumber": "Simulated Device Melacon", + "oamV4IpAddress": "10.42.6.245", + "oamV6IpAddress": "0:0:0:0:0:ffff:a0a:011", + "serialNumber": "ORAN_SIM-172.30.1.6-400600927-Simulated Device Melacon", + "softwareVersion": "2.3.5", + "unitType": "ntsim_oran", + "vendorName": "Melacon" + }, + "productFamilyId": "5G", + "instanceParams": [ + { + "text": "test-pnf-level" + } + ], + "instanceName": "{{ service_instance.instance_name }}", + "processingPriority": 1 + } + {% endfor %} + ] + {% endif %} + {% endblock %} + } + } + }, + { + "Homing_Solution": "none" + } + ], + "aLaCarte": false, + "usePreload": false + }, + "project": { + "projectName": "{{ project }}" + }, + "owningEntity": { + "owningEntityId": "{{ owning_entity.owning_entity_id }}", + "owningEntityName": "{{ owning_entity.name }}" + } + } +} diff --git a/tests/test_so_pnf_modify.py b/tests/test_so_pnf_modify.py new file mode 100644 index 0000000..4a7391a --- /dev/null +++ b/tests/test_so_pnf_modify.py @@ -0,0 +1,35 @@ +from unittest import mock + +from onapsdk.so.modification import PnfModificationRequest +from onapsdk.aai.business.owning_entity import OwningEntity + + +@mock.patch.object(PnfModificationRequest, "send_message_json") +@mock.patch.object(OwningEntity, "get_by_owning_entity_id") +def test_pnf_modification(mock_owning_entity_get, mock_pnf_modification_send_message): + aai_service_instance_mock = mock.MagicMock() + aai_service_instance_mock.instance_id = "test_instance_id" + + pnf_object_mock = mock.MagicMock() + pnf_object_mock.pnf_id = "test_pnf_id" + + relation_1 = mock.MagicMock() + relation_1.related_to = "owning-entity" + relation_1.relationship_data = [{"relationship-value": "test"}] + relation_2 = mock.MagicMock() + relation_2.related_to = "project" + relation_2.relationship_data = [{"relationship-value": "test"}] + + aai_service_instance_mock.relationships = (item for item in [relation_1, relation_2]) + + pnf_modification = PnfModificationRequest. \ + send_request(aai_service_instance=aai_service_instance_mock, + pnf_object=pnf_object_mock, + sdc_service=mock.MagicMock()) + + mock_pnf_modification_send_message.assert_called_once() + method, _, url = mock_pnf_modification_send_message.call_args[0] + assert method == "PUT" + assert url == (f"{PnfModificationRequest.base_url}/onap/so/infra/serviceInstantiation/" + f"{PnfModificationRequest.api_version}/serviceInstances/" + f"{aai_service_instance_mock.instance_id}/pnfs/{pnf_object_mock.pnf_id}") |