From: Zhang Rong(Jon) Date: Wed, 24 May 2023 07:23:03 +0000 (+0800) Subject: Fix the wrong format of registration and subscription with SMO X-Git-Tag: 2.0.2~5 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=108d56bb68007e4f71079ebd36d109fa70ee3fb3;p=pti%2Fo2.git Fix the wrong format of registration and subscription with SMO It should be JSON, not string Issue-ID: INF-419 Signed-off-by: Zhang Rong(Jon) Change-Id: I22873f03161dc1f86f0fc707ae3d3080e696bbb5 --- diff --git a/o2common/service/command/handler.py b/o2common/service/command/handler.py index 624781a..aff9b78 100644 --- a/o2common/service/command/handler.py +++ b/o2common/service/command/handler.py @@ -14,7 +14,6 @@ import os import requests -import json import http.client import ssl from requests_oauthlib import OAuth2Session @@ -147,8 +146,7 @@ class SMOClient: for _ in range(retries): try: - response = self.session.post( - url, data=json.dumps(data)) + response = self.session.post(url, json=data) response.raise_for_status() return self.handle_post_data(response) except (SSLError, RequestException) as e: diff --git a/o2ims/service/command/notify_alarm_handler.py b/o2ims/service/command/notify_alarm_handler.py index 81cbeaa..b630d1e 100644 --- a/o2ims/service/command/notify_alarm_handler.py +++ b/o2ims/service/command/notify_alarm_handler.py @@ -93,9 +93,7 @@ def callback_smo(notifications: AbstractNotifications, sub: AlarmSubscription, 'perceivedSeverity': alarm_data['perceivedSeverity'], 'extensions': json.loads(alarm_data['extensions']) } - # logger.warning(callback) - callback_data = json.dumps(callback) logger.info('callback URL: {}'.format(sub_data['callback'])) - logger.debug('callback data: {}'.format(callback_data)) + logger.debug('callback data: {}'.format(json.dumps(callback))) - return notifications.send(sub_data['callback'], callback_data) + return notifications.send(sub_data['callback'], callback) diff --git a/o2ims/service/command/notify_handler.py b/o2ims/service/command/notify_handler.py index 19363f9..0b2ce58 100644 --- a/o2ims/service/command/notify_handler.py +++ b/o2ims/service/command/notify_handler.py @@ -295,11 +295,10 @@ def callback_smo(notifications: AbstractNotifications, sub: Subscription, callback['postObjectState'] = json.dumps(obj_dict) if msg.notificationEventType == NotificationEventEnum.DELETE: callback.pop('objectRef') - callback_data = json.dumps(callback) logger.info('callback URL: {}'.format(sub_data['callback'])) - logger.debug('callback data: {}'.format(callback_data)) + logger.debug('callback data: {}'.format(json.dumps(callback))) - return notifications.send(sub_data['callback'], callback_data) + return notifications.send(sub_data['callback'], callback) # Call SMO through the SMO callback url # o = urlparse(sub_data['callback']) diff --git a/o2ims/service/command/registration_handler.py b/o2ims/service/command/registration_handler.py index 8531a2d..e6f4904 100644 --- a/o2ims/service/command/registration_handler.py +++ b/o2ims/service/command/registration_handler.py @@ -129,12 +129,12 @@ def call_smo(notifications: AbstractNotifications, reg_data: dict): 'smo_token_algo': 'RS256' } - callback_data = json.dumps({ + callback = { 'globalCloudId': reg_data['globalCloudId'], 'oCloudId': reg_data['oCloudId'], 'IMS_EP': config.get_api_url(), 'smo_token_data': smo_token_info - }) + } logger.info('callback URL: {}'.format(conf.DEFAULT.smo_register_url)) - logger.debug('callback data: {}'.format(callback_data)) - return notifications.send(conf.DEFAULT.smo_register_url, callback_data) + logger.debug('callback data: {}'.format(json.dumps(callback))) + return notifications.send(conf.DEFAULT.smo_register_url, callback)