From a5bb2dc260dd68aafca5e867f9f0bc4ca3a18af8 Mon Sep 17 00:00:00 2001 From: Cole Walker Date: Thu, 19 Dec 2024 16:06:14 -0500 Subject: [PATCH] Fix for rabbitmq address format A package update sometime after the notificationclient 2.3.0 release has changed the behaviour of oslo_messaging. In rpc_helper.py get_transport(), the oslo_messaging.get_rpc_transport() now errors out when passed an ipv4 address wrapped in "[]". This was not previously the case. Updated the parsing for the broker_host variable so that it is only wrapped in brackets when it is ipv6. Testing: Pass: Verify operation on ipv4 systems Pass: Verify operation on ipv6 systems Closes-bug: 2093125 Signed-off-by: Cole Walker Change-Id: I7211d0d4c2769547233ecc1dae0416327a19c32c --- .../services/broker_connection_manager.py | 15 +++++++++++++-- .../notificationclientsdk/services/ptp.py | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/broker_connection_manager.py b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/broker_connection_manager.py index 747a4ac..6ab84be 100644 --- a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/broker_connection_manager.py +++ b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/broker_connection_manager.py @@ -1,9 +1,10 @@ # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2025 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # +import ipaddress import time import oslo_messaging import logging @@ -13,6 +14,7 @@ from notificationclientsdk.common.helpers import log_helper from notificationclientsdk.client.locationservice import LocationServiceClient from notificationclientsdk.client.notificationservice \ import NotificationServiceClient +from notificationclientsdk.exception import client_exception LOG = logging.getLogger(__name__) log_helper.config_logger(LOG) @@ -246,7 +248,16 @@ class BrokerConnectionManager: # special case: if monitor all node, then use the same broker as # locationservice return self.location_watcher - broker_host = "[{0}]".format(broker_pod_ip) + try: + check_pod_ip = ipaddress.ip_address(broker_pod_ip) + if check_pod_ip.version == 4: + broker_host = "{0}".format(broker_pod_ip) + else: #IPv6 + broker_host = "[{0}]".format(broker_pod_ip) + except ValueError as err: + LOG.error("%s: broker_pod_ip %s is not a valid address" % (err, broker_pod_ip)) + raise client_exception.InvalidEndpoint(broker_name) + broker_transport_endpoint = "rabbit://{0}:{1}@{2}:{3}".format( self.shared_broker_context['NOTIFICATION_BROKER_USER'], self.shared_broker_context['NOTIFICATION_BROKER_PASS'], diff --git a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/ptp.py b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/ptp.py index edf289b..45faaac 100644 --- a/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/ptp.py +++ b/notificationclient-base/docker/notificationclient-sidecar/notificationclientsdk/services/ptp.py @@ -1,9 +1,10 @@ # -# Copyright (c) 2021-2024 Wind River Systems, Inc. +# Copyright (c) 2021-2025 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # +import ipaddress import json import logging from datetime import datetime @@ -99,7 +100,16 @@ class PtpService(object): def _query(self, broker_name, broker_pod_ip, resource_address=None, optional=None): - broker_host = "[{0}]".format(broker_pod_ip) + try: + check_pod_ip = ipaddress.ip_address(broker_pod_ip) + if check_pod_ip.version == 4: + broker_host = "{0}".format(broker_pod_ip) + else: #IPv6 + broker_host = "[{0}]".format(broker_pod_ip) + except ValueError as err: + LOG.error("%s: broker_pod_ip %s is not a valid address" % (err, broker_pod_ip)) + raise client_exception.InvalidEndpoint(broker_name) + broker_transport_endpoint = "rabbit://{0}:{1}@{2}:{3}".format( self.daemon_control.daemon_context['NOTIFICATION_BROKER_USER'], self.daemon_control.daemon_context['NOTIFICATION_BROKER_PASS'],