Use err.errno to access errno for socket errors

Otherwise, you may see errors like

    TypeError: 'OSError' object is not subscriptable

Change-Id: I2aa952d6e323f2f30ab915c3fbf609c651ed1fe9
This commit is contained in:
Tim Burke 2020-09-25 09:46:52 -07:00
parent c008250f6e
commit a78ddafdec
2 changed files with 5 additions and 3 deletions

View File

@ -263,7 +263,7 @@ def get_socket(conf, default_port):
backlog=conf.backlog,
family=address_family)
except socket.error as err:
if err.args[0] != errno.EADDRINUSE:
if err.errno != errno.EADDRINUSE:
raise
eventlet.sleep(0.1)
if not sock:
@ -584,7 +584,7 @@ class Server(object):
keepalive=cfg.CONF.eventlet_opts.wsgi_keep_alive,
socket_timeout=socket_timeout)
except socket.error as err:
if err[0] != errno.EINVAL:
if err.errno != errno.EINVAL:
raise
self.pool.waitall()

View File

@ -441,10 +441,12 @@ class GetSocketTestCase(common.HeatTestCase):
wsgi.cfg.CONF.heat_api, 1234)
def test_get_socket_with_bind_problems(self):
err = wsgi.socket.error(
socket.errno.EADDRINUSE, 'Address already in use')
self.useFixture(fixtures.MonkeyPatch(
'heat.common.wsgi.eventlet.listen',
mock.Mock(side_effect=(
[wsgi.socket.error(socket.errno.EADDRINUSE)] * 3 + [None]))))
[err] * 3 + [None]))))
self.useFixture(fixtures.MonkeyPatch(
'heat.common.wsgi.ssl.wrap_socket',
lambda *x, **y: None))