Comply with current data model in grant vnf 17/71817/3
authorRuoyu Ying <ruoyu.ying@intel.com>
Mon, 5 Nov 2018 08:58:21 +0000 (16:58 +0800)
committerRuoyu Ying <ruoyu.ying@intel.com>
Tue, 6 Nov 2018 02:38:01 +0000 (10:38 +0800)
Change the code to comply with current data model

Change-Id: I3047fd240313eb0a48e2c69fa52a9ac1f6c395a3
Issue-ID: VFC-1085
Signed-off-by: Ruoyu Ying <ruoyu.ying@intel.com>
lcm/ns_vnfs/biz/grant_vnf.py
lcm/ns_vnfs/tests/tests.py

index faeebec..6987fc0 100644 (file)
@@ -105,12 +105,14 @@ class GrantVnf(object):
 
         offs = OOFDataModel.objects.filter(service_resource_id=ignore_case_get(self.data, "vnfInstanceId"))
         if offs.exists():
-            for off in offs:
+            vdu_info = json.loads(offs[0].vdu_info)
+            grant_resp['vimAssets'] = {'computeResourceFlavours': []}
+            for vdu in vdu_info:
                 grant_resp['vimAssets']['computeResourceFlavours'].append({
-                    'vimConnectionId': off.vim_id,
-                    'resourceProviderId': off.vdu_name,
+                    'vimConnectionId': offs[0].vim_id,
+                    'resourceProviderId': vdu.get("vduName"),
                     'vnfdVirtualComputeDescId': None,  # TODO: required
-                    'vimFlavourId': off.flavor_name
+                    'vimFlavourId': vdu.get("flavorName")
                 })
                 # grant_resp['additionalparams'][off.vim_id] = off.directive
 
index b6c5a1b..422182a 100644 (file)
@@ -26,6 +26,7 @@ from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.values import ignore_case_get
 from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
+from lcm.ns_vnfs.biz.grant_vnf import GrantVnf
 from lcm.ns_vnfs.biz.heal_vnfs import NFHealService
 from lcm.ns_vnfs.biz.scale_vnfs import NFManualScaleService
 from lcm.ns_vnfs.biz.subscribe import SubscriptionDeletion
@@ -33,6 +34,7 @@ from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
 from lcm.ns_vnfs.const import VNF_STATUS, INST_TYPE
 from lcm.ns_vnfs.biz import create_vnfs
 from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
+from lcm.pub.msapi import resmgr
 
 
 class TestGetVnfViews(TestCase):
@@ -936,6 +938,38 @@ class TestPlaceVnfViews(TestCase):
         self.assertEqual(db_info[0].vdu_info, "none")
 
 
+class TestGrantVnfViews(TestCase):
+    def setUp(self):
+        self.vnf_inst_id = str(uuid.uuid4())
+        self.data = {
+            "vnfInstanceId": self.vnf_inst_id,
+            "vnfLcmOpOccId": "1234"
+        }
+        vdu_info_dict = [{"vduName": "vg", "flavorName": "flavor_1", "directive": []}]
+        OOFDataModel(request_id='1234', transaction_id='1234', request_status='done', request_module_name='vg',
+                     service_resource_id=self.vnf_inst_id, vim_id='cloudOwner_casa', cloud_owner='cloudOwner',
+                     cloud_region_id='casa', vdu_info=json.dumps(vdu_info_dict)).save()
+
+    def tearDown(self):
+        OOFDataModel.objects.all().delete()
+
+    @mock.patch.object(resmgr, "grant_vnf")
+    def test_exec_grant(self, mock_grant):
+        resmgr_grant_resp = {
+            "vim": {
+                "vimId": "cloudOwner_casa",
+                "accessInfo": {
+                    "tenant": "tenantA"
+                }
+            }
+        }
+        mock_grant.return_value = resmgr_grant_resp
+        resp = GrantVnf(self.data).exec_grant()
+        self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['vimConnectionId'], 'cloudOwner_casa')
+        self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['resourceProviderId'], 'vg')
+        self.assertEquals(resp['vimAssets']['computeResourceFlavours'][0]['vimFlavourId'], 'flavor_1')
+
+
 vnfd_model_dict = {
     'local_storages': [],
     'vdus': [