diff options
-rw-r--r-- | src/onapsdk/aai/business/service.py | 45 | ||||
-rw-r--r-- | src/onapsdk/so/instantiation.py | 16 | ||||
-rw-r--r-- | src/onapsdk/so/templates/deletion_pnf.json.j2 | 6 | ||||
-rwxr-xr-x | src/onapsdk/so/templates/instantiate_pnf_macro.json.j2 | 10 | ||||
-rw-r--r-- | src/onapsdk/so/templates/instantiate_pnf_macro_in_service.json.j2 | 109 | ||||
-rwxr-xr-x | src/onapsdk/so/templates/instantiate_pnf_macro_so_pnf.json.j2 | 10 | ||||
-rw-r--r-- | src/onapsdk/so/templates/instantiate_service_macro_skip_pnf_registration_event.json.j2 | 181 | ||||
-rw-r--r-- | tests/test_aai_service.py | 83 | ||||
-rw-r--r-- | tests/test_so_instantiation.py | 29 |
9 files changed, 406 insertions, 83 deletions
diff --git a/src/onapsdk/aai/business/service.py b/src/onapsdk/aai/business/service.py index fe3b34d..4351a26 100644 --- a/src/onapsdk/aai/business/service.py +++ b/src/onapsdk/aai/business/service.py @@ -18,7 +18,7 @@ from typing import Iterator, Type, Union, Iterable, Optional from onapsdk.exceptions import StatusError, ParameterError from onapsdk.sdc.service import Service from onapsdk.so.deletion import ServiceDeletionRequest -from onapsdk.so.instantiation import NetworkInstantiation, VnfInstantiation +from onapsdk.so.instantiation import NetworkInstantiation, VnfInstantiation, PnfInstantiation from onapsdk.utils.jinja import jinja_env from .instance import Instance @@ -417,6 +417,49 @@ class ServiceInstance(Instance): # pylint: disable=too-many-instance-attributes sdc_service=self.sdc_service ) + def add_pnf(self, # pylint: disable=too-many-arguments + pnf: "Pnf", + line_of_business: "LineOfBusiness", + platform: "Platform", + pnf_instance_name: str = None, + customer: "Customer" = None, + service_subscription: "ServiceSubscription" = None, + sdc_service: "SdcService" = None, + ) -> "PnfInstantiation": + """Add pnf into service instance. + + Instantiate PNF. + + Args: + pnf (Pnf): Pnf from service configuration to instantiate + line_of_business (LineOfBusiness): LineOfBusiness to use in instantiation request + platform (Platform): Platform to use in instantiation request + customer (Customer): Customer to use in instantiation request + service_subscription(ServiceSubscription): ServiceSubscription + pnf_instance_name (str): PNF instantiation name + sdc_service (SdcService): service model from sdc + + Raises: + StatusError: Service orchestration status is not "Active". + + Returns: + PnfInstantiation: PnfInstantiation request object + + """ + if not self.active: + raise StatusError('Service orchestration status must be "Active"') + + return PnfInstantiation.instantiate_macro( + self, + pnf, + line_of_business, + customer, + service_subscription, + platform, + pnf_instance_name, + sdc_service + ) + def add_network(self, # pylint: disable=too-many-arguments network: "Network", line_of_business: "LineOfBusiness", diff --git a/src/onapsdk/so/instantiation.py b/src/onapsdk/so/instantiation.py index a6781de..2ca25c2 100644 --- a/src/onapsdk/so/instantiation.py +++ b/src/onapsdk/so/instantiation.py @@ -789,8 +789,6 @@ class PnfInstantiation(NodeTemplateInstantiation): # pylint: disable=too-many-a pnf_object: "Pnf", line_of_business: str, platform: str, - cloud_region: "CloudRegion", - tenant: "Tenant", sdc_service: "SdcService", pnf_instance_name: str = None, pnf_parameters: Iterable["InstantiationParameter"] = None, @@ -803,8 +801,7 @@ class PnfInstantiation(NodeTemplateInstantiation): # pylint: disable=too-many-a pnf_object (Pnf): Pnf to instantiate line_of_business (LineOfBusiness): LineOfBusiness to use in instantiation request platform (Platform): Platform to use in instantiation request - cloud_region (CloudRegion): Cloud region to use in instantiation request. - tenant (Tenant): Tenant to use in instantiation request. + sdc_service(SdcService): service model to instantiate pnf_instance_name (str, optional): Pnf instance name. Defaults to None. pnf_parameters (Iterable[InstantiationParameter], optional): Instantiation parameters that are sent in the request. Defaults to None @@ -847,9 +844,6 @@ class PnfInstantiation(NodeTemplateInstantiation): # pylint: disable=too-many-a instance_name=pnf_instance_name, pnf=pnf_object, service=sdc_service, - cloud_region=cloud_region or \ - next(aai_service_instance.service_subscription.cloud_regions), - tenant=tenant or next(aai_service_instance.service_subscription.tenants), project=project, owning_entity=owning_entity, line_of_business=line_of_business, @@ -989,7 +983,8 @@ class ServiceInstantiation(Instantiation): # pylint: disable=too-many-ancestors vnf_parameters: Iterable["VnfParameters"] = None, enable_multicloud: bool = False, so_service: "SoService" = None, - service_subscription: "ServiceSubscription" = None + service_subscription: "ServiceSubscription" = None, + skip_pnf_registration_event: "skip_event" = False ) -> "ServiceInstantiation": """Instantiate service using SO macro request. @@ -1012,6 +1007,8 @@ class ServiceInstantiation(Instantiation): # pylint: disable=too-many-ancestors so_service (SoService, optional): SO values to use in instantiation request service_subscription(ServiceSubscription, optional): Customer service subscription for the instantiated service. Required if so_service is not provided. + skip_pnf_registration_event(skip_event, optional) Required to skip + WaitForPnfReadyEvent. Raises: StatusError: if a service is not distributed. @@ -1035,6 +1032,9 @@ class ServiceInstantiation(Instantiation): # pylint: disable=too-many-ancestors msg = f"Service {sdc_service.name} is not distributed." raise StatusError(msg) + if skip_pnf_registration_event: + template_file = "instantiate_service_macro_skip_pnf_registration_event.json.j2" + response: dict = cls.send_message_json( "POST", f"Instantiate {sdc_service.name} service macro", diff --git a/src/onapsdk/so/templates/deletion_pnf.json.j2 b/src/onapsdk/so/templates/deletion_pnf.json.j2 index 852432a..4e8770d 100644 --- a/src/onapsdk/so/templates/deletion_pnf.json.j2 +++ b/src/onapsdk/so/templates/deletion_pnf.json.j2 @@ -16,12 +16,6 @@ "requestParameters": { "testApi": "GR_API", "aLaCarte": {{ a_la_carte | tojson }} - }, - {# the code below is needed to be refactored # - } - {# https: //gitlab.com/Orange-OpenSource/lfn/onap/python-onapsdk/-/issues/133 #} "cloudConfiguration": { "cloudOwner": "{{ pnf_instance.service_instance.service_subscription.cloud_region.cloud_owner }}", - "lcpCloudRegionId": "{{ pnf_instance.service_instance.service_subscription.cloud_region.cloud_region_id }}", - "tenantId": "{{ pnf_instance.service_instance.service_subscription.tenant.tenant_id }}" } } }
\ No newline at end of file diff --git a/src/onapsdk/so/templates/instantiate_pnf_macro.json.j2 b/src/onapsdk/so/templates/instantiate_pnf_macro.json.j2 index 6abfe84..1f9b3a2 100755 --- a/src/onapsdk/so/templates/instantiate_pnf_macro.json.j2 +++ b/src/onapsdk/so/templates/instantiate_pnf_macro.json.j2 @@ -16,11 +16,6 @@ "modelCustomizationId": "{{ pnf.model_customization_id }}",
"modelInstanceName": "{{ pnf.name }}"
},
- "cloudConfiguration": {
- "tenantId": "{{ tenant.tenant_id }}",
- "cloudOwner": "{{ cloud_region.cloud_owner }}",
- "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}"
- },
"platform": {
"platformName": "{{ platform }}"
},
@@ -53,11 +48,6 @@ "modelCustomizationId": "{{ pnf.model_customization_id }}",
"modelInstanceName": "{{ pnf.name }}"
},
- "cloudConfiguration": {
- "tenantId": "{{ tenant.tenant_id }}",
- "cloudOwner": "{{ cloud_region.cloud_owner }}",
- "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}"
- },
"platform": {
"platformName": "{{ platform }}"
},
diff --git a/src/onapsdk/so/templates/instantiate_pnf_macro_in_service.json.j2 b/src/onapsdk/so/templates/instantiate_pnf_macro_in_service.json.j2 new file mode 100644 index 0000000..b38c985 --- /dev/null +++ b/src/onapsdk/so/templates/instantiate_pnf_macro_in_service.json.j2 @@ -0,0 +1,109 @@ +instantiate_service_macro_skip_pnf_registration_event.json.j2{ + "requestDetails": { + "requestInfo": { + "instanceName": "{{ service_instance.instance_name }}", + "source": "VID", + "suppressRollback": false, + "requestorId": "demo", + "productFamilyId": "1234" + }, + "modelInfo": { + "modelType": "pnf", + "modelInvariantId": "{{ pnf.model_invariant_id }}", + "modelVersionId": "{{ pnf.model_version_id }}", + "modelName": "{{ pnf.model_name }}", + "modelVersion": "{{ pnf.model_version }}", + "modelCustomizationId": "{{ pnf.model_customization_id }}", + "modelInstanceName": "{{ pnf.name }}" + }, + "platform": { + "platformName": "{{ platform }}" + }, + "lineOfBusiness": { + "lineOfBusinessName": "{{ line_of_business }}" + }, + "subscriberInfo": { + "globalSubscriberId": "{{ service_instance.service_subscription.customer.global_customer_id }}" + }, + "requestParameters": { + {% block subscriptionServiceType %} + "subscriptionServiceType": "{{ service.name }}", + {% endblock %} + "userParams": [ + { + "Homing_Solution": "none" + }, + { + "service": { + "instanceParams": [], + "resources": { + {% block pnfs %} + "pnfs": [ + { + "modelInfo": { + "modelName": "{{ pnf.model_name }}", + "modelVersionId": "{{ pnf.model_version_id }}", + "modelInvariantUuid": "{{ pnf.model_invariant_id }}", + "modelVersion": "{{ pnf.model_version }}", + "modelCustomizationId": "{{ pnf.model_customization_id }}", + "modelInstanceName": "{{ pnf.name }}" + }, + "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" + }, + "platform": { + "platformName": "{{ platform }}" + }, + "lineOfBusiness": { + "lineOfBusinessName": "{{ line_of_business }}" + }, + "productFamilyId": "1234", + "instanceName": "{{ instance_name }}" + } + ] + {% endblock %} + }, + "modelInfo": { + "modelType": "pnf", + "modelInvariantId": "{{ pnf.model_invariant_id }}", + "modelVersionId": "{{ pnf.model_version_id }}", + "modelName": "{{ pnf.model_name }}", + "modelVersion": "{{ pnf.model_version }}", + "modelCustomizationId": "{{ pnf.model_customization_id }}", + "modelCustomizationName": "{{ pnf.name }}" + } + } + } + ], + "aLaCarte": false + }, + "project": { + "projectName": "{{ project }}" + }, + "owningEntity": { + "owningEntityId": "{{ owning_entity.owning_entity_id }}", + "owningEntityName": "{{ owning_entity.name }}" + }, + "relatedInstanceList": [ + { + "relatedInstance": { + "instanceId": "{{ service_instance.instance_id }}", + "modelInfo": { + "modelType": "service", + "modelInvariantId": "{{ service.unique_uuid }}", + "modelVersionId": "{{ service.identifier }}", + "modelName": "{{ service.name }}", + "modelVersion": "1.0" + } + } + } + ] + }, + "serviceInstanceId": "{{ service_instance.instance_id }}" +} diff --git a/src/onapsdk/so/templates/instantiate_pnf_macro_so_pnf.json.j2 b/src/onapsdk/so/templates/instantiate_pnf_macro_so_pnf.json.j2 index 5f1f22c..630d95e 100755 --- a/src/onapsdk/so/templates/instantiate_pnf_macro_so_pnf.json.j2 +++ b/src/onapsdk/so/templates/instantiate_pnf_macro_so_pnf.json.j2 @@ -16,11 +16,6 @@ "modelCustomizationId": "{{ pnf.model_customization_id }}",
"modelInstanceName": "{{ pnf.name }}"
},
- "cloudConfiguration": {
- "tenantId": "{{ tenant.tenant_id }}",
- "cloudOwner": "{{ cloud_region.cloud_owner }}",
- "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}"
- },
"platform": {
"platformName": "{{ platform }}"
},
@@ -53,11 +48,6 @@ "modelCustomizationId": "{{ pnf.model_customization_id }}",
"modelInstanceName": "{{ pnf.name }}"
},
- "cloudConfiguration": {
- "tenantId": "{{ tenant.tenant_id }}",
- "cloudOwner": "{{ cloud_region.cloud_owner }}",
- "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}"
- },
"platform": {
"platformName": "{{ platform }}"
},
diff --git a/src/onapsdk/so/templates/instantiate_service_macro_skip_pnf_registration_event.json.j2 b/src/onapsdk/so/templates/instantiate_service_macro_skip_pnf_registration_event.json.j2 new file mode 100644 index 0000000..caa0ab4 --- /dev/null +++ b/src/onapsdk/so/templates/instantiate_service_macro_skip_pnf_registration_event.json.j2 @@ -0,0 +1,181 @@ +{ + "requestDetails": { + "requestInfo": { + "suppressRollback": false, + {% if aai_service %} + "productFamilyId":"{{ aai_service.service_id }}", + {% else %} + "productFamilyId": "1234", + {% endif %} + "requestorId": "demo", + "instanceName": "{{ service_instance_name }}", + "source": "VID" + }, + "modelInfo": { + "modelType": "service", + "modelInvariantId": "{{ sdc_service.unique_uuid }}", + "modelVersionId": "{{ sdc_service.identifier }}", + "modelName": "{{ sdc_service.name }}", + "modelVersion": "1.0" + }, + {% if sdc_service.has_vnfs %} + "cloudConfiguration": { + "tenantId": "{{ tenant.tenant_id }}", + "cloudOwner": "{{ cloud_region.cloud_owner }}", + "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}" + }, + {% endif %} + "subscriberInfo": { + "globalSubscriberId": "{{ customer.global_customer_id }}" + }, + "requestParameters": { + {% block subscriptionServiceType %} + "subscriptionServiceType": "{{ service_subscription.service_type }}", + {% endblock %} + "userParams": [ + { + "Homing_Solution": "none" + }, + {% if enable_multicloud %} + { + "name":"orchestrator", + "value":"multicloud" + }, + {% endif %} + { + "service": { + "instanceParams": [], + "instanceName": "{{ service_instance_name }}", + "resources": { + {% block pnfs %} + {% if sdc_service.pnfs %} + "pnfs":[ + {% for pnf in sdc_service.pnfs %} + { + "modelInfo":{ + "modelCustomizationName":"{{ pnf.name }}", + "modelCustomizationId":"{{ pnf.model_customization_id }}", + "modelInvariantId":"{{ sdc_service.unique_uuid }}", + "modelVersionId":"{{ sdc_service.identifier }}", + "modelName":"{{ sdc_service.name }}", + "modelType":"pnf", + "modelVersion":"1.0" + },"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" + }, + "platform":{ + "platformName":"{{ platform }}" + }, + "lineOfBusiness":{ + "lineOfBusinessName":"{{ line_of_business }}" + }, + "productFamilyId":"{{ aai_service.service_id }}", + "instanceParams":[], + "instanceName":"{{ service_instance_name }}" + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + {% if sdc_service.vnfs %},{% endif %} + {% endif %} + {% endblock %} + {% block vnfs %} + {% if sdc_service.vnfs %} + "vnfs": [ + {% for vnf in sdc_service.vnfs %} + { + "modelInfo": { + "modelName": "{{ vnf.model_name }}", + "modelVersionId": "{{ vnf.model_version_id }}", + "modelInvariantUuid": "{{ vnf.model_invariant_id }}", + "modelVersion": "{{ vnf.model_version }}", + "modelCustomizationId": "{{ vnf.model_customization_id }}", + "modelInstanceName": "{{ vnf.model_name }}" + }, + "cloudConfiguration": { + "tenantId": "{{ tenant.tenant_id }}", + "cloudOwner": "{{ cloud_region.cloud_owner }}", + "lcpCloudRegionId": "{{ cloud_region.cloud_region_id }}" + }, + "platform": { + "platformName": "{{ platform }}" + }, + "lineOfBusiness": { + "lineOfBusinessName": "{{ line_of_business }}" + }, + "productFamilyId": "1234", + "instanceName": "{{ vnf.model_name }}", + "instanceParams": [ + { + {% for vnf_parameter in vnf_parameters %} + {% if vnf_parameter.name == vnf.model_name %} + {% for parameter in vnf_parameter.vnf_parameters %} + "{{ parameter.name }}": "{{ parameter.value }}"{% if not loop.last %},{% endif %} + {% endfor %} + {% endif %} + {% endfor %} + } + ], + "vfModules": [ + {% for vf_module in vnf.vf_modules %} + { + "modelInfo": { + "modelName": "{{ vf_module.model_name }}", + "modelVersionId": "{{ vf_module.model_version_id }}", + "modelInvariantUuid": "{{ vf_module.model_invariant_uuid }}", + "modelVersion": "{{ vf_module.model_version }}", + "modelCustomizationId": "{{ vf_module.model_customization_id }}" + }, + "instanceName": "{{ service_instance_name }}_{{ vf_module.name }}", + "instanceParams": [ + { + {% for vnf_parameter in vnf_parameters %} + {% if vnf_parameter.name == vnf.model_name %} + {% set mylist = vf_module.name.split('..') %} + {% set item = mylist|length-2 %} + {% for vf_module_parameter in vnf_parameter.vfmodule_parameters %} + {% if vf_module_parameter.name == mylist[item] %} + {% for parameter in vf_module_parameter.vfmodule_parameters %} + "{{ parameter.name }}": "{{ parameter.value }}"{% if not loop.last %},{% endif %} + {% endfor %} + {% endif %} + {% endfor %} + {% endif %} + {% endfor %} + } + ] + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + }{% if not loop.last %},{% endif %} + {% endfor %} + ] + {% endif %} + {% endblock %} + }, + "modelInfo": { + "modelVersion": "1.0", + "modelVersionId": "{{ sdc_service.identifier }}", + "modelInvariantId": "{{ sdc_service.unique_uuid }}", + "modelName": "{{ sdc_service.name }}", + "modelType": "service" + } + } + } + ], + "aLaCarte": false + }, + "project": { + "projectName": "{{ project }}" + }, + "owningEntity": { + "owningEntityId": "{{ owning_entity.owning_entity_id }}", + "owningEntityName": "{{ owning_entity.name }}" + } + } +} diff --git a/tests/test_aai_service.py b/tests/test_aai_service.py index aac4c59..a13131a 100644 --- a/tests/test_aai_service.py +++ b/tests/test_aai_service.py @@ -23,11 +23,10 @@ from onapsdk.aai.cloud_infrastructure import ( EsrSystemInfo, Tenant ) -from onapsdk.aai.business import Customer +from onapsdk.aai.business import Customer, ServiceInstance from onapsdk.aai.service_design_and_creation import Service, Model from onapsdk.onap_service import OnapService - # pylint: disable=C0301 TENANT = { "tenant": [ @@ -88,7 +87,6 @@ TENANT = { ] } - CLOUD_REGIONS = { "cloud-region": [ { @@ -122,7 +120,6 @@ CLOUD_REGIONS = { ] } - CLOUD_REGION = { "cloud-region": [ { @@ -156,7 +153,6 @@ CLOUD_REGION = { ] } - COMPLEXES = { "complex": [ { @@ -225,7 +221,6 @@ COMPLEXES = { ] } - CLOUD_REGION_RELATIONSHIP = { "relationship": [ { @@ -242,7 +237,6 @@ CLOUD_REGION_RELATIONSHIP = { ] } - SERVICE_SUBSCRIPTION = { "service-subscription": [ { @@ -282,7 +276,6 @@ SERVICE_SUBSCRIPTION = { ] } - SUBSCRIPTION_TYPES_NO_RESOURCES = { "requestError": { "serviceException": { @@ -292,8 +285,8 @@ SUBSCRIPTION_TYPES_NO_RESOURCES = { "GET", "service-design-and-creation/services", ( - "Node Not Found:No Node of type service found at: " - + "/service-design-and-creation/services" + "Node Not Found:No Node of type service found at: " + + "/service-design-and-creation/services" ), "ERR.5.4.6114", ], @@ -301,7 +294,6 @@ SUBSCRIPTION_TYPES_NO_RESOURCES = { } } - SUBSCRIPTION_TYPES_LIST = { "service": [ { @@ -322,7 +314,6 @@ SUBSCRIPTION_TYPES_LIST = { ] } - CUSTOMERS_NO_RESOURCES = { "requestError": { "serviceException": { @@ -332,8 +323,8 @@ CUSTOMERS_NO_RESOURCES = { "GET", "business/customers", ( - "Node Not Found:No Node of type customer found at: " - + "business/customers" + "Node Not Found:No Node of type customer found at: " + + "business/customers" ), "ERR.5.4.6114", ], @@ -341,7 +332,6 @@ CUSTOMERS_NO_RESOURCES = { } } - SIMPLE_CUSTOMER = { "customer": [ { @@ -353,7 +343,6 @@ SIMPLE_CUSTOMER = { ] } - ESR_SYSTEM_INFO = { 'esr-system-info': [ { @@ -368,28 +357,29 @@ ESR_SYSTEM_INFO = { ] } - CLOUD_REGIONS_ITERATOR = ( cloud_region for cloud_region in [ - CloudRegion( - cloud_owner="OPNFV", - cloud_region_id="RegionOne", - cloud_type="openstack", - owner_defined_type="N/A", - cloud_region_version="pike", - identity_url=None, - cloud_zone="OPNFV LaaS", - complex_name="Cruguil", - sriov_automation=None, - cloud_extra_info=None, - upgrade_cycle=None, - orchestration_disabled=False, - in_maint=False, - resource_version=None, - ) - ] + CloudRegion( + cloud_owner="OPNFV", + cloud_region_id="RegionOne", + cloud_type="openstack", + owner_defined_type="N/A", + cloud_region_version="pike", + identity_url=None, + cloud_zone="OPNFV LaaS", + complex_name="Cruguil", + sriov_automation=None, + cloud_extra_info=None, + upgrade_cycle=None, + orchestration_disabled=False, + in_maint=False, + resource_version=None, + ) +] ) + + # pylint: enable=C0301 @@ -410,6 +400,7 @@ def test_class_variables(): "x-transactionid": "0a3f6713-ba96-4971-a6f8-c2da85a3176e", "authorization": "Basic QUFJOkFBSQ=="} + @mock.patch.object(AaiElement, 'send_message_json') def test_customers(mock_send): """Test get_customer function of A&AI.""" @@ -422,6 +413,7 @@ def test_customers(mock_send): assert aai_customer_1.resource_version == "1561218640404" mock_send.assert_called_with("GET", 'get customers', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_customers_no_resources(mock_send): """Test get_customer function with no customer declared in A&AI.""" @@ -429,6 +421,7 @@ def test_customers_no_resources(mock_send): assert len(list(Customer.get_all())) == 0 mock_send.assert_called_with("GET", 'get customers', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_subscription_type_list(mock_send): """Test the getter of subscription types in A&AI.""" @@ -454,6 +447,7 @@ def test_subscription_type_list(mock_send): assert aai_service_3.resource_version == "1561219799684" mock_send.assert_called_with("GET", 'get subscriptions', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_subscription_types_no_resources(mock_send): """Test get_customer function with no customer declared in A&AI.""" @@ -461,6 +455,7 @@ def test_subscription_types_no_resources(mock_send): assert len(list(Service.get_all())) == 0 mock_send.assert_called_with("GET", 'get subscriptions', mock.ANY) + @mock.patch.object(AaiElement, 'send_message_json') def test_cloud_regions(mock_send): """Test get cloud regions from A&AI.""" @@ -487,6 +482,7 @@ def test_cloud_regions(mock_send): cloud_regions = list(CloudRegion.get_all()) assert len(cloud_regions) == 1 + @mock.patch.object(CloudRegion, "send_message") def test_cloud_region_creation(mock_send): """Test cloud region creation""" @@ -514,6 +510,7 @@ def test_cloud_region_creation(mock_send): assert cloud_region.cloud_extra_info == "" assert cloud_region.upgrade_cycle == "Test" + @mock.patch.object(CloudRegion, 'get_all') @mock.patch.object(AaiElement, 'send_message_json') def test_tenants_info(mock_send, mock_cloud_regions): @@ -536,6 +533,7 @@ def test_tenants_info(mock_send, mock_cloud_regions): f"resource-version=1562591004273" ) + @mock.patch.object(CloudRegion, 'get_all') @mock.patch.object(AaiElement, 'send_message_json') def test_tenants_info_wrong_cloud_name(mock_send, mock_cloud_regions): @@ -558,7 +556,7 @@ def test_cloud_regions_relationship(mock_send): assert isinstance(relationship, Relationship) assert relationship.relationship_label == "org.onap.relationships.inventory.LocatedIn" assert relationship.related_link == \ - "/aai/v16/cloud-infrastructure/complexes/complex/integration_test_complex" + "/aai/v16/cloud-infrastructure/complexes/complex/integration_test_complex" assert relationship.related_to == "complex" assert relationship.relationship_data[0]["relationship-key"] == "complex.physical-location-id" assert relationship.relationship_data[0]["relationship-value"] == "integration_test_complex" @@ -594,6 +592,7 @@ def test_cloud_regions_esr_system_infos(mock_send): assert esr_system_info.system_status is None assert esr_system_info.openstack_region_id is None + @mock.patch.object(Complex, "send_message") def test_create_complex(mock_send): """Test complex creation""" @@ -701,6 +700,8 @@ SIMPLE_MODEL = { } ] } + + # pylint: enable=C0301 @@ -708,7 +709,7 @@ def test_service_url(): """Test service property""" service = Service("12345", "description", "version1.0") assert service.url == (f"{service.base_url}{service.api_version}/service-design-and-creation/services/service/" - f"{service.service_id}?resource-version={service.resource_version}") + f"{service.service_id}?resource-version={service.resource_version}") @mock.patch.object(Service, 'send_message') @@ -768,3 +769,13 @@ def test_cloud_region_complex_property(mock_complex_get_by_physical_location_id, mock_send.return_value = CLOUD_REGION_RELATIONSHIP assert cloud_region.complex is not None assert mock_complex_get_by_physical_location_id.called_once_with("integration_test_complex") + + +@mock.patch.object(ServiceInstance, 'send_message') +def test_service_instance_create(mock_send): + """Test service instance creation""" + service_subscription = mock.MagicMock() + ServiceInstance.create(service_subscription=service_subscription, instance_id="1234") + mock_send.assert_called_once() + method, description, url = mock_send.call_args[0] + assert method == "PUT" diff --git a/tests/test_so_instantiation.py b/tests/test_so_instantiation.py index 3babdd3..200dd11 100644 --- a/tests/test_so_instantiation.py +++ b/tests/test_so_instantiation.py @@ -34,7 +34,8 @@ from onapsdk.so.instantiation import ( PnfInstantiation, PnfRegistrationParameters, ServiceOperation, - VnfOperation + VnfOperation, + PnfInstantiation ) from onapsdk.vid import Vid from onapsdk.aai.business.owning_entity import OwningEntity @@ -109,7 +110,21 @@ def test_service_macro_instantiation(mock_service_instantiation_send_message): line_of_business=mock.MagicMock(), platform=mock.MagicMock(), service_instance_name="test", - service_subscription=mock.MagicMock()) + service_subscription=mock.MagicMock(), + skip_pnf_registration_event=True) + assert service_instance.name == "test" + + service_instance = ServiceInstantiation. \ + instantiate_macro(sdc_service=mock_sdc_service, + cloud_region=mock.MagicMock(), + tenant=mock.MagicMock(), + customer=mock.MagicMock(), + owning_entity=mock.MagicMock(), + project=mock.MagicMock(), + line_of_business=mock.MagicMock(), + platform=mock.MagicMock(), + service_instance_name="test", + service_subscription=mock.MagicMock()) assert service_instance.name == "test" service_instance = ServiceInstantiation.\ @@ -366,8 +381,6 @@ def test_pnf_instantiation_macro(mock_owning_entity_get, mock_pnf_instantiation_ 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() @@ -383,8 +396,6 @@ def test_pnf_instantiation_macro(mock_owning_entity_get, mock_pnf_instantiation_ 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" @@ -393,8 +404,6 @@ def test_pnf_instantiation_macro(mock_owning_entity_get, mock_pnf_instantiation_ 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_") @@ -406,8 +415,6 @@ def test_pnf_instantiation_macro(mock_owning_entity_get, mock_pnf_instantiation_ 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" @@ -981,8 +988,6 @@ def test_pnf_instantiation_so_service(mock_owning_entity_get, mock_send_message_ 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) |