devinstall_test: Use 10.0.2.2 as binhost's IP

Avoid a conflict between qemu's networking and the host's IP address
when the latter happens to be in the 10.0.2.* range. The dev_install
requests from the guest to, say 10.0.2.219, were handled by qemu itself
and not actually passed to the host.

Forcing the guest to send requests to 10.0.2.2 instead will now ensure
that it always points to the host.
https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29

Note: existing cros lint errors not fixed

BUG=chromium:808045
TEST=cros tryjob --swarming novato-release-tryjob
TEST=cros tryjob novato-release-tryjob
TEST=local test on novato image ./devmode-test/devinstall_test.py ...

Change-Id: I9d5873a4820c10156f7046e04b348b7561a9befd
Reviewed-on: https://chromium-review.googlesource.com/947042
Commit-Ready: Nicolas Norvez <norvez@chromium.org>
Tested-by: Nicolas Norvez <norvez@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/devmode-test/devinstall_test.py b/devmode-test/devinstall_test.py
index a294387..3eb9839 100755
--- a/devmode-test/devinstall_test.py
+++ b/devmode-test/devinstall_test.py
@@ -39,6 +39,14 @@
 
 class DevModeTest(object):
   """Wrapper for dev mode tests."""
+
+  # qemu hardcodes 10.0.2.2 as the host from the guest's point of view
+  # https://wiki.qemu.org/Documentation/Networking#User_Networking_.28SLIRP.29
+  # When the host's eth0 IP address is also 10.0.2.*, and the guest tries to
+  # access it, the requests will be handled by qemu and never be seen by the
+  # host. Instead, let the guest always connect to 10.0.2.2.
+  HOST_IP_ADDRESS = '10.0.2.2'
+
   def __init__(self, image_path, board, binhost):
     """Initializes DevModeTest.
 
@@ -115,7 +123,8 @@
       logging.info('Starting the devserver.')
       self.devserver = dev_server_wrapper.DevServerWrapper()
       self.devserver.Start()
-      self.binhost = self.devserver.GetURL(
+      self.binhost = self.devserver.GetDevServerURL(
+          ip=self.HOST_IP_ADDRESS, port=self.devserver.port,
           sub_dir='static/pkgroot/%s/packages' % self.board)
 
     logging.info('Using binhost %s', self.binhost)
@@ -144,7 +153,8 @@
     try:
       self.device.RunCommand(
           ['gmerge', 'gmerge', '--accept_stable', '--usepkg',
-           '--devserver_url', self.devserver.GetURL(),
+           '--devserver_url', self.devserver.GetDevServerURL(
+               ip=self.HOST_IP_ADDRESS, port=self.devserver.port),
            '--board', self.board])
     except (cros_build_lib.RunCommandError,
             remote_access.SSHConnectionError) as e: