[objectstore] Refactor RGW endpoint lookup to consolidate logic

The changes refactor the _get_endpoint method in the RGW pollster to
consolidate duplicate endpoint lookup logic and add explicit error
handling when required config is missing.

Consolidate the two separate conditional blocks for endpoint lookup
into a single block that handles both service_name and service_type
configurations. This simplifies the code and eliminates duplication.

Add explicit RuntimeError when neither rgw_client.rgw_service_name
nor service_types.radosgw is configured, providing a clearer error
message instead of silently failing.

Depends-On: https://review.opendev.org/c/openstack/telemetry-tempest-plugin/+/978293
Change-Id: Ic644c481e2bdf56e934b1c0e957b4e2902ba1504
Signed-off-by: Emma Foley <efoley@redhat.com>
This commit is contained in:
Emma Foley
2026-01-15 07:52:39 -05:00
parent d1c2fd8a8c
commit d3c8ae0842

View File

@@ -74,27 +74,22 @@ class _Base(plugin_base.PollsterBase):
def _get_endpoint(conf, ksclient):
# we store the endpoint as a base class attribute, so keystone is
# only ever called once.
if _Base._ENDPOINT is None and conf.rgw_client.rgw_service_name:
if _Base._ENDPOINT is None:
service_type = conf.service_types.radosgw
service_name = conf.rgw_client.rgw_service_name
if service_type is None and service_name is None:
raise RuntimeError(
"Required config not found, need either "
"rgw_client.rgw_service_name or service_types.radosgw")
try:
creds = conf.service_credentials
# Use the service_name to target the endpoint.
# There are cases where both 'radosgw' and 'swift' are used.
rgw_url = keystone_client.url_for(
ksclient,
service_name=conf.rgw_client.rgw_service_name,
interface=creds.interface,
region_name=creds.region_name)
_Base._ENDPOINT = urlparse.urljoin(rgw_url, '/admin')
except exceptions.EndpointNotFound:
LOG.debug("Radosgw endpoint not found")
elif _Base._ENDPOINT is None and conf.service_types.radosgw:
try:
creds = conf.service_credentials
rgw_url = keystone_client.url_for(
ksclient,
service_type=conf.service_types.radosgw,
interface=creds.interface,
region_name=creds.region_name)
service_type=service_type, service_name=service_name,
interface=conf.service_credentials.interface,
region_name=conf.service_credentials.region_name)
_Base._ENDPOINT = urlparse.urljoin(rgw_url, '/admin')
except exceptions.EndpointNotFound:
LOG.debug("Radosgw endpoint not found")