try:
instance = RgwClient.admin_instance()
# Check if the service is online.
- if not instance.is_service_online():
+ try:
+ is_online = instance.is_service_online()
+ except RequestException as e:
+ # Drop this instance because the RGW client seems not to
+ # exist anymore (maybe removed via orchestrator). Removing
+ # the instance from the cache will result in the correct
+ # error message next time when the backend tries to
+ # establish a new connection (-> 'No RGW found' instead
+ # of 'RGW REST API failed request ...').
+ # Note, this only applies to auto-detected RGW clients.
+ RgwClient.drop_instance(instance.userid)
+ raise e
+ if not is_online:
msg = 'Failed to connect to the Object Gateway\'s Admin Ops API.'
raise RequestException(msg)
# Ensure the API user ID is known by the RGW.
addr = _parse_addr(daemon['addr'])
port, ssl = _parse_frontend_config(daemon['metadata']['frontend_config#0'])
+ logger.info('Auto-detected RGW configuration: addr=%s, port=%d, ssl=%s',
+ addr, port, str(ssl))
+
return addr, port, ssl
# Discard all cached instances if any rgw setting has changed
if RgwClient._rgw_settings_snapshot != RgwClient._rgw_settings():
RgwClient._rgw_settings_snapshot = RgwClient._rgw_settings()
- RgwClient._user_instances.clear()
+ RgwClient.drop_instance()
if not RgwClient._user_instances:
RgwClient._load_settings()
def admin_instance():
return RgwClient.instance(RgwClient._SYSTEM_USERID)
+ @staticmethod
+ def drop_instance(userid=None):
+ """
+ Drop a cached instance by name or all.
+ """
+ if userid:
+ RgwClient._user_instances.pop(userid, None)
+ else:
+ RgwClient._user_instances.clear()
+
def _reset_login(self):
if self.userid != RgwClient._SYSTEM_USERID:
logger.info("Fetching new keys for user: %s", self.userid)