X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fpub%2Futils%2Fnotificationsutil.py;h=8a38fd62c6eda49d1f7748ec50730ac38cf09f78;hb=f2e52aa4efb15e1f94506710528d6f47d21348d6;hp=0a0e1f2dbcb7cfa87e6e853064dd3eaf19104ce7;hpb=a950cff842896b4a435fb17a5e6ffa3c40c2c46d;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/pub/utils/notificationsutil.py b/lcm/lcm/pub/utils/notificationsutil.py index 0a0e1f2d..8a38fd62 100644 --- a/lcm/lcm/pub/utils/notificationsutil.py +++ b/lcm/lcm/pub/utils/notificationsutil.py @@ -22,31 +22,31 @@ from rest_framework import status from lcm.nf import const from lcm.pub.database.models import SubscriptionModel -from lcm.pub.database.models import ( - VmInstModel, NetworkInstModel, - PortInstModel, StorageInstModel, VNFCInstModel -) +from lcm.pub.database.models import VmInstModel +from lcm.pub.database.models import NetworkInstModel +from lcm.pub.database.models import PortInstModel +from lcm.pub.database.models import StorageInstModel +from lcm.pub.database.models import VNFCInstModel from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.enumutil import enum logger = logging.getLogger(__name__) -NOTIFY_TYPE = enum(lCM_OP_OCC="VnfLcmOperationOccurrenceNotification", - CREATION="VnfIdentifierCreationNotification", - DELETION="VnfIdentifierDeletionNotification") +NOTIFY_TYPE = enum( + lCM_OP_OCC="VnfLcmOperationOccurrenceNotification", + CREATION="VnfIdentifierCreationNotification", + DELETION="VnfIdentifierDeletionNotification" +) class NotificationsUtil(object): - def __init__(self): - pass - def send_notification(self, notification): logger.info("Send Notifications to the callbackUri") filters = { "operationState": "operation_states", "operation": "operation_types" } - subscriptions_filter = {v + "__contains": notification[k] for k, v in filters.iteritems()} + subscriptions_filter = {v + "__contains": notification[k] for k, v in list(filters.items())} subscriptions = SubscriptionModel.objects.filter(**subscriptions_filter) if not subscriptions.exists(): @@ -65,18 +65,20 @@ class NotificationsUtil(object): try: self.post_notification(callbackUri, auth_info, notification) except Exception as e: - logger.error("Failed to post notification: %s", e.message) + logger.error("Failed to post notification: %s", e.args[0]) def post_notification(self, callbackUri, auth_info, notification): params = auth_info.get("paramsBasic", {}) username = params.get("userName") password = params.get("password") logger.info("Sending notification to %s", callbackUri) - resp = requests.post(callbackUri, - data=notification, - auth=HTTPBasicAuth(username, password)) + resp = requests.post( + callbackUri, + data=notification, + auth=HTTPBasicAuth(username, password) + ) if resp.status_code != status.HTTP_204_NO_CONTENT: - raise Exception("Notify %s failed: %s" % (callbackUri, resp.text)) + logger.error("Notify %s failed: %s", callbackUri, resp.text) def set_affected_vnfcs(affected_vnfcs, nfinstid, changetype): @@ -136,7 +138,7 @@ def set_ext_connectivity(ext_connectivity, nfinstid): }, 'cpInstanceId': port.portid # TODO: port.cpinstanceid is not initiated when create port resource. }) - for network_id, ext_link_ports in ext_connectivity_map.items(): + for network_id, ext_link_ports in list(ext_connectivity_map.items()): networks = NetworkInstModel.objects.filter(networkid=network_id) net_name = networks[0].name if networks else network_id network_resource = { @@ -171,10 +173,9 @@ def set_affected_vss(affected_vss, nfinstid, changetype): def get_notification_status(operation_state): - notification_status = const.LCM_NOTIFICATION_STATUS.START - if operation_state in const.RESULT_RANGE: - notification_status = const.LCM_NOTIFICATION_STATUS.RESULT - return notification_status + if operation_state == const.OPERATION_STATE_TYPE.STARTING: + return const.LCM_NOTIFICATION_STATUS.START + return const.LCM_NOTIFICATION_STATUS.RESULT def prepare_notification(nfinstid, jobid, operation, operation_state): @@ -208,10 +209,12 @@ def prepare_notification(nfinstid, jobid, operation, operation_state): def prepare_notification_data(nfinstid, jobid, changetype, operation): - data = prepare_notification(nfinstid=nfinstid, - jobid=jobid, - operation=operation, - operation_state=const.OPERATION_STATE_TYPE.COMPLETED) + data = prepare_notification( + nfinstid=nfinstid, + jobid=jobid, + operation=operation, + operation_state=const.OPERATION_STATE_TYPE.COMPLETED + ) set_affected_vnfcs(data['affectedVnfcs'], nfinstid, changetype) set_affected_vls(data['affectedVirtualLinks'], nfinstid, changetype)