diff options
-rw-r--r-- | lcm/v2/grant_vnf.py | 8 | ||||
-rw-r--r-- | lcm/v2/handle_vnflcmooc_notification.py | 22 | ||||
-rw-r--r-- | lcm/v2/tests.py | 37 | ||||
-rw-r--r-- | lcm/v2/views.py | 1 |
4 files changed, 42 insertions, 26 deletions
diff --git a/lcm/v2/grant_vnf.py b/lcm/v2/grant_vnf.py index 5395d7eb..38b1fbc2 100644 --- a/lcm/v2/grant_vnf.py +++ b/lcm/v2/grant_vnf.py @@ -35,10 +35,10 @@ class GrantVnf(object): has_res_tpl = False grant_type = None vimConnections = [] - if ignore_case_get(self.data, "addResource"): - grant_type = "addResource" - elif ignore_case_get(self.data, "removeResource"): - grant_type = "removeResource" + if ignore_case_get(self.data, "addResources"): + grant_type = "addResources" + elif ignore_case_get(self.data, "removeResources"): + grant_type = "removeResources" else: has_res_tpl = True diff --git a/lcm/v2/handle_vnflcmooc_notification.py b/lcm/v2/handle_vnflcmooc_notification.py index 3ab4debe..4b13a246 100644 --- a/lcm/v2/handle_vnflcmooc_notification.py +++ b/lcm/v2/handle_vnflcmooc_notification.py @@ -82,23 +82,23 @@ class HandleVnfLcmOocNotification(object): vmId = ignore_case_get(computeResource, 'resourceId') vmName = ignore_case_get(computeResource, 'resourceId') # replaced with resouceId temporarily - if changeType == 'added': + if changeType == 'ADDED': VNFCInstModel(vnfcinstanceid=vnfcInstanceId, vduid=vduId, nfinstid=self.vnf_instid, vmid=vmId).save() VmInstModel(vmid=vmId, vimid=vimId, resouceid=vmId, insttype=INST_TYPE.VNF, instid=self.vnf_instid, vmname=vmName, hostid='1').save() if REPORT_TO_AAI: self.create_vserver_in_aai(vimId, vmId, vmName) - elif changeType == 'removed': + elif changeType == 'REMOVED': if REPORT_TO_AAI: self.delete_vserver_in_aai(vimId, vmId, vmName) VNFCInstModel.objects.filter(vnfcinstanceid=vnfcInstanceId).delete() - elif changeType == 'modified': + elif changeType == 'MODIFIED': VNFCInstModel.objects.filter(vnfcinstanceid=vnfcInstanceId).update(vduid=vduId, nfinstid=self.vnf_instid, vmid=vmId) else: - self.exception('affectedVnfc struct error: changeType not in {added,removed,modified}') + self.exception('affectedVnfc struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') logger.debug("Success to update all vserver to aai.") def update_Vl(self): @@ -116,17 +116,17 @@ class HandleVnfLcmOocNotification(object): ownerId = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) - if changeType == 'added': + if changeType == 'ADDED': VLInstModel(vlinstanceid=vlInstanceId, vldid=vldid, vlinstancename=resourceName, ownertype=0, ownerid=ownerId, relatednetworkid=resourceId, vltype=0).save() - elif changeType == 'removed': + elif changeType == 'REMOVED': VLInstModel.objects.filter(vlinstanceid=vlInstanceId).delete() - elif changeType == 'modified': + elif changeType == 'MODIFIED': VLInstModel.objects.filter(vlinstanceid=vlInstanceId)\ .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}') + self.exception('affectedVl struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') def update_Cp(self): for cp in self.affectedCps: @@ -182,12 +182,12 @@ class HandleVnfLcmOocNotification(object): ownerId = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid) - if changeType in ['added', 'modified']: + if changeType in ['ADDED', 'MODIFIED']: self.create_network_and_subnet_in_aai(vlInstanceId, ownerId) - elif changeType == 'removed': + elif changeType == 'REMOVED': self.delete_network_and_subnet_in_aai(vlInstanceId) else: - logger.error('affectedVl struct error: changeType not in {added,removed,modified}') + logger.error('affectedVl struct error: changeType not in {ADDED, REMOVED, MODIFIED, TEMPORARY}') except NSLCMException as e: logger.debug("Fail to create internal network to aai, detail message: %s" % e.message) except: diff --git a/lcm/v2/tests.py b/lcm/v2/tests.py index 76f3448b..996852f1 100644 --- a/lcm/v2/tests.py +++ b/lcm/v2/tests.py @@ -15,14 +15,15 @@ import unittest import json import mock -from django.test import Client +from rest_framework.test import APIClient from rest_framework import status +from lcm.pub.database.models import NfInstModel from lcm.pub.utils import restcall class VnfGrantViewTest(unittest.TestCase): def setUp(self): - self.client = Client() + self.client = APIClient() def tearDown(self): pass @@ -107,7 +108,6 @@ class VnfGrantViewTest(unittest.TestCase): } ] } - self.assertEqual(expect_resp_data, resp_data) def test_get_notify_vnf_normal(self): @@ -129,11 +129,11 @@ class VnfGrantViewTest(unittest.TestCase): "affectedVnfcs": [{ "id": "string", "vduId": "string", - "changeType": "added", + "changeType": "ADDED", "computeResource": { "vimConnectionId": "string", "resourceProviderId": "string", - "resouceId": "string", + "resourceId": "string", "vimLevelResourceType": "string" }, "metadata": {}, @@ -142,16 +142,28 @@ class VnfGrantViewTest(unittest.TestCase): "removedStorageResourceIds": [], }], "affectedVirtualLinks": [{ - "vlInstanceId": "string", - "vldId": "string", - "changeType": "added", + "id": "string", + "virtualLinkDescId": "string", + "changeType": "ADDED", "networkResource": { - "resourceType": "network", + "vimConnectionId": "string", + "resourceProviderId": "string", "resourceId": "string", - "resourceName": "string" + "vimLevelResourceType": "network", } }], - "affectedVirtualStorages": [{}], + "affectedVirtualStorages": [{ + "id": "string", + "virtualStorageDescId": "string", + "changeType": "ADDED", + "storageResource": { + "vimConnectionId": "string", + "resourceProviderId": "string", + "resourceId": "string", + "vimLevelResourceType": "network", + }, + "metadata": {} + }], "changedInfo": { "vnfInstanceName": "string", "vnfInstanceDescription": "string", @@ -235,5 +247,8 @@ class VnfGrantViewTest(unittest.TestCase): } } } + NfInstModel.objects.create(nfinstid='22', + mnfinstid='2', + vnfm_inst_id='1') response = self.client.post("/api/nslcm/v2/ns/1/vnfs/2/Notify", data=data, format='json') self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content) diff --git a/lcm/v2/views.py b/lcm/v2/views.py index a3ce25a7..9c953c19 100644 --- a/lcm/v2/views.py +++ b/lcm/v2/views.py @@ -75,6 +75,7 @@ class VnfNotifyView(APIView): vnfLcmOocNotificationSerializer = VnfLcmOperationOccurrenceNotificationSerializer(data=request.data) if not vnfLcmOocNotificationSerializer.is_valid(): raise Exception(vnfLcmOocNotificationSerializer.errors) + HandleVnfLcmOocNotification(vnfmId, vnfInstanceId, vnfLcmOocNotificationSerializer.data).do_biz() return Response(data={}, status=status.HTTP_204_NO_CONTENT) except Exception as e: |