Notification stuffs. 71/66271/2
authorlaili <lai.li@zte.com.cn>
Thu, 13 Sep 2018 02:54:16 +0000 (10:54 +0800)
committerLi Lai <lai.li@zte.com.cn>
Thu, 13 Sep 2018 02:55:31 +0000 (02:55 +0000)
- Send operation and terminate notification using notificationutil.

Change-Id: Id32d6ed37cf8f09c836c90c03819b8125135e69a
Issue-ID: VFC-1095
Signed-off-by: laili <lai.li@zte.com.cn>
lcm/lcm/nf/biz/instantiate_vnf.py
lcm/lcm/nf/biz/operate_vnf.py
lcm/lcm/nf/biz/terminate_vnf.py
lcm/lcm/nf/const.py
lcm/lcm/nf/serializers/affected_storages.py
lcm/lcm/nf/serializers/affected_vls.py
lcm/lcm/nf/serializers/affected_vnfcs.py
lcm/lcm/nf/tests/test_operate_vnf.py
lcm/lcm/nf/tests/test_terminate_vnf.py
lcm/lcm/pub/msapi/gvnfmdriver.py

index f86baab..73109c8 100644 (file)
@@ -30,7 +30,7 @@ from lcm.pub.utils.notificationsutil import NotificationsUtil
 from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean, get_integer
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
 from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean, get_integer
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
-from lcm.nf.const import GRANT_TYPE
+from lcm.nf.const import CHANGE_TYPE, GRANT_TYPE, OPERATION_TYPE
 
 logger = logging.getLogger(__name__)
 
 
 logger = logging.getLogger(__name__)
 
@@ -131,7 +131,7 @@ class InstantiateVnf(Thread):
         logger.info("Create resource finish")
 
     def lcm_notify(self):
         logger.info("Create resource finish")
 
     def lcm_notify(self):
-        notification_content = prepare_notification_data(self.nf_inst_id, self.job_id, "ADDED")
+        notification_content = prepare_notification_data(self.nf_inst_id, self.job_id, CHANGE_TYPE.ADDED, OPERATION_TYPE.INSTANTIATE)
         logger.info('Notify request data = %s' % notification_content)
         # resp = notify_lcm_to_nfvo(json.dumps(notification_content))
         # logger.info('Lcm notify end, response %s' % resp)
         logger.info('Notify request data = %s' % notification_content)
         # resp = notify_lcm_to_nfvo(json.dumps(notification_content))
         # logger.info('Lcm notify end, response %s' % resp)
index 99c1e6d..1c01ada 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import json
+import json
 import logging
 import traceback
 from threading import Thread
 
 from lcm.pub.database.models import NfInstModel, VmInstModel
 from lcm.pub.exceptions import NFLCMException
 import logging
 import traceback
 from threading import Thread
 
 from lcm.pub.database.models import NfInstModel, VmInstModel
 from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo, prepare_notification_data
+from lcm.pub.msapi.gvnfmdriver import prepare_notification_data
+# from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.timeutil import now_time
+from lcm.pub.utils.notificationsutil import NotificationsUtil
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
-from lcm.nf.const import VNF_STATUS, RESOURCE_MAP, GRANT_TYPE
+from lcm.nf.const import VNF_STATUS, RESOURCE_MAP, CHANGE_TYPE, GRANT_TYPE, OPERATION_TYPE
 
 logger = logging.getLogger(__name__)
 
 
 logger = logging.getLogger(__name__)
 
@@ -88,10 +90,11 @@ class OperateVnf(Thread):
         logger.info('Operate resource complete')
 
     def lcm_notify(self):
         logger.info('Operate resource complete')
 
     def lcm_notify(self):
-        notification_content = prepare_notification_data(self.nf_inst_id, self.job_id, "MODIFIED")
+        notification_content = prepare_notification_data(self.nf_inst_id, self.job_id, CHANGE_TYPE.MODIFIED, OPERATION_TYPE.OPERATE)
         logger.info('Notify request data = %s' % notification_content)
         logger.info('Notify request data = %s' % notification_content)
-        resp = notify_lcm_to_nfvo(json.dumps(notification_content))
-        logger.info('Lcm notify end, response %s' % resp)
+        # resp = notify_lcm_to_nfvo(json.dumps(notification_content))
+        # logger.info('Lcm notify end, response %s' % resp)
+        NotificationsUtil().send_notification(notification_content)
 
     def vnf_operate_failed_handle(self, error_msg):
         logger.error('VNF Operation failed, detail message: %s' % error_msg)
 
     def vnf_operate_failed_handle(self, error_msg):
         logger.error('VNF Operation failed, detail message: %s' % error_msg)
index 5b299f2..4f74f62 100644 (file)
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import json
+import json
 import logging
 import traceback
 from threading import Thread
 import logging
 import traceback
 from threading import Thread
@@ -24,13 +24,15 @@ from lcm.pub.database.models import (
     FlavourInstModel, SubNetworkInstModel
 )
 from lcm.pub.exceptions import NFLCMException
     FlavourInstModel, SubNetworkInstModel
 )
 from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.gvnfmdriver import prepare_notification_data, notify_lcm_to_nfvo
+from lcm.pub.msapi.gvnfmdriver import prepare_notification_data
+# from lcm.pub.msapi.gvnfmdriver import notify_lcm_to_nfvo
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.timeutil import now_time
+from lcm.pub.utils.notificationsutil import NotificationsUtil
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
 from lcm.pub.utils.values import ignore_case_get
 from lcm.pub.vimapi import adaptor
 from lcm.nf.biz.grant_vnf import grant_resource
-from lcm.nf.const import GRANT_TYPE
+from lcm.nf.const import CHANGE_TYPE, GRANT_TYPE, OPERATION_TYPE
 
 logger = logging.getLogger(__name__)
 
 
 logger = logging.getLogger(__name__)
 
@@ -98,7 +100,7 @@ class TerminateVnf(Thread):
         }
 
     def query_notify_data(self):
         }
 
     def query_notify_data(self):
-        self.notify_data = prepare_notification_data(self.nf_inst_id, self.job_id, "RMOVED")
+        self.notify_data = prepare_notification_data(self.nf_inst_id, self.job_id, CHANGE_TYPE.REMOVED, OPERATION_TYPE.TERMINATE)
         NetworkInstModel.objects.filter(instid=self.nf_inst_id)
         StorageInstModel.objects.filter(instid=self.nf_inst_id)
         PortInstModel.objects.filter(instid=self.nf_inst_id)
         NetworkInstModel.objects.filter(instid=self.nf_inst_id)
         StorageInstModel.objects.filter(instid=self.nf_inst_id)
         PortInstModel.objects.filter(instid=self.nf_inst_id)
@@ -120,8 +122,9 @@ class TerminateVnf(Thread):
     def lcm_notify(self):
         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='NOT_INSTANTIATED', lastuptime=now_time())
         logger.info('Send notify request to nfvo')
     def lcm_notify(self):
         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='NOT_INSTANTIATED', lastuptime=now_time())
         logger.info('Send notify request to nfvo')
-        resp = notify_lcm_to_nfvo(json.dumps(self.notify_data))
-        logger.info('Lcm notify end, response: %s' % resp)
+        # resp = notify_lcm_to_nfvo(json.dumps(self.notify_data))
+        # logger.info('Lcm notify end, response: %s' % resp)
+        NotificationsUtil().send_notification(self.notify_data)
 
     def vnf_term_failed_handle(self, error_msg):
         logger.error('VNF termination failed, detail message: %s' % error_msg)
 
     def vnf_term_failed_handle(self, error_msg):
         logger.error('VNF termination failed, detail message: %s' % error_msg)
index 15e2715..912b9c3 100644 (file)
@@ -22,6 +22,37 @@ VNF_STATUS = enum(NULL='null', INSTANTIATING="instantiating", INACTIVE='inactive
                   FAILED="failed", TERMINATING="terminating", SCALING="scaling", OPERATING="operating",
                   UPDATING="updating", HEALING="healing")
 
                   FAILED="failed", TERMINATING="terminating", SCALING="scaling", OPERATING="operating",
                   UPDATING="updating", HEALING="healing")
 
+OPERATION_TYPE = enum(
+    INSTANTIATE="INSTANTIATE",
+    SCALE="SCALE",
+    SCALE_TO_LEVEL="SCALE_TO_LEVEL",
+    CHANGE_FLAVOUR="CHANGE_FLAVOUR",
+    TERMINATE="TERMINATE",
+    HEAL="HEAL",
+    OPERATE="OPERATE",
+    CHANGE_EXT_CONN="CHANGE_EXT_CONN",
+    MODIFY_INFO="MODIFY_INFO"
+)
+
+OPERATION_STATE_TYPE = enum(
+    STARTING="STARTING",
+    PROCESSING="PROCESSING",
+    COMPLETED="COMPLETED",
+    FAILED_TEMP="FAILED_TEMP",
+    FAILED="FAILED",
+    ROLLING_BACK="ROLLING_BACK",
+    ROLLED_BACK="ROLLED_BACK"
+)
+
+CHANGE_TYPE = enum(
+    ADDED='ADDED',
+    REMOVED='REMOVED',
+    MODIFIED='MODIFIED',
+    TEMPORARY='TEMPORARY',
+    LINK_PORT_ADDED='LINK_PORT_ADDED',
+    LINK_PORT_REMOVED='LINK_PORT_REMOVED'
+)
+
 RESOURCE_MAP = {'Storage': 'volumn', 'Network': 'network', 'SubNetwork': 'subnet', 'Port': 'port',
                 'Flavour': 'flavor', 'Vm': 'vm'}
 
 RESOURCE_MAP = {'Storage': 'volumn', 'Network': 'network', 'SubNetwork': 'subnet', 'Port': 'port',
                 'Flavour': 'flavor', 'Vm': 'vm'}
 
@@ -42,25 +73,25 @@ NOTIFICATION_TYPES = [
 ]
 
 LCM_OPERATION_TYPES = [
 ]
 
 LCM_OPERATION_TYPES = [
-    "INSTANTIATE",
-    "SCALE",
-    "SCALE_TO_LEVEL",
-    "CHANGE_FLAVOUR",
-    "TERMINATE",
-    "HEAL",
-    "OPERATE",
-    "CHANGE_EXT_CONN",
-    "MODIFY_INFO"
+    OPERATION_TYPE.INSTANTIATE,
+    OPERATION_TYPE.SCALE,
+    OPERATION_TYPE.SCALE_TO_LEVEL,
+    OPERATION_TYPE.CHANGE_FLAVOUR,
+    OPERATION_TYPE.TERMINATE,
+    OPERATION_TYPE.HEAL,
+    OPERATION_TYPE.OPERATE,
+    OPERATION_TYPE.CHANGE_EXT_CONN,
+    OPERATION_TYPE.MODIFY_INFO
 ]
 
 LCM_OPERATION_STATE_TYPES = [
 ]
 
 LCM_OPERATION_STATE_TYPES = [
-    "STARTING",
-    "PROCESSING",
-    "COMPLETED",
-    "FAILED_TEMP",
-    "FAILED",
-    "ROLLING_BACK",
-    "ROLLED_BACK"
+    OPERATION_STATE_TYPE.STARTING,
+    OPERATION_STATE_TYPE.PROCESSING,
+    OPERATION_STATE_TYPE.COMPLETED,
+    OPERATION_STATE_TYPE.FAILED_TEMP,
+    OPERATION_STATE_TYPE.FAILED,
+    OPERATION_STATE_TYPE.ROLLING_BACK,
+    OPERATION_STATE_TYPE.ROLLED_BACK
 ]
 
 
 ]
 
 
index de66f28..1c01fef 100644 (file)
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
 
 CHANGE_TYPES = [
 
 CHANGE_TYPES = [
-    "ADDED",
-    "REMOVED",
-    "MODIFIED",
-    "TEMPORARY"
+    CHANGE_TYPE.ADDED,
+    CHANGE_TYPE.REMOVED,
+    CHANGE_TYPE.MODIFIED,
+    CHANGE_TYPE.TEMPORARY
 ]
 
 
 ]
 
 
index 7bd362e..0b47b27 100644 (file)
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
 
 CHANGE_TYPES = [
 
 CHANGE_TYPES = [
-    "ADDED",
-    "REMOVED",
-    "MODIFIED",
-    "TEMPORARY",
-    "LINK_PORT_ADDED",
-    "LINK_PORT_REMOVED"
+    CHANGE_TYPE.ADDED,
+    CHANGE_TYPE.REMOVED,
+    CHANGE_TYPE.MODIFIED,
+    CHANGE_TYPE.TEMPORARY,
+    CHANGE_TYPE.LINK_PORT_ADDED,
+    CHANGE_TYPE.LINK_PORT_REMOVED
 ]
 
 
 ]
 
 
index 85b8364..10d9347 100644 (file)
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
 from rest_framework import serializers
 
 from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
 
 CHANGE_TYPES = [
 
 CHANGE_TYPES = [
-    "ADDED",
-    "REMOVED",
-    "MODIFIED",
-    "TEMPORARY"
+    CHANGE_TYPE.ADDED,
+    CHANGE_TYPE.REMOVED,
+    CHANGE_TYPE.MODIFIED,
+    CHANGE_TYPE.TEMPORARY
 ]
 
 
 ]
 
 
index 625d40a..3ebc90a 100644 (file)
 # limitations under the License.\r
 \r
 import json\r
 # limitations under the License.\r
 \r
 import json\r
+import uuid\r
 \r
 import mock\r
 from django.test import TestCase, Client\r
 from rest_framework import status\r
 \r
 from lcm.nf.biz.operate_vnf import OperateVnf\r
 \r
 import mock\r
 from django.test import TestCase, Client\r
 from rest_framework import status\r
 \r
 from lcm.nf.biz.operate_vnf import OperateVnf\r
-from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel\r
+from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, SubscriptionModel\r
 from lcm.pub.utils import restcall\r
 from lcm.pub.utils.jobutil import JobUtil\r
 from lcm.pub.utils import restcall\r
 from lcm.pub.utils.jobutil import JobUtil\r
+from lcm.pub.utils.notificationsutil import NotificationsUtil\r
 from lcm.pub.utils.timeutil import now_time\r
 from lcm.pub.vimapi import api\r
 \r
 from lcm.pub.utils.timeutil import now_time\r
 from lcm.pub.vimapi import api\r
 \r
@@ -68,7 +70,8 @@ class TestNFOperate(TestCase):
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
-    def test_operate_vnf_success_start(self, mock_call, mock_call_req):\r
+    @mock.patch.object(NotificationsUtil, 'post_notification')\r
+    def test_operate_vnf_success_start(self, mock_post_notification, mock_call, mock_call_req):\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
@@ -93,11 +96,39 @@ class TestNFOperate(TestCase):
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
+\r
+        SubscriptionModel.objects.create(\r
+            subscription_id=str(uuid.uuid4()),\r
+            callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',\r
+            auth_info=json.JSONEncoder().encode({\r
+                'authType': ['BASIC'],\r
+                'paramsBasic': {\r
+                    'userName': 'username',\r
+                    'password': 'password'\r
+                }\r
+            }),\r
+            notification_types=str([\r
+                'VnfLcmOperationOccurrenceNotification',\r
+                'VnfIdentifierCreationNotification',\r
+                'VnfIdentifierDeletionNotification'\r
+            ]),\r
+            operation_types=str(['OPERATE']),\r
+            operation_states=str(['COMPLETED']),\r
+            vnf_instance_filter=json.JSONEncoder().encode({\r
+                'vnfdIds': [],\r
+                'vnfProductsFromProviders': [],\r
+                'vnfInstanceIds': ['1111'],\r
+                'vnfInstanceNames': [],\r
+            })\r
+        )\r
+\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
-        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
         t3_action_vm_start_result = [0, json.JSONEncoder().encode(''), '202']\r
         t3_action_vm_start_result = [0, json.JSONEncoder().encode(''), '202']\r
-        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result]\r
+        # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result]\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_start_result]\r
         mock_call.return_value = None\r
         mock_call.return_value = None\r
+        mock_post_notification.return_value = None\r
         req_data = {\r
             "changeStateTo": "STARTED"\r
         }\r
         req_data = {\r
             "changeStateTo": "STARTED"\r
         }\r
@@ -111,7 +142,8 @@ class TestNFOperate(TestCase):
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
-    def test_operate_vnf_success_stop(self, mock_call, mock_call_req):\r
+    @mock.patch.object(NotificationsUtil, 'post_notification')\r
+    def test_operate_vnf_success_stop(self, mock_post_notification, mock_call, mock_call_req):\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
@@ -136,11 +168,39 @@ class TestNFOperate(TestCase):
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
                                    vmname="test_01",\r
                                    is_predefined=1,\r
                                    operationalstate=1)\r
+\r
+        SubscriptionModel.objects.create(\r
+            subscription_id=str(uuid.uuid4()),\r
+            callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',\r
+            auth_info=json.JSONEncoder().encode({\r
+                'authType': ['BASIC'],\r
+                'paramsBasic': {\r
+                    'userName': 'username',\r
+                    'password': 'password'\r
+                }\r
+            }),\r
+            notification_types=str([\r
+                'VnfLcmOperationOccurrenceNotification',\r
+                'VnfIdentifierCreationNotification',\r
+                'VnfIdentifierDeletionNotification'\r
+            ]),\r
+            operation_types=str(['OPERATE']),\r
+            operation_states=str(['COMPLETED']),\r
+            vnf_instance_filter=json.JSONEncoder().encode({\r
+                'vnfdIds': [],\r
+                'vnfProductsFromProviders': [],\r
+                'vnfInstanceIds': ['1111'],\r
+                'vnfInstanceNames': [],\r
+            })\r
+        )\r
+\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200']\r
-        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
         t3_action_vm_stop_result = [0, json.JSONEncoder().encode(''), '202']\r
         t3_action_vm_stop_result = [0, json.JSONEncoder().encode(''), '202']\r
-        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result]\r
+        # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result]\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_stop_result]\r
         mock_call.return_value = None\r
         mock_call.return_value = None\r
+        mock_post_notification.return_value = None\r
         req_data = {\r
             "changeStateTo": "STOPPED"\r
         }\r
         req_data = {\r
             "changeStateTo": "STOPPED"\r
         }\r
index 97330b6..5e9a9a8 100644 (file)
@@ -22,10 +22,11 @@ from rest_framework import status
 \r
 from lcm.nf.biz.terminate_vnf import TerminateVnf\r
 from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \\r
 \r
 from lcm.nf.biz.terminate_vnf import TerminateVnf\r
 from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, NetworkInstModel, SubNetworkInstModel, \\r
-    PortInstModel, FlavourInstModel, StorageInstModel\r
+    PortInstModel, FlavourInstModel, StorageInstModel, SubscriptionModel\r
 from lcm.pub.utils import restcall\r
 from lcm.pub.utils.jobutil import JobUtil\r
 from lcm.pub.utils.timeutil import now_time\r
 from lcm.pub.utils import restcall\r
 from lcm.pub.utils.jobutil import JobUtil\r
 from lcm.pub.utils.timeutil import now_time\r
+from lcm.pub.utils.notificationsutil import NotificationsUtil\r
 from lcm.pub.vimapi import api\r
 \r
 \r
 from lcm.pub.vimapi import api\r
 \r
 \r
@@ -115,7 +116,8 @@ class TestNFTerminate(TestCase):
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
 \r
     @mock.patch.object(restcall, 'call_req')\r
     @mock.patch.object(api, 'call')\r
-    def test_terminate_vnf_success(self, mock_call, mock_call_req):\r
+    @mock.patch.object(NotificationsUtil, 'post_notification')\r
+    def test_terminate_vnf_success(self, mock_post_notification, mock_call, mock_call_req):\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
         NfInstModel.objects.create(nfinstid='1111',\r
                                    nf_name='2222',\r
                                    vnfminstid='1',\r
@@ -131,6 +133,32 @@ class TestNFTerminate(TestCase):
                                    vnfConfigurableProperties='todo',\r
                                    localizationLanguage='EN_US',\r
                                    create_time=now_time())\r
                                    vnfConfigurableProperties='todo',\r
                                    localizationLanguage='EN_US',\r
                                    create_time=now_time())\r
+\r
+        SubscriptionModel.objects.create(\r
+            subscription_id=str(uuid.uuid4()),\r
+            callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification',\r
+            auth_info=json.JSONEncoder().encode({\r
+                'authType': ['BASIC'],\r
+                'paramsBasic': {\r
+                    'userName': 'username',\r
+                    'password': 'password'\r
+                }\r
+            }),\r
+            notification_types=str([\r
+                'VnfLcmOperationOccurrenceNotification',\r
+                'VnfIdentifierCreationNotification',\r
+                'VnfIdentifierDeletionNotification'\r
+            ]),\r
+            operation_types=str(['TERMINATE']),\r
+            operation_states=str(['COMPLETED']),\r
+            vnf_instance_filter=json.JSONEncoder().encode({\r
+                'vnfdIds': ['111'],\r
+                'vnfProductsFromProviders': [],\r
+                'vnfInstanceIds': ['1111'],\r
+                'vnfInstanceNames': [],\r
+            })\r
+        )\r
+\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(\r
             {\r
                 "id": "1",\r
         t1_apply_grant_result = [0, json.JSONEncoder().encode(\r
             {\r
                 "id": "1",\r
@@ -143,10 +171,12 @@ class TestNFTerminate(TestCase):
                     }\r
                 ]\r
             }), '200']\r
                     }\r
                 ]\r
             }), '200']\r
-        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
+        t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']\r
         t3_delete_flavor = [0, json.JSONEncoder().encode({"vim_id": "vimid_1"}), '200']\r
         t3_delete_flavor = [0, json.JSONEncoder().encode({"vim_id": "vimid_1"}), '200']\r
-        mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_delete_flavor]\r
+        # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_delete_flavor]\r
+        mock_call_req.side_effect = [t1_apply_grant_result, t3_delete_flavor]\r
         mock_call.return_value = None\r
         mock_call.return_value = None\r
+        mock_post_notification.return_value = None\r
         data = {\r
             "terminationType": "FORCEFUL",\r
             "gracefulTerminationTimeout": 120\r
         data = {\r
             "terminationType": "FORCEFUL",\r
             "gracefulTerminationTimeout": 120\r
index a61227f..13e8dee 100644 (file)
@@ -51,7 +51,7 @@ def notify_lcm_to_nfvo(data):
     return ret[1]
 
 
     return ret[1]
 
 
-def prepare_notification_data(nfinstid, jobid, changetype):
+def prepare_notification_data(nfinstid, jobid, changetype, operation):
     logger.info('Send notify request to nfvo')
     affected_vnfcs = []
     vnfcs = VNFCInstModel.objects.filter(instid=nfinstid)
     logger.info('Send notify request to nfvo')
     affected_vnfcs = []
     vnfcs = VNFCInstModel.objects.filter(instid=nfinstid)
@@ -122,7 +122,7 @@ def prepare_notification_data(nfinstid, jobid, changetype):
         'notificationStatus': 'RESULT',
         'operationState': 'COMPLETED',
         'vnfInstanceId': nfinstid,
         'notificationStatus': 'RESULT',
         'operationState': 'COMPLETED',
         'vnfInstanceId': nfinstid,
-        'operation': 'INSTANTIATE',
+        'operation': operation,
         'isAutomaticInvocation': False,
         'vnfLcmOpOccId': jobid,
         'affectedVnfcs': affected_vnfcs,
         'isAutomaticInvocation': False,
         'vnfLcmOpOccId': jobid,
         'affectedVnfcs': affected_vnfcs,