Fix ptp-notification version 1 client subscription

Revert the notify code only for version 1 clients.

As a initial state notification is sent to test new
subscription's endpoint URI, fixing the notification
message also fixed the subscription request failure.

Test Plan:
PASS: Build the notificationclient-base container (sidecar)
PASS: Deployed both v1 and v2 clients and tested the
      follwing in both clients:
PASS: Executed a subscription request.
PASS: Checked the initial state notifcation message.
PASS: Executed a list current subscription request.
PASS: Executed a get current state request.
PASS: Checked event notification when a state changes.
PASS: Executed a delete subscription request.

Closes-bug: 2011737

Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
Change-Id: I725a986efff008f498844d698ddd88b846b0e84e
This commit is contained in:
Andre Mauricio Zelak 2023-03-15 18:24:38 -03:00
parent 0dc361b093
commit 3d8245ec08

@ -25,12 +25,21 @@ def notify(subscriptioninfo, notification, timeout=2, retry=3):
try:
headers = {'Content-Type': 'application/json'}
url = subscriptioninfo.EndpointUri
for item in notification:
data = format_notification_data(subscriptioninfo, {item: notification[item]})
if 'ResourceType' in notification:
# version 1
data = format_notification_data(subscriptioninfo, notification)
data = json.dumps(data)
response = requests.post(url, data=data, headers=headers,
timeout=timeout)
response.raise_for_status()
else:
# version 2
for item in notification:
data = format_notification_data(subscriptioninfo, {item: notification[item]})
data = json.dumps(data)
response = requests.post(url, data=data, headers=headers,
timeout=timeout)
response.raise_for_status()
result = True
return response
except client_exception.InvalidResource as ex: