Deal with VnfLcmOocNotification related stuffs. 79/60479/1
authorlaili <lai.li@zte.com.cn>
Tue, 14 Aug 2018 07:36:14 +0000 (15:36 +0800)
committerlaili <lai.li@zte.com.cn>
Tue, 14 Aug 2018 07:36:14 +0000 (15:36 +0800)
Fix bugs.

Change-Id: Ie7dea71c6634a3baf257d44bb8d86388f907e936
Issue-ID: VFC-1018
Signed-off-by: laili <lai.li@zte.com.cn>
lcm/v2/grant_vnf.py
lcm/v2/handle_vnflcmooc_notification.py
lcm/v2/tests.py
lcm/v2/views.py

index 5395d7e..38b1fbc 100644 (file)
@@ -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
 
index 3ab4deb..4b13a24 100644 (file)
@@ -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:
index 76f3448..996852f 100644 (file)
 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)
index a3ce25a..9c953c1 100644 (file)
@@ -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: