1. fix the url of links in VNF
[modeling/etsicatalog.git] / catalog / packages / biz / notificationsutil.py
index a18c4b3..4b8f736 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import json
 import logging
+import traceback
 import uuid
+
 import requests
-import json
-from rest_framework import status
+from django.db.models import Q
 from requests.auth import HTTPBasicAuth
-from catalog.packages import const
-from catalog.pub.database.models import VnfPackageModel, VnfPkgSubscriptionModel, NsdmSubscriptionModel
+from rest_framework import status
+
 import catalog.pub.utils.timeutil
-from catalog.pub.utils.values import remove_none_key
-from catalog.pub.config import config as pub_config
-import traceback
-from django.db.models import Q
+from catalog.packages import const
 from catalog.packages.serializers.vnf_pkg_notifications import PkgChangeNotificationSerializer, \
     PkgOnboardingNotificationSerializer
+from catalog.pub.config import config as pub_config
+from catalog.pub.database.models import VnfPackageModel, VnfPkgSubscriptionModel, NsdmSubscriptionModel
+from catalog.pub.utils.values import remove_none_key
 
 logger = logging.getLogger(__name__)
 
@@ -87,8 +89,13 @@ class NotificationsUtil(object):
                     params = auth_info.get("paramsBasic", {})
                     username = params.get("userName")
                     password = params.get("password")
-                    resp = requests.post(callbackuri, data=notification, headers={'Connection': 'close'},
-                                         auth=HTTPBasicAuth(username, password))
+                    resp = requests.post(callbackuri,
+                                         data=json.dumps(notification),
+                                         headers={'Connection': 'close',
+                                                  'content-type': 'application/json',
+                                                  'accept': 'application/json'},
+                                         auth=HTTPBasicAuth(username, password),
+                                         verify=False)
                 elif const.OAUTH2_CLIENT_CREDENTIALS in auth_info.get("authType", ''):
                     # todo
                     pass
@@ -96,11 +103,17 @@ class NotificationsUtil(object):
                     # todo
                     pass
             else:
-                resp = requests.post(callbackuri, data=notification, headers={'Connection': 'close'})
-            if resp.status_code != status.HTTP_204_NO_CONTENT:
-                logger.error("Sending notification to %s failed: %s" % (callbackuri, resp.text))
-            else:
+                resp = requests.post(callbackuri,
+                                     data=json.dumps(notification),
+                                     headers={'Connection': 'close',
+                                              'content-type': 'application/json',
+                                              'accept': 'application/json'},
+                                     verify=False)
+
+            if resp.status_code == status.HTTP_204_NO_CONTENT:
                 logger.info("Sending notification to %s successfully.", callbackuri)
+            else:
+                logger.error("Sending notification to %s failed: %s" % (callbackuri, resp))
         except:
             logger.error("Post notification failed.")
             logger.error(traceback.format_exc())