Closed Bug 1160094 Opened 5 years ago Closed 5 years ago

[moznetwork] Attempt to pick most suitable IP when multiple are associated with the hostname

Categories

(Testing :: Mozbase, defect)

defect
Not set

Tracking

(firefox40 affected, firefox41 fixed)

RESOLVED FIXED
mozilla41
Tracking Status
firefox40 --- affected
firefox41 --- fixed

People

(Reporter: davehunt, Assigned: davehunt)

References

Details

Attachments

(1 file)

Martijn recently reported in bug 1154784 that moznetwork had selected a vmnet interface address. After some investigation it turns out that we're using socket.gethostbyname [1] to determine the IP address of the host, however this will return a single IP even if there are multiple associated with the host.

Instead we should use socket.gethostbyname_ex [2] and only select the IP if there is only one returned. If there are multiple we should allow moznetwork to try preexisting methods of returning the most suitable IP address.

[1] https://docs.python.org/2/library/socket.html#socket.gethostbyname
[2] https://docs.python.org/2/library/socket.html#socket.gethostbyname_ex
Note that this depends on the patches in bug 1160090 and bug 1160087. I was able to replicate the issue with moznetwork returning an unsuitable IP:

$ moznetwork --log-mach-level=DEBUG
 0:00.00 LOG: MainThread moznetwork DEBUG Retrieving IP for Daves-MacBook-Pro.local
 0:00.57 LOG: MainThread moznetwork DEBUG Multiple addresses found: ['192.168.38.1', '192.168.142.1', '192.168.1.10']
 0:00.57 LOG: MainThread moznetwork DEBUG Parsing ifconfig
 0:00.58 LOG: MainThread moznetwork DEBUG Default interface: [en0] 192.168.1.10
 0:00.58 LOG: MainThread moznetwork INFO IP address: 192.168.1.10

In the above example moznetwork would return 192.168.38.1 without the patch, which is a vmnet interface on my machine.
Attachment #8599792 - Flags: review?(wlachance)
Comment on attachment 8599792 [details] [diff] [review]
Ignore multiple IPs for hostname. v1.0

Review of attachment 8599792 [details] [diff] [review]:
-----------------------------------------------------------------

Looks reasonable, the only change I'd make would be to clarify the log message a bit.

::: testing/mozbase/moznetwork/moznetwork/moznetwork.py
@@ +120,5 @@
> +            ips = socket.gethostbyname_ex(hostname)[2]
> +        if len(ips) == 1:
> +            ip = ips[0]
> +        else:
> +            logger.debug('Multiple addresses found: %s' % ips)

Maybe add a note that we're falling back to parsing ifconfig or something here. It kind of looks like we're giving up just from the log message.
Attachment #8599792 - Flags: review?(wlachance) → review+
(In reply to William Lachance (:wlach) from comment #2)
> Comment on attachment 8599792 [details] [diff] [review]
> Ignore multiple IPs for hostname. v1.0
> 
> Maybe add a note that we're falling back to parsing ifconfig or something
> here. It kind of looks like we're giving up just from the log message.

The very next log message is either 'Parsing ifconfig' or 'Gathering interface list' so I think that makes it clear we're trying another method to retrieve the IP address.

Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=4c33de7df3ac
https://hg.mozilla.org/mozilla-central/rev/ad6016b26dbd
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
Depends on: 1163992
Blocks: 1175101
You need to log in before you can comment on or make changes to this bug.