X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fnf%2Ftests%2Ftest_operate_vnf.py;h=3ebc90a2c84ba6dcb8c72d23aab72e087739f69e;hb=9975ee2ab76998715538fa3aeee377b947125b7e;hp=625d40a3058839cdfec1cf47f4a228c9d5c194f3;hpb=5729b6abb1a43319bfa419db6548ae8df6120479;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/nf/tests/test_operate_vnf.py b/lcm/lcm/nf/tests/test_operate_vnf.py index 625d40a3..3ebc90a2 100644 --- a/lcm/lcm/nf/tests/test_operate_vnf.py +++ b/lcm/lcm/nf/tests/test_operate_vnf.py @@ -13,15 +13,17 @@ # limitations under the License. import json +import uuid import mock from django.test import TestCase, Client from rest_framework import status from lcm.nf.biz.operate_vnf import OperateVnf -from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel +from lcm.pub.database.models import NfInstModel, JobStatusModel, VmInstModel, SubscriptionModel from lcm.pub.utils import restcall from lcm.pub.utils.jobutil import JobUtil +from lcm.pub.utils.notificationsutil import NotificationsUtil from lcm.pub.utils.timeutil import now_time from lcm.pub.vimapi import api @@ -68,7 +70,8 @@ class TestNFOperate(TestCase): @mock.patch.object(restcall, 'call_req') @mock.patch.object(api, 'call') - def test_operate_vnf_success_start(self, mock_call, mock_call_req): + @mock.patch.object(NotificationsUtil, 'post_notification') + def test_operate_vnf_success_start(self, mock_post_notification, mock_call, mock_call_req): NfInstModel.objects.create(nfinstid='1111', nf_name='2222', vnfminstid='1', @@ -93,11 +96,39 @@ class TestNFOperate(TestCase): vmname="test_01", is_predefined=1, operationalstate=1) + + SubscriptionModel.objects.create( + subscription_id=str(uuid.uuid4()), + callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification', + auth_info=json.JSONEncoder().encode({ + 'authType': ['BASIC'], + 'paramsBasic': { + 'userName': 'username', + 'password': 'password' + } + }), + notification_types=str([ + 'VnfLcmOperationOccurrenceNotification', + 'VnfIdentifierCreationNotification', + 'VnfIdentifierDeletionNotification' + ]), + operation_types=str(['OPERATE']), + operation_states=str(['COMPLETED']), + vnf_instance_filter=json.JSONEncoder().encode({ + 'vnfdIds': [], + 'vnfProductsFromProviders': [], + 'vnfInstanceIds': ['1111'], + 'vnfInstanceNames': [], + }) + ) + t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200'] - t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200'] + # t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200'] t3_action_vm_start_result = [0, json.JSONEncoder().encode(''), '202'] - mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result] + # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_start_result] + mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_start_result] mock_call.return_value = None + mock_post_notification.return_value = None req_data = { "changeStateTo": "STARTED" } @@ -111,7 +142,8 @@ class TestNFOperate(TestCase): @mock.patch.object(restcall, 'call_req') @mock.patch.object(api, 'call') - def test_operate_vnf_success_stop(self, mock_call, mock_call_req): + @mock.patch.object(NotificationsUtil, 'post_notification') + def test_operate_vnf_success_stop(self, mock_post_notification, mock_call, mock_call_req): NfInstModel.objects.create(nfinstid='1111', nf_name='2222', vnfminstid='1', @@ -136,11 +168,39 @@ class TestNFOperate(TestCase): vmname="test_01", is_predefined=1, operationalstate=1) + + SubscriptionModel.objects.create( + subscription_id=str(uuid.uuid4()), + callback_uri='api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification', + auth_info=json.JSONEncoder().encode({ + 'authType': ['BASIC'], + 'paramsBasic': { + 'userName': 'username', + 'password': 'password' + } + }), + notification_types=str([ + 'VnfLcmOperationOccurrenceNotification', + 'VnfIdentifierCreationNotification', + 'VnfIdentifierDeletionNotification' + ]), + operation_types=str(['OPERATE']), + operation_states=str(['COMPLETED']), + vnf_instance_filter=json.JSONEncoder().encode({ + 'vnfdIds': [], + 'vnfProductsFromProviders': [], + 'vnfInstanceIds': ['1111'], + 'vnfInstanceNames': [], + }) + ) + t1_apply_grant_result = [0, json.JSONEncoder().encode(''), '200'] - t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200'] + # t2_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200'] t3_action_vm_stop_result = [0, json.JSONEncoder().encode(''), '202'] - mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result] + # mock_call_req.side_effect = [t1_apply_grant_result, t2_lcm_notify_result, t3_action_vm_stop_result] + mock_call_req.side_effect = [t1_apply_grant_result, t3_action_vm_stop_result] mock_call.return_value = None + mock_post_notification.return_value = None req_data = { "changeStateTo": "STOPPED" }