Fix the typo for terminate
[vfc/nfvo/lcm.git] / lcm / ns_vnfs / tests / tests.py
index b6c5a1b..f0ecc8f 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):
@@ -727,14 +729,14 @@ class TestGetVimInfoViews(TestCase):
 class TestPlaceVnfViews(TestCase):
     def setUp(self):
         self.vnf_inst_id = "1234"
-        self.vnf_inst_name = "vG"
+        self.vnf_id = "vG"
         self.client = Client()
         OOFDataModel.objects.all().delete()
         OOFDataModel.objects.create(
             request_id="1234",
             transaction_id="1234",
             request_status="init",
-            request_module_name=self.vnf_inst_name,
+            request_module_name=self.vnf_id,
             service_resource_id=self.vnf_inst_id,
             vim_id="",
             cloud_owner="",
@@ -750,6 +752,7 @@ class TestPlaceVnfViews(TestCase):
         vdu_info_json = [{
             "vduName": "vG_0",
             "flavorName": "HPA.flavor.1",
+            "flavorId": "12345",
             "directive": []
         }]
         PlaceVnfs(vnf_place_request).extract()
@@ -770,7 +773,7 @@ class TestPlaceVnfViews(TestCase):
                 "placementSolutions": [
                     [
                         {
-                            "resourceModuleName": self.vnf_inst_name,
+                            "resourceModuleName": self.vnf_id,
                             "serviceResourceId": self.vnf_inst_id,
                             "solution": {
                                 "identifierType": "serviceInstanceId",
@@ -821,7 +824,7 @@ class TestPlaceVnfViews(TestCase):
                 "placementSolutions": [
                     [
                         {
-                            "resourceModuleName": self.vnf_inst_name,
+                            "resourceModuleName": self.vnf_id,
                             "serviceResourceId": self.vnf_inst_id,
                             "solution": {
                                 "identifierType": "serviceInstanceId",
@@ -871,7 +874,7 @@ class TestPlaceVnfViews(TestCase):
                 "placementSolutions": [
                     [
                         {
-                            "resourceModuleName": self.vnf_inst_name,
+                            "resourceModuleName": self.vnf_id,
                             "serviceResourceId": self.vnf_inst_id,
                             "solution": {
                                 "identifierType": "serviceInstanceId",
@@ -936,6 +939,39 @@ 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",
+            "operation": "INSTANTIATE"
+        }
+        vdu_info_dict = [{"vduName": "vg", "flavorName": "flavor_1", "flavorId": "12345", "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'], '12345')
+
+
 vnfd_model_dict = {
     'local_storages': [],
     'vdus': [
@@ -1723,15 +1759,19 @@ vnf_place_request = {
                              "directives": [
                                  {
                                      "id": "vG_0",
-                                     "type": "tocsa.nodes.nfv.Vdu.Compute",
+                                     "type": "tosca.nodes.nfv.Vdu.Compute",
                                      "directives": [
                                          {
                                              "type": "flavor_directives",
                                              "attributes": [
                                                  {
-                                                     "attribute_name": "flavor_name",
+                                                     "attribute_name": "flavorName",
                                                      "attribute_value": "HPA.flavor.1"
-                                                 }
+                                                 },
+                                                 {
+                                                     "attribute_name": "flavorId",
+                                                     "attribute_value": "12345"
+                                                 },
                                              ]
                                          }
                                      ]