diff options
author | 2018-09-11 07:46:00 +0000 | |
---|---|---|
committer | 2018-09-11 07:46:00 +0000 | |
commit | d6e67484b1daa7bb27afcf6c6a47b1419b4409cf (patch) | |
tree | 21b3a8eeca1571dfef5237d2e901533d836da086 | |
parent | 34fa98751d6e041655aa0a31bfe538ff8b858e2e (diff) | |
parent | b8eb02279a1fb7c1be7802023c487e1ccbddc353 (diff) |
Merge "Notification endpoint stuffs."
-rw-r--r-- | lcm/ns_vnfs/biz/handle_notification.py | 46 | ||||
-rw-r--r-- | lcm/ns_vnfs/serializers/grant_vnf_serializer.py | 6 | ||||
-rw-r--r-- | lcm/ns_vnfs/tests/const.py | 226 | ||||
-rw-r--r-- | lcm/ns_vnfs/tests/vnf_tests.py | 277 |
4 files changed, 278 insertions, 277 deletions
diff --git a/lcm/ns_vnfs/biz/handle_notification.py b/lcm/ns_vnfs/biz/handle_notification.py index 5ba685bc..20225088 100644 --- a/lcm/ns_vnfs/biz/handle_notification.py +++ b/lcm/ns_vnfs/biz/handle_notification.py @@ -38,7 +38,7 @@ class HandleVnfLcmOocNotification(object): logger.debug("[Notify LCM] vnfmid=%s, vnfInstanceId=%s, data=%s" % (vnfmid, vnfInstanceId, data)) self.vnfmid = vnfmid self.m_vnfInstanceId = vnfInstanceId - self.vnf_instid = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) + self.vnf_instid = get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) self.operation = ignore_case_get(data, 'operation') self.affectedVnfcs = ignore_case_get(data, 'affectedVnfcs') self.affectedVls = ignore_case_get(data, 'affectedVls') @@ -55,22 +55,10 @@ class HandleVnfLcmOocNotification(object): self.update_network_in_aai() logger.debug("notify lcm end") except NSLCMException as e: - self.exception(e.message) + exception(e.message) except Exception: logger.error(traceback.format_exc()) - self.exception('unexpected exception') - - def get_vnfinstid(self, mnfinstid, vnfm_inst_id): - logger.debug("vnfinstid in vnfm is:%s,vnfmid is:%s", mnfinstid, vnfm_inst_id) - logger.debug("mnfinstid=%s, vnfm_inst_id=%s", mnfinstid, vnfm_inst_id) - nfinst = NfInstModel.objects.filter(mnfinstid=mnfinstid, vnfm_inst_id=vnfm_inst_id).first() - if nfinst: - return nfinst.nfinstid - raise NSLCMException("vnfinstid not exist") - - def exception(self, error_msg): - logger.error('Notify Lcm failed, detail message: %s' % error_msg) - return Response(data={'error': '%s' % error_msg}, status=status.HTTP_409_CONFLICT) + exception('unexpected exception') def update_Vnfc(self): for vnfc in self.affectedVnfcs: @@ -98,7 +86,7 @@ class HandleVnfLcmOocNotification(object): nfinstid=self.vnf_instid, vmid=vmId) else: - self.exception('affectedVnfc struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') + exception('affectedVnfc struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') logger.debug("Success to update all vserver to aai.") def update_Vl(self): @@ -112,9 +100,9 @@ class HandleVnfLcmOocNotification(object): resourceName = ignore_case_get(networkResource, 'resourceId') # replaced with resouceId temporarily if resourceType != 'network': - self.exception('affectedVl struct error: resourceType not euqal network') + exception('affectedVl struct error: resourceType not euqal network') - ownerId = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) + ownerId = self.vnf_instid if changeType == 'ADDED': VLInstModel(vlinstanceid=vlInstanceId, vldid=vldid, vlinstancename=resourceName, ownertype=0, @@ -126,7 +114,7 @@ class HandleVnfLcmOocNotification(object): .update(vldid=vldid, vlinstancename=resourceName, ownertype=0, ownerid=ownerId, relatednetworkid=resourceId, vltype=0) else: - self.exception('affectedVl struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') + exception('affectedVl struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') def update_Cp(self): for cp in self.affectedCps: @@ -325,7 +313,7 @@ class HandleVnfIdentifierCreationNotification(object): logger.debug("Notify VNF identifier creation end.") except Exception: logger.error(traceback.format_exc()) - self.exception('unexpected exception') + exception('unexpected exception') class HandleVnfIdentifierDeletionNotification(object): @@ -333,7 +321,7 @@ class HandleVnfIdentifierDeletionNotification(object): logger.debug("[Notify VNF Identifier Deletion] vnfmId=%s, vnfInstanceId=%s, data=%s" % (vnfmId, vnfInstanceId, data)) self.vnfm_id = vnfmId self.m_vnf_instance_id = vnfInstanceId - self.vnf_instance_id = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) + self.vnf_instance_id = get_vnfinstid(self.m_vnf_instance_id, self.vnfm_id) self.time_stamp = ignore_case_get(data, 'timeStamp') # TODO: self.subscription_id = ignore_case_get(data, 'subscriptionId') # TODO: self._links = ignore_case_get(data, '_links') @@ -347,4 +335,18 @@ class HandleVnfIdentifierDeletionNotification(object): logger.debug("Notify VNF identifier deletion end.") except Exception: logger.error(traceback.format_exc()) - self.exception('unexpected exception') + exception('unexpected exception') + + +def get_vnfinstid(mnfinstid, vnfm_inst_id): + logger.debug("vnfinstid in vnfm is:%s,vnfmid is:%s", mnfinstid, vnfm_inst_id) + logger.debug("mnfinstid=%s, vnfm_inst_id=%s", mnfinstid, vnfm_inst_id) + nfinst = NfInstModel.objects.filter(mnfinstid=mnfinstid, vnfm_inst_id=vnfm_inst_id).first() + if nfinst: + return nfinst.nfinstid + raise NSLCMException("vnfinstid not exist") + + +def exception(error_msg): + logger.error('Notify Lcm failed, detail message: %s' % error_msg) + return Response(data={'error': '%s' % error_msg}, status=status.HTTP_409_CONFLICT) diff --git a/lcm/ns_vnfs/serializers/grant_vnf_serializer.py b/lcm/ns_vnfs/serializers/grant_vnf_serializer.py index 2325c83b..31ea9d73 100644 --- a/lcm/ns_vnfs/serializers/grant_vnf_serializer.py +++ b/lcm/ns_vnfs/serializers/grant_vnf_serializer.py @@ -1038,8 +1038,7 @@ class VnfIdentifierCreationNotificationSerializer(serializers.Serializer): allow_blank=True ) timeStamp = serializers.DateField( - help_text="Discriminator for the different notification types. \ - Shall be set to VnfIdentifierCreationNotification for this notification type.", + help_text="Date-time of the generation of the notification.", required=True, allow_null=False, ) @@ -1081,8 +1080,7 @@ class VnfIdentifierDeletionNotificationSerializer(serializers.Serializer): allow_blank=True ) timeStamp = serializers.DateField( - help_text="Discriminator for the different notification types. \ - Shall be set to VnfIdentifierDeletionionNotification for this notification type.", + help_text="Date-time of the generation of the notification.", required=True, allow_null=False, ) diff --git a/lcm/ns_vnfs/tests/const.py b/lcm/ns_vnfs/tests/const.py new file mode 100644 index 00000000..08c5bdfd --- /dev/null +++ b/lcm/ns_vnfs/tests/const.py @@ -0,0 +1,226 @@ +# Copyright 2018 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GRANT_DATA = { + 'vnfInstanceId': '1', + 'vnfLcmOpOccId': '2', + 'vnfdId': '3', + 'flavourId': '4', + 'operation': 'INSTANTIATE', + 'isAutomaticInvocation': True, + 'instantiationLevelId': '5', + 'addResources': [ + { + 'id': '1', + 'type': 'COMPUTE', + 'vduId': '2', + 'resourceTemplateId': '3', + 'resourceTemplate': { + 'vimConnectionId': '4', + 'resourceProviderId': '5', + 'resourceId': '6', + 'vimLevelResourceType': '7' + } + } + ], + 'placementConstraints': [ + { + 'affinityOrAntiAffinity': 'AFFINITY', + 'scope': 'NFVI_POP', + 'resource': [ + { + 'idType': 'RES_MGMT', + 'resourceId': '1', + 'vimConnectionId': '2', + 'resourceProviderId': '3' + } + ] + } + ], + 'vimConstraints': [ + { + 'sameResourceGroup': True, + 'resource': [ + { + 'idType': 'RES_MGMT', + 'resourceId': '1', + 'vimConnectionId': '2', + 'resourceProviderId': '3' + } + ] + } + ], + 'additionalParams': {}, + '_links': { + 'vnfLcmOpOcc': { + 'href': '1' + }, + 'vnfInstance': { + 'href': '2' + } + } +} + +VNF_LCM_OP_OCC_NOTIFICATION_DATA = { + 'id': 'string', + 'notificationType': 'VnfLcmOperationOccurrenceNotification', + 'subscriptionId': 'string', + 'timeStamp': 'string', + 'notificationStatus': 'START', + 'operationState': 'STARTING', + 'vnfInstanceId': 'string', + 'operation': 'INSTANTIATE', + 'isAutomaticInvocation': True, + 'vnfLcmOpOccId': 'string', + 'affectedVnfcs': [{ + 'id': 'string', + 'vduId': 'string', + 'changeType': 'ADDED', + 'computeResource': { + 'vimConnectionId': 'string', + 'resourceProviderId': 'string', + 'resourceId': 'string', + 'vimLevelResourceType': 'string' + }, + 'metadata': {}, + 'affectedVnfcCpIds': [], + 'addedStorageResourceIds': [], + 'removedStorageResourceIds': [], + }], + 'affectedVirtualLinks': [{ + 'id': 'string', + 'virtualLinkDescId': 'string', + 'changeType': 'ADDED', + 'networkResource': { + 'vimConnectionId': 'string', + 'resourceProviderId': 'string', + 'resourceId': 'string', + 'vimLevelResourceType': 'network', + } + }], + 'affectedVirtualStorages': [{ + 'id': 'string', + 'virtualStorageDescId': 'string', + 'changeType': 'ADDED', + 'storageResource': { + 'vimConnectionId': 'string', + 'resourceProviderId': 'string', + 'resourceId': 'string', + 'vimLevelResourceType': 'network', + }, + 'metadata': {} + }], + 'changedInfo': { + 'vnfInstanceName': 'string', + 'vnfInstanceDescription': 'string', + 'vnfConfigurableProperties': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + }, + 'metadata': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + }, + 'extensions': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + }, + 'vimConnectionInfo': [{ + 'id': 'string', + 'vimId': 'string', + 'vimType': 'string', + 'interfaceInfo': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + }, + 'accessInfo': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + }, + 'extra': { + 'additionalProp1': 'string', + 'additionalProp2': 'string', + 'additionalProp3': 'string' + } + }], + 'vnfPkgId': 'string', + 'vnfdId': 'string', + 'vnfProvider': 'string', + 'vnfProductName': 'string', + 'vnfSoftwareVersion': 'string', + 'vnfdVersion': 'string' + }, + 'changedExtConnectivity': [{ + 'id': 'string', + 'resourceHandle': { + 'vimConnectionId': 'string', + 'resourceProviderId': 'string', + 'resourceId': 'string', + 'vimLevelResourceType': 'string' + }, + 'extLinkPorts': [{ + 'id': 'string', + 'resourceHandle': { + 'vimConnectionId': 'string', + 'resourceProviderId': 'string', + 'resourceId': 'string', + 'vimLevelResourceType': 'string' + }, + 'cpInstanceId': 'string' + }] + }], + 'error': { + 'type': 'string', + 'title': 'string', + 'status': 0, + 'detail': 'string', + 'instance': 'string' + }, + '_links': { + 'vnfInstance': {'href': 'string'}, + 'subscription': {'href': 'string'}, + 'vnfLcmOpOcc': {'href': 'string'} + } +} + +VNF_IDENTIFIER_CREATION_NOTIFICATION_DATA = { + 'id': 'Identifier of this notification', + 'notificationType': 'VnfIdentifierCreationNotification', + 'subscriptionId': 'Identifier of the subscription', + 'timeStamp': '2018-9-11', + 'vnfInstanceId': '2', + '_links': { + 'vnfInstance': {'href': 'URI of the referenced resource'}, + 'subscription': {'href': 'URI of the referenced resource'}, + 'vnfLcmOpOcc': {'href': 'URI of the referenced resource'} + } +} + +VNF_IDENTIFIER_DELETION_NOTIFICATION_DATA = { + 'id': 'Identifier of this notification', + 'notificationType': 'VnfIdentifierDeletionNotification', + 'subscriptionId': 'Identifier of the subscription', + 'timeStamp': '2018-9-11', + 'vnfInstanceId': '2', + '_links': { + 'vnfInstance': {'href': 'URI of the referenced resource'}, + 'subscription': {'href': 'URI of the referenced resource'}, + 'vnfLcmOpOcc': {'href': 'URI of the referenced resource'} + } +} diff --git a/lcm/ns_vnfs/tests/vnf_tests.py b/lcm/ns_vnfs/tests/vnf_tests.py index 3b3bddcd..1e4fda67 100644 --- a/lcm/ns_vnfs/tests/vnf_tests.py +++ b/lcm/ns_vnfs/tests/vnf_tests.py @@ -17,6 +17,8 @@ import json import mock from rest_framework.test import APIClient from rest_framework import status +from lcm.ns_vnfs.tests.const import GRANT_DATA, VNF_LCM_OP_OCC_NOTIFICATION_DATA, \ + VNF_IDENTIFIER_CREATION_NOTIFICATION_DATA, VNF_IDENTIFIER_DELETION_NOTIFICATION_DATA from lcm.pub.database.models import NfInstModel from lcm.pub.utils import restcall @@ -30,71 +32,12 @@ class VnfGrantViewTest(unittest.TestCase): @mock.patch.object(restcall, 'call_req') def test_grant_vnf_normal(self, mock_call_req): - data = { - "vnfInstanceId": "1", - "vnfLcmOpOccId": "2", - "vnfdId": "3", - "flavourId": "4", - "operation": "INSTANTIATE", - "isAutomaticInvocation": True, - "instantiationLevelId": "5", - "addResources": [ - { - "id": "1", - "type": "COMPUTE", - "vduId": "2", - "resourceTemplateId": "3", - "resourceTemplate": { - "vimConnectionId": "4", - "resourceProviderId": "5", - "resourceId": "6", - "vimLevelResourceType": "7" - } - } - ], - "placementConstraints": [ - { - "affinityOrAntiAffinity": "AFFINITY", - "scope": "NFVI_POP", - "resource": [ - { - "idType": "RES_MGMT", - "resourceId": "1", - "vimConnectionId": "2", - "resourceProviderId": "3" - } - ] - } - ], - "vimConstraints": [ - { - "sameResourceGroup": True, - "resource": [ - { - "idType": "RES_MGMT", - "resourceId": "1", - "vimConnectionId": "2", - "resourceProviderId": "3" - } - ] - } - ], - "additionalParams": {}, - "_links": { - "vnfLcmOpOcc": { - "href": "1" - }, - "vnfInstance": { - "href": "2" - } - } - } - vimConnections = { + vim_connections = { "id": "1", "vimId": "1", } - mock_call_req.return_value = [0, json.JSONEncoder().encode(vimConnections), '200'] - response = self.client.post("/api/nslcm/v2/grants", data=data, format='json') + mock_call_req.return_value = [0, json.JSONEncoder().encode(vim_connections), '200'] + response = self.client.post("/api/nslcm/v2/grants", data=GRANT_DATA, format='json') self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.content) resp_data = json.loads(response.content) expect_resp_data = { @@ -111,60 +54,7 @@ class VnfGrantViewTest(unittest.TestCase): self.assertEqual(expect_resp_data, resp_data) def test_grant_vnf_when_vnfinst_not_exist(self): - data = { - "vnfInstanceId": "1", - "vnfLcmOpOccId": "2", - "vnfdId": "3", - "flavourId": "4", - "operation": "INSTANTIATE", - "isAutomaticInvocation": True, - "instantiationLevelId": "5", - "removeResources": [ - { - "id": "1", - "type": "COMPUTE", - "vduId": "2", - "resourceTemplateId": "3", - } - ], - "placementConstraints": [ - { - "affinityOrAntiAffinity": "AFFINITY", - "scope": "NFVI_POP", - "resource": [ - { - "idType": "RES_MGMT", - "resourceId": "1", - "vimConnectionId": "2", - "resourceProviderId": "3" - } - ] - } - ], - "vimConstraints": [ - { - "sameResourceGroup": True, - "resource": [ - { - "idType": "RES_MGMT", - "resourceId": "1", - "vimConnectionId": "2", - "resourceProviderId": "3" - } - ] - } - ], - "additionalParams": {}, - "_links": { - "vnfLcmOpOcc": { - "href": "1" - }, - "vnfInstance": { - "href": "2" - } - } - } - response = self.client.post("/api/nslcm/v2/grants", data=data, format='json') + response = self.client.post("/api/nslcm/v2/grants", data=GRANT_DATA, format='json') self.failUnlessEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code) @mock.patch.object(restcall, 'call_req') @@ -278,141 +168,26 @@ class VnfGrantViewTest(unittest.TestCase): response = self.client.get("/api/nslcm/v2/ns/1/ns_vnfs/1/Notify") self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content) - def test_notify_vnf_normal(self): - data = { - "id": "string", - "notificationType": "VnfLcmOperationOccurrenceNotification", - "subscriptionId": "string", - "timeStamp": "string", - "notificationStatus": "START", - "operationState": "STARTING", - "vnfInstanceId": "string", - "operation": "INSTANTIATE", - "isAutomaticInvocation": True, - "vnfLcmOpOccId": "string", - "affectedVnfcs": [{ - "id": "string", - "vduId": "string", - "changeType": "ADDED", - "computeResource": { - "vimConnectionId": "string", - "resourceProviderId": "string", - "resourceId": "string", - "vimLevelResourceType": "string" - }, - "metadata": {}, - "affectedVnfcCpIds": [], - "addedStorageResourceIds": [], - "removedStorageResourceIds": [], - }], - "affectedVirtualLinks": [{ - "id": "string", - "virtualLinkDescId": "string", - "changeType": "ADDED", - "networkResource": { - "vimConnectionId": "string", - "resourceProviderId": "string", - "resourceId": "string", - "vimLevelResourceType": "network", - } - }], - "affectedVirtualStorages": [{ - "id": "string", - "virtualStorageDescId": "string", - "changeType": "ADDED", - "storageResource": { - "vimConnectionId": "string", - "resourceProviderId": "string", - "resourceId": "string", - "vimLevelResourceType": "network", - }, - "metadata": {} - }], - "changedInfo": { - "vnfInstanceName": "string", - "vnfInstanceDescription": "string", - "vnfConfigurableProperties": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - }, - "metadata": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - }, - "extensions": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - }, - "vimConnectionInfo": [{ - "id": "string", - "vimId": "string", - "vimType": "string", - "interfaceInfo": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - }, - "accessInfo": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - }, - "extra": { - "additionalProp1": "string", - "additionalProp2": "string", - "additionalProp3": "string" - } - }], - "vnfPkgId": "string", - "vnfdId": "string", - "vnfProvider": "string", - "vnfProductName": "string", - "vnfSoftwareVersion": "string", - "vnfdVersion": "string" - }, - "changedExtConnectivity": [{ - "id": "string", - "resourceHandle": { - "vimConnectionId": "string", - "resourceProviderId": "string", - "resourceId": "string", - "vimLevelResourceType": "string" - }, - "extLinkPorts": [{ - "id": "string", - "resourceHandle": { - "vimConnectionId": "string", - "resourceProviderId": "string", - "resourceId": "string", - "vimLevelResourceType": "string" - }, - "cpInstanceId": "string" - }] - }], - "error": { - "type": "string", - "title": "string", - "status": 0, - "detail": "string", - "instance": "string" - }, - "_links": { - "vnfInstance": { - "href": "string" - }, - "subscription": { - "href": "string" - }, - "vnfLcmOpOcc": { - "href": "string" - } - } - } + def test_notify_vnflcmopooc_normal(self): NfInstModel.objects.create(nfinstid='22', mnfinstid='2', vnfm_inst_id='1') - response = self.client.post("/api/nslcm/v2/ns/1/ns_vnfs/2/Notify", data=data, format='json') - self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content) + response = self.client.post("/api/nslcm/v2/ns/1/ns_vnfs/2/Notify", + data=VNF_LCM_OP_OCC_NOTIFICATION_DATA, + format='json') + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) + + def test_notify_vnf_identifier_creation_normal(self): + response = self.client.post("/api/nslcm/v2/ns/1/ns_vnfs/2/Notify", + data=VNF_IDENTIFIER_CREATION_NOTIFICATION_DATA, + format='json') + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) + + def test_notify_vnf_identifier_deletion_normal(self): + NfInstModel.objects.create(nfinstid='22', + mnfinstid='2', + vnfm_inst_id='1') + response = self.client.post("/api/nslcm/v2/ns/1/ns_vnfs/2/Notify", + data=VNF_IDENTIFIER_DELETION_NOTIFICATION_DATA, + format='json') + self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) |