summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-24 13:56:39 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-24 15:42:36 +0800
commita950cff842896b4a435fb17a5e6ffa3c40c2c46d (patch)
tree252e04a9bb06711bf75f7b157eb3b40c4631f669 /lcm
parent4dfb5277d5e59a3fd92a032b409eed0dacdff874 (diff)
Refactor codes for notification
Change-Id: I9179c2dc107143b67acd398f1773718c78c5eedc Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/pub/utils/notificationsutil.py22
1 files changed, 12 insertions, 10 deletions
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):