- Send operation and terminate notification using notificationutil.
Change-Id: Id32d6ed37cf8f09c836c90c03819b8125135e69a
Issue-ID: VFC-1095
Signed-off-by: laili <lai.li@zte.com.cn>
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.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)
# 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
-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.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.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.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)
- 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)
# 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
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.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.nf.const import GRANT_TYPE
+from lcm.nf.const import CHANGE_TYPE, GRANT_TYPE, OPERATION_TYPE
logger = logging.getLogger(__name__)
}
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)
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)
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'}
]
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 = [
- "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
]
from rest_framework import serializers
from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
CHANGE_TYPES = [
- "ADDED",
- "REMOVED",
- "MODIFIED",
- "TEMPORARY"
+ CHANGE_TYPE.ADDED,
+ CHANGE_TYPE.REMOVED,
+ CHANGE_TYPE.MODIFIED,
+ CHANGE_TYPE.TEMPORARY
]
from rest_framework import serializers
from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
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
]
from rest_framework import serializers
from resource_handle import ResourceHandleSerializer
+from lcm.nf.const import CHANGE_TYPE
CHANGE_TYPES = [
- "ADDED",
- "REMOVED",
- "MODIFIED",
- "TEMPORARY"
+ CHANGE_TYPE.ADDED,
+ CHANGE_TYPE.REMOVED,
+ CHANGE_TYPE.MODIFIED,
+ CHANGE_TYPE.TEMPORARY
]
# 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
-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.notificationsutil import NotificationsUtil\r
from lcm.pub.utils.timeutil import now_time\r
from lcm.pub.vimapi import api\r
\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
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
- 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
- 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_post_notification.return_value = None\r
req_data = {\r
"changeStateTo": "STARTED"\r
}\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
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
- 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
- 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_post_notification.return_value = None\r
req_data = {\r
"changeStateTo": "STOPPED"\r
}\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.notificationsutil import NotificationsUtil\r
from lcm.pub.vimapi import api\r
\r
\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
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
}\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
- 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_post_notification.return_value = None\r
data = {\r
"terminationType": "FORCEFUL",\r
"gracefulTerminationTimeout": 120\r
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)
'notificationStatus': 'RESULT',
'operationState': 'COMPLETED',
'vnfInstanceId': nfinstid,
- 'operation': 'INSTANTIATE',
+ 'operation': operation,
'isAutomaticInvocation': False,
'vnfLcmOpOccId': jobid,
'affectedVnfcs': affected_vnfcs,