aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_so_instantiation.py
diff options
context:
space:
mode:
authorSreeja Gattagouni <sg00744975@techmahindra.com>2023-05-19 07:20:37 +0000
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2023-05-25 10:34:45 +0000
commit3860bac3bf74c485eebb0327e9125d6b45685278 (patch)
treefdce842bbf15f9ffcb4b549cb46b06515abdf4cb /tests/test_so_instantiation.py
parent676cfced1bf3b1602e99288f20ae1d3e91031f49 (diff)
Addition-Deletion PNF Support in Automation(Macro-Flow)
-PNF Additon Support -PNF Deletion Support Issue-ID: INT-2211 Change-ID:I73f97f986a817d423f92f8d925dcd0947b8a2525 Signed-off-by: Sreeja Gattagouni <sg00744975@techmahindra.com>
Diffstat (limited to 'tests/test_so_instantiation.py')
-rw-r--r--tests/test_so_instantiation.py174
1 files changed, 174 insertions, 0 deletions
diff --git a/tests/test_so_instantiation.py b/tests/test_so_instantiation.py
index ec796a9..1374b84 100644
--- a/tests/test_so_instantiation.py
+++ b/tests/test_so_instantiation.py
@@ -31,6 +31,7 @@ from onapsdk.so.instantiation import (
SoServiceVnf,
VfModuleInstantiation,
VnfInstantiation,
+ PnfInstantiation,
ServiceOperation,
VnfOperation
)
@@ -344,6 +345,71 @@ def test_vnf_instantiation_macro(mock_owning_entity_get, mock_vnf_instantiation_
so_vnf=so_vnf_mock)
assert vnf_instantiation.name == "SoVnfInstanceName"
+@mock.patch.object(PnfInstantiation, "send_message_json")
+@mock.patch.object(OwningEntity, "get_by_owning_entity_id")
+def test_pnf_instantiation_macro(mock_owning_entity_get, mock_pnf_instantiation_send_message):
+ aai_service_instance_mock = mock.MagicMock()
+ aai_service_instance_mock.instance_id = "test_instance_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_instantiation = PnfInstantiation.\
+ instantiate_macro(aai_service_instance=aai_service_instance_mock,
+ pnf_object=mock.MagicMock(),
+ line_of_business="test_lob",
+ platform="test_platform",
+ cloud_region=mock.MagicMock(),
+ tenant=mock.MagicMock(),
+ sdc_service=mock.MagicMock())
+ assert pnf_instantiation.name.startswith("Python_ONAP_SDK_pnf_instance_")
+ mock_pnf_instantiation_send_message.assert_called_once()
+ method, _, url = mock_pnf_instantiation_send_message.call_args[0]
+ assert method == "POST"
+ assert url == (f"{PnfInstantiation.base_url}/onap/so/infra/serviceInstantiation/"
+ f"{PnfInstantiation.api_version}/serviceInstances/"
+ f"{aai_service_instance_mock.instance_id}/pnfs")
+
+ pnf_instantiation = PnfInstantiation. \
+ instantiate_macro(aai_service_instance=aai_service_instance_mock,
+ pnf_object=mock.MagicMock(),
+ line_of_business="test_lob",
+ platform="test_platform",
+ pnf_instance_name="test",
+ cloud_region=mock.MagicMock(),
+ tenant=mock.MagicMock(),
+ sdc_service=mock.MagicMock())
+ assert pnf_instantiation.name == "test"
+
+ pnf_instantiation = PnfInstantiation. \
+ instantiate_macro(aai_service_instance=aai_service_instance_mock,
+ pnf_object=mock.MagicMock(),
+ line_of_business="test_lob",
+ platform="test_platform",
+ cloud_region=mock.MagicMock(),
+ tenant=mock.MagicMock(),
+ sdc_service=mock.MagicMock(),
+ so_pnf=mock.MagicMock())
+ assert pnf_instantiation.name.startswith("Python_ONAP_SDK_service_instance_")
+
+ so_pnf_mock = mock.MagicMock()
+ so_pnf_mock.instance_name = "SoPnfInstanceName"
+ pnf_instantiation = PnfInstantiation. \
+ instantiate_macro(aai_service_instance=aai_service_instance_mock,
+ pnf_object=mock.MagicMock(),
+ line_of_business="test_lob",
+ platform="test_platform",
+ cloud_region=mock.MagicMock(),
+ tenant=mock.MagicMock(),
+ sdc_service=mock.MagicMock(),
+ so_pnf=so_pnf_mock)
+ assert pnf_instantiation.name == "SoPnfInstanceName"
@mock.patch.object(VnfInstantiation, "send_message_json")
@mock.patch.object(OwningEntity, "get_by_owning_entity_id")
@@ -626,6 +692,114 @@ def test_vnf_instantiation_get_by_vnf_instance_name(mock_sdc_service, mock_send_
}
assert VnfInstantiation.get_by_vnf_instance_name("test_vnf_instance_name") is not None
+@mock.patch.object(Vid, "send_message")
+@mock.patch.object(PnfInstantiation, "send_message_json")
+@mock.patch("onapsdk.so.instantiation.SdcService")
+def test_pnf_instantiation_get_by_pnf_instance_name(mock_sdc_service, mock_send_message_json, mock_send):
+ mock_sdc_service.return_value.pnfs = []
+ mock_send_message_json.return_value = {}
+ with pytest.raises(InvalidResponse):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList": [
+ ]
+ }
+ with pytest.raises(InvalidResponse):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList1": [
+ ]
+ }
+ with pytest.raises(InvalidResponse):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList": [
+ {
+ "request": {
+ "requestScope": "not_pnf"
+ }
+ }
+ ]
+ }
+ with pytest.raises(InvalidResponse):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList": [
+ {
+ "request": {
+ "requestScope": "pnf",
+ "requestType": "updateInstance"
+ }
+ }
+ ]
+ }
+ with pytest.raises(InvalidResponse):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList": [
+ {
+ "request": {
+ "requestScope": "pnf",
+ "requestType": "createInstance"
+ }
+ }
+ ]
+ }
+ with pytest.raises(ResourceNotFound):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_send_message_json.return_value = {
+ "requestList": [
+ {
+ "request": {
+ "requestScope": "pnf",
+ "requestType": "createInstance",
+ "requestDetails": {
+ "relatedInstanceList": [
+ {
+ "relatedInstance": {
+ "modelInfo": {
+ "modelType": "service",
+ "modelName": "test_service"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ with pytest.raises(ResourceNotFound):
+ PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name")
+ mock_pnf = mock.MagicMock()
+ mock_pnf.name = "test_pnf_name"
+ mock_sdc_service.return_value.pnfs = [mock_pnf]
+ mock_send_message_json.return_value = {
+ "requestList": [
+ {
+ "request": {
+ "requestScope": "pnf",
+ "requestType": "createInstance",
+ "requestDetails": {
+ "modelInfo": {
+ "modelCustomizationName": "test_pnf_name"
+ },
+ "relatedInstanceList": [
+ {
+ "relatedInstance": {
+ "modelInfo": {
+ "modelType": "service",
+ "modelName": "test_service"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ assert PnfInstantiation.get_by_pnf_instance_name("test_pnf_instance_name") is not None
@mock.patch.object(VfModuleInstantiation, "send_message_json")
@mock.patch.object(VfModulePreload, "upload_vf_module_preload")