Fix RabbitMQ endpoint
Only the IPv6 addresses must be enclosed in square brackets, the IPv4 adresses and hostname can't be enclosed. Test plan: Pass: Verify ptp-notification in IPv4 and IPv6 system. Pass: Verify ptp-notification operations (pull status, subscribe, list, delete) Pass: Verify both ptp-notification V1 and V2 operations Closes-bug: 2097136 Change-Id: I7792b2648bd609ca49fbec840eaf7e687ae25c7d Signed-off-by: Andre Mauricio Zelak <andre.zelak@windriver.com>
This commit is contained in:
parent
19841dd96f
commit
fc05f7fb44
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2023 Wind River Systems, Inc.
|
||||
# Copyright (c) 2023-2025 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
@ -18,10 +18,28 @@ import json
|
||||
import time
|
||||
import glob
|
||||
import re
|
||||
import ipaddress
|
||||
import oslo_messaging
|
||||
from oslo_config import cfg
|
||||
from trackingfunctionsdk.services.daemon import DaemonControl
|
||||
|
||||
def build_rabbitmq_endpoint(user, password, host, port):
|
||||
"""Build RabitMQ endpoint URL"""
|
||||
|
||||
"""Only IPv6 addresses are enclosed in square brackets."""
|
||||
# 'rabbit://admin:admin@127.0.0.1:5672/'
|
||||
# 'rabbit://admin:admin@registration.notification.svc.cluster.local:5672/'
|
||||
# 'rabbit://admin:admin@[::1]:5672/'
|
||||
endpoint_format = 'rabbit://{0}:{1}@{2}:{3}'
|
||||
try:
|
||||
ip = ipaddress.ip_address(host)
|
||||
if ip.version == 6:
|
||||
endpoint_format = 'rabbit://{0}:{1}@[{2}]:{3}'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return endpoint_format.format(user, password, host, port)
|
||||
|
||||
THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE", 'notification')
|
||||
THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME", 'controller-1')
|
||||
THIS_POD_IP = os.environ.get("THIS_POD_IP", '127.0.0.1')
|
||||
@ -30,14 +48,12 @@ REGISTRATION_PASS = os.environ.get("REGISTRATION_PASS", "admin")
|
||||
REGISTRATION_PORT = os.environ.get("REGISTRATION_PORT", "5672")
|
||||
REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST",
|
||||
'registration.notification.svc.cluster.local')
|
||||
# 'rabbit://admin:admin@[127.0.0.1]:5672/'
|
||||
# 'rabbit://admin:admin@[::1]:5672/'
|
||||
REGISTRATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@[{2}]:{3}'.format(
|
||||
REGISTRATION_TRANSPORT_ENDPOINT = build_rabbitmq_endpoint(
|
||||
REGISTRATION_USER, REGISTRATION_PASS, REGISTRATION_HOST, REGISTRATION_PORT)
|
||||
NOTIFICATION_BROKER_USER = os.environ.get("NOTIFICATIONSERVICE_USER", "admin")
|
||||
NOTIFICATION_BROKER_PASS = os.environ.get("NOTIFICATIONSERVICE_PASS", "admin")
|
||||
NOTIFICATION_BROKER_PORT = os.environ.get("NOTIFICATIONSERVICE_PORT", "5672")
|
||||
NOTIFICATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@[{2}]:{3}'.format(
|
||||
NOTIFICATION_TRANSPORT_ENDPOINT = build_rabbitmq_endpoint(
|
||||
NOTIFICATION_BROKER_USER, NOTIFICATION_BROKER_PASS, THIS_POD_IP, NOTIFICATION_BROKER_PORT)
|
||||
PTP_DEVICE_SIMULATED = os.environ.get("PTP_DEVICE_SIMULATED", False)
|
||||
PTP_HOLDOVER_SECONDS = os.environ.get("PTP_HOLDOVER_SECONDS", 30)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2021-2023 Wind River Systems, Inc.
|
||||
# Copyright (c) 2021-2025 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
@ -10,6 +10,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import ipaddress
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
@ -20,6 +21,23 @@ from trackingfunctionsdk.services.daemon import DaemonControl
|
||||
LOG = logging.getLogger(__name__)
|
||||
log_helper.config_logger(LOG)
|
||||
|
||||
def build_rabbitmq_endpoint(user, password, host, port):
|
||||
"""Build RabitMQ endpoint URL"""
|
||||
|
||||
"""Only IPv6 addresses are enclosed in square brackets."""
|
||||
# 'rabbit://admin:admin@127.0.0.1:5672/'
|
||||
# 'rabbit://admin:admin@registration.notification.svc.cluster.local:5672/'
|
||||
# 'rabbit://admin:admin@[::1]:5672/'
|
||||
endpoint_format = 'rabbit://{0}:{1}@{2}:{3}'
|
||||
try:
|
||||
ip = ipaddress.ip_address(host)
|
||||
if ip.version == 6:
|
||||
endpoint_format = 'rabbit://{0}:{1}@[{2}]:{3}'
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return endpoint_format.format(user, password, host, port)
|
||||
|
||||
THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE", 'notification')
|
||||
THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME", 'controller-0')
|
||||
THIS_POD_IP = os.environ.get("THIS_POD_IP", '127.0.0.1')
|
||||
@ -33,14 +51,14 @@ REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST", 'localhost')
|
||||
|
||||
# 'rabbit://admin:admin@[127.0.0.1]:5672/'
|
||||
# 'rabbit://admin:admin@[::1]:5672/'
|
||||
REGISTRATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@[{2}]:{3}'.format(
|
||||
REGISTRATION_TRANSPORT_ENDPOINT = build_rabbitmq_endpoint(
|
||||
REGISTRATION_USER, REGISTRATION_PASS, REGISTRATION_HOST, REGISTRATION_PORT)
|
||||
|
||||
NOTIFICATION_BROKER_USER = os.environ.get("NOTIFICATIONSERVICE_USER", "guest")
|
||||
NOTIFICATION_BROKER_PASS = os.environ.get("NOTIFICATIONSERVICE_PASS", "guest")
|
||||
NOTIFICATION_BROKER_PORT = os.environ.get("NOTIFICATIONSERVICE_PORT", "5672")
|
||||
|
||||
NOTIFICATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@[{2}]:{3}'.format(
|
||||
NOTIFICATION_TRANSPORT_ENDPOINT = build_rabbitmq_endpoint(
|
||||
NOTIFICATION_BROKER_USER, NOTIFICATION_BROKER_PASS, THIS_POD_IP,
|
||||
NOTIFICATION_BROKER_PORT)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2021-2024 Wind River Systems, Inc.
|
||||
# Copyright (c) 2021-2025 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
@ -89,9 +89,11 @@ class PtpWatcherDefault:
|
||||
self.node_name = self.daemon_context['THIS_NODE_NAME']
|
||||
self.namespace = self.daemon_context.get('THIS_NAMESPACE', 'notification')
|
||||
|
||||
broker_transport_endpoint = self.daemon_context['NOTIFICATION_TRANSPORT_ENDPOINT']
|
||||
broker_transport_endpoint = \
|
||||
self.daemon_context['NOTIFICATION_TRANSPORT_ENDPOINT']
|
||||
|
||||
registration_transport_endpoint = self.daemon_context['REGISTRATION_TRANSPORT_ENDPOINT']
|
||||
registration_transport_endpoint = \
|
||||
self.daemon_context['REGISTRATION_TRANSPORT_ENDPOINT']
|
||||
|
||||
self.broker_endpoint = RpcEndpointInfo(broker_transport_endpoint)
|
||||
self.registration_broker_endpoint = RpcEndpointInfo(registration_transport_endpoint)
|
||||
|
Loading…
x
Reference in New Issue
Block a user