Fix finger gateway testing

With fast test nodes it is possible for finger gateway testing to start
a gateway then attempt to use it before the gateway has registered its
proper port. When this happens we attempt to connect to port 0 as a
client which isn't valid and that fails with this exception:

  DEBUG    Source (us-west) and worker (eu-central) zone are different, routing via localhost:0
  ERROR    Finger request handling exception (localhost:0):
  Traceback (most recent call last):
    File "/home/zuul/src/opendev.org/zuul/zuul/zuul/lib/fingergw.py", line 106, in handle
      self._fingerClient(server, port, build_uuid, use_ssl)
    File "/home/zuul/src/opendev.org/zuul/zuul/tests/unit/test_streaming.py", line 745, in _fingerClient
      super()._fingerClient(server, port, build_uuid, use_ssl)
    File "/home/zuul/src/opendev.org/zuul/zuul/zuul/lib/fingergw.py", line 72, in _fingerClient
      with socket.create_connection((server, port), timeout=10) as s:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.12/socket.py", line 852, in create_connection
      raise exceptions[0]
    File "/usr/lib/python3.12/socket.py", line 837, in create_connection
      sock.connect(sa)
  ConnectionRefusedError: [Errno 111] Connection refused

We can fix this by waiting for the gateway to register a valid port
before we consider the gateway valid.

Change-Id: Ife4ec07cc060631982ee2b0fca8ed933ad0200ea
This commit is contained in:
Clark Boylan
2025-03-26 18:05:49 -07:00
parent ee43cdb812
commit 91361a6825

View File

@ -226,7 +226,9 @@ class TestStreamingBase(tests.base.AnsibleZuulTestCase):
found = False
for gw in self.scheds.first.sched.component_registry.\
all('fingergw'):
if gw.zone == zone:
if gw.zone == zone and gw.public_port != 0:
# We need to wait for the component to be registered
# and for it to be listening on a valid port.
found = True
break
if found: