Merge "py3: Fix exception types" into f/centos8

This commit is contained in:
Zuul 2021-07-29 13:22:55 +00:00 committed by Gerrit Code Review
commit 4b2e6866f2
1 changed files with 17 additions and 4 deletions

View File

@ -488,7 +488,7 @@ class Connection(object):
"%(hostname)s:%(port)d") % params) "%(hostname)s:%(port)d") % params)
try: try:
self.connection.release() self.connection.release()
except self.connection_errors: except tuple(self.connection_errors): # pylint: disable=catching-non-exception
pass pass
# Setting this in case the next statement fails, though # Setting this in case the next statement fails, though
# it shouldn't be doing any network operations, yet. # it shouldn't be doing any network operations, yet.
@ -523,11 +523,14 @@ class Connection(object):
while True: while True:
params = self.params_list[attempt % len(self.params_list)] params = self.params_list[attempt % len(self.params_list)]
attempt += 1 attempt += 1
e = None
try: try:
self._connect(params) self._connect(params)
return return
except (IOError, self.connection_errors) as e: except IOError as ex:
pass e = ex
except tuple(self.connection_errors) as ex: # pylint: disable=catching-non-exception
e = ex
except Exception as e: except Exception as e:
# NOTE(comstud): Unfortunately it's possible for amqplib # NOTE(comstud): Unfortunately it's possible for amqplib
# to return an error not covered by its transport # to return an error not covered by its transport
@ -535,6 +538,7 @@ class Connection(object):
# a protocol response. (See paste link in LP888621) # a protocol response. (See paste link in LP888621)
# So, we check all exceptions for 'timeout' in them # So, we check all exceptions for 'timeout' in them
# and try to reconnect in this case. # and try to reconnect in this case.
e = ex
if 'timeout' not in str(e): if 'timeout' not in str(e):
raise raise
@ -569,7 +573,16 @@ class Connection(object):
while True: while True:
try: try:
return method(*args, **kwargs) return method(*args, **kwargs)
except (self.channel_errors, self.connection_errors, socket.timeout, IOError) as e: except tuple(self.channel_errors) as e: # pylint: disable=catching-non-exception
if error_callback:
error_callback(e)
except tuple(self.connection_errors) as e: # pylint: disable=catching-non-exception
if error_callback:
error_callback(e)
except socket.timeout as e:
if error_callback:
error_callback(e)
except IOError as e:
if error_callback: if error_callback:
error_callback(e) error_callback(e)
except Exception as e: except Exception as e: