Merge lp:~soren/nova/lp668229 into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Vish Ishaya
Approved revision: 391
Merged at revision: 394
Proposed branch: lp:~soren/nova/lp668229
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 14 lines (+2/-2)
1 file modified
nova/utils.py (+2/-2)
To merge this branch: bzr merge lp:~soren/nova/lp668229
Reviewer Review Type Date Requested Status
Vish Ishaya (community) Approve
Devin Carlen (community) Approve
Review via email: mp+39968@code.launchpad.net

Description of the change

Change socket type in nova.utils.get_my_ip() to SOCK_DGRAM. This way, we don't actually have to set up a connection.
Also, change the destination host to an IP (chose one of Google's DNS's at random) rather than a hostname, so we avoid doing a DNS lookup.

To post a comment you must log in.
Revision history for this message
Dave Walker (davewalker) wrote :

Works for me... testing in a closed environment, and one with misleading /etc/hosts (which caused issue with another approach). Not tried against a skewed routing table, but that seems an unfair experiment.

Revision history for this message
Thierry Carrez (ttx) wrote :

Hmm, except that 8.8.8.8 (being a DNS server) doesn't answer on port 80 ?

Revision history for this message
Dave Walker (davewalker) wrote :

@ttx, The switch to UDP means no connection is actually made, as no datagrams are sent. So the port is only required for generating the essentially unused socket, for gathering information from the OS.

Revision history for this message
Devin Carlen (devcamcar) wrote :

approve, this has bitten me before :)

review: Approve
Revision history for this message
Vish Ishaya (vishvananda) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/utils.py'
2--- nova/utils.py 2010-10-26 22:37:32 +0000
3+++ nova/utils.py 2010-11-03 14:08:07 +0000
4@@ -154,8 +154,8 @@
5 if getattr(FLAGS, 'fake_tests', None):
6 return '127.0.0.1'
7 try:
8- csock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
9- csock.connect(('www.google.com', 80))
10+ csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
11+ csock.connect(('8.8.8.8', 80))
12 (addr, port) = csock.getsockname()
13 csock.close()
14 return addr