Skip to content

do not attempt dns resolution on ip addresses#2040

Merged
holmanb merged 3 commits into
canonical:mainfrom
holmanb:holmanb/no-resolve-ips
Mar 14, 2023
Merged

do not attempt dns resolution on ip addresses#2040
holmanb merged 3 commits into
canonical:mainfrom
holmanb:holmanb/no-resolve-ips

Conversation

@holmanb
Copy link
Copy Markdown
Member

@holmanb holmanb commented Feb 27, 2023

util: Skip dns resolution check for ip addresses

A slight optimization in the default case.

Copy link
Copy Markdown
Collaborator

@igalic igalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@TheRealFalcon TheRealFalcon self-assigned this Mar 10, 2023
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good. I think we should probably add a mock to the unit test to ensure we're not attempting to resolve, but that's minor enough that I'm gonna approve anyway.

Comment thread tests/unittests/test_util.py Outdated
Therefore, the fast path checks if the address contains an IP and exits
early if the path is a valid IP.
"""
assert util.is_resolvable("http://169.254.169.254/")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We should probably add an is True to these asserts so we're more specific than just asserting truthiness.

Comment thread tests/unittests/test_util.py Outdated
early if the path is a valid IP.
"""
assert util.is_resolvable("http://169.254.169.254/")
assert util.is_resolvable("http://[fd00:ec2::254]/")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be checking that socket.getaddrinfo isn't called here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets used higher up in the function, but I can mock the global variable to skip that code.

@holmanb holmanb merged commit fc6c1d3 into canonical:main Mar 14, 2023
aale24 pushed a commit to aale24/cloud-init that referenced this pull request Feb 28, 2026
Building on the previous optimization in canonical#2040, add an additional
optimization to fail early when the hostname is not resolvable at all.
holmanb pushed a commit that referenced this pull request Mar 11, 2026
…le (#6772)

Building on the previous optimization in #2040, add an additional 
optimization to fail early when the hostname is not resolvable at all.
blackboxsw pushed a commit to blackboxsw/cloud-init that referenced this pull request Apr 13, 2026
…le (canonical#6772)

Building on the previous optimization in canonical#2040, add an additional 
optimization to fail early when the hostname is not resolvable at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants