Skip to content

Commit

Permalink
test(ec2): fix mocking with responses==0.9.0 (focal) (#5163)
Browse files Browse the repository at this point in the history
  • Loading branch information
aciba90 committed Apr 9, 2024
1 parent d075d43 commit 596266a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/unittests/sources/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,12 @@ def test_network_config_cached_property_refreshed_on_upgrade(

def _remove_md(resp_list: List) -> None:
for index, url in enumerate(resp_list):
if url["url"].startswith(
try:
url = url.url
except AttributeError:
# Can be removed when Bionic is EOL
url = url["url"]
if url.startswith(
"http://169.254.169.254/2009-04-04/meta-data/"
):
del resp_list[index]
Expand All @@ -615,6 +620,11 @@ def _remove_md(resp_list: List) -> None:
elif hasattr(responses, "_matches"):
# Can be removed when Focal is EOL
_remove_md(responses._matches)
elif hasattr(responses, "_default_mock") and hasattr(
responses._default_mock, "_matches"
):
# Can be removed when Focal is EOL
_remove_md(responses._default_mock._matches)

# Provide new revision of metadata that contains network data
register_mock_metaserver(
Expand Down

0 comments on commit 596266a

Please sign in to comment.