Skip to content

Commit

Permalink
fix: Don't log error in wait_for_url (#5972)
Browse files Browse the repository at this point in the history
There are use cases where we may want to recover or not treat a failure
of this function as an error. This change lets the caller decide what
to do.

Logging was added to callsites that didn't already have it.

Fixes GH-5971
  • Loading branch information
TheRealFalcon authored Jan 14, 2025
1 parent 0547349 commit 4ee6539
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions cloudinit/sources/DataSourceEc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def _maybe_fetch_api_token(self, mdurls):

# If we get here, then wait_for_url timed out, waiting for IMDS
# or the IMDS HTTP endpoint is disabled
LOG.error("Unable to get response from urls: %s", urls)
return None

def wait_for_metadata_service(self):
Expand Down
1 change: 1 addition & 0 deletions cloudinit/sources/DataSourceExoscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def crawl_metadata(self):
metadata_ready = self.wait_for_metadata_service()

if not metadata_ready:
LOG.error("Unable to get response from metadata service")
return {}

return read_metadata(
Expand Down
1 change: 0 additions & 1 deletion cloudinit/url_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,6 @@ def read_url_parallel(
# We've already exceeded our max_wait. Time to bail.
break

LOG.error("Timed out, no response from urls: %s", urls)
return False, None


Expand Down
6 changes: 1 addition & 5 deletions tests/unittests/test_url_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pylint: disable=attribute-defined-outside-init

import logging
import re
from functools import partial
from threading import Event
from time import process_time
Expand Down Expand Up @@ -733,7 +732,7 @@ def test_order(self, addresses, expected_address_index, response):
assert response.encode() == response_contents

@responses.activate
def test_timeout(self, caplog):
def test_timeout(self):
"""If no endpoint responds in time, expect no response"""

self.event.clear()
Expand Down Expand Up @@ -761,9 +760,6 @@ def test_timeout(self, caplog):
self.event.set()
assert not url
assert not response_contents
assert re.search(
r"open 'https:\/\/sleep1\/'.*Timed out", caplog.text, re.DOTALL
)

def test_explicit_arguments(self, retry_mocks):
"""Ensure that explicit arguments are respected"""
Expand Down

0 comments on commit 4ee6539

Please sign in to comment.