From a950cff842896b4a435fb17a5e6ffa3c40c2c46d Mon Sep 17 00:00:00 2001 From: fujinhua Date: Wed, 24 Apr 2019 13:56:39 +0800 Subject: Refactor codes for notification Change-Id: I9179c2dc107143b67acd398f1773718c78c5eedc Issue-ID: VFC-1306 Signed-off-by: fujinhua --- lcm/lcm/pub/utils/notificationsutil.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lcm') diff --git a/lcm/lcm/pub/utils/notificationsutil.py b/lcm/lcm/pub/utils/notificationsutil.py index 444e8071..0a0e1f2d 100644 --- a/lcm/lcm/pub/utils/notificationsutil.py +++ b/lcm/lcm/pub/utils/notificationsutil.py @@ -56,25 +56,27 @@ class NotificationsUtil(object): for subscription in subscriptions: # set subscription id notification["subscriptionId"] = subscription.subscription_id - notification['_links']['subscription'] = {'href': '/api/vnflcm/v1/subscriptions/%s' % subscription.subscription_id} + notification['_links']['subscription'] = { + 'href': '/api/vnflcm/v1/subscriptions/%s' % subscription.subscription_id + } callbackUri = subscription.callback_uri auth_info = json.loads(subscription.auth_info) - if auth_info["authType"] == const.OAUTH2_CLIENT_CREDENTIALS: - pass - try: - self.post_notification(callbackUri, auth_info, notification) - except Exception as e: - logger.error("Failed to post notification: %s", e.message) + if auth_info["authType"] != const.OAUTH2_CLIENT_CREDENTIALS: + try: + self.post_notification(callbackUri, auth_info, notification) + except Exception as e: + logger.error("Failed to post notification: %s", e.message) 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("Unable to send the notification to %s, due to %s" % (callbackUri, resp.text)) - return + raise Exception("Notify %s failed: %s" % (callbackUri, resp.text)) def set_affected_vnfcs(affected_vnfcs, nfinstid, changetype): -- cgit 1.2.3-korg