X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fpub%2Futils%2Fnotificationsutil.py;h=6b7c791f6192bcd281773b85ad008fc8e08785db;hb=2cd885c6de901784dfdfcf50a8ca1316c3daa029;hp=2eb820fe0004260eef63a924bb8a8f6c119bdcca;hpb=d36b8189117b5b6832460bc8ae413242ce4c107f;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/pub/utils/notificationsutil.py b/lcm/lcm/pub/utils/notificationsutil.py index 2eb820fe..6b7c791f 100644 --- a/lcm/lcm/pub/utils/notificationsutil.py +++ b/lcm/lcm/pub/utils/notificationsutil.py @@ -22,24 +22,24 @@ 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 = { @@ -61,7 +61,7 @@ class NotificationsUtil(object): } callbackUri = subscription.callback_uri auth_info = json.loads(subscription.auth_info) - if auth_info["authType"] != const.OAUTH2_CLIENT_CREDENTIALS: + if const.BASIC in auth_info["authType"]: try: self.post_notification(callbackUri, auth_info, notification) except Exception as e: @@ -72,11 +72,13 @@ class NotificationsUtil(object): 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): @@ -207,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)