[autotest] Add hostname in devserver resolve calls

This is to make sure any attempt to resolve a devserver is able to pick a
devserver in the same subnet of the dut if it's in a restricted subnet.

BUG=chromium:577363
TEST=unittest, test push

Change-Id: If959865ef8ba04fa92299acc5b3c8c2d3bd8691b
Reviewed-on: https://chromium-review.googlesource.com/339215
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Fang Deng <fdeng@chromium.org>
diff --git a/server/site_autotest.py b/server/site_autotest.py
index f36a162..d78bb67 100755
--- a/server/site_autotest.py
+++ b/server/site_autotest.py
@@ -83,7 +83,13 @@
                 # the host will no longer have the context of the image option
                 # and will revert back to utilizing test code/artifacts that are
                 # currently present in the users source checkout.
-                devserver_url = dev_server.ImageServer.resolve(image_opt).url()
+                # devserver selected must be in the same subnet of self.host, if
+                # the host is in restricted subnet. Otherwise, host may not be
+                # able to reach the devserver and download packages from the
+                # repo_url.
+                hostname = self.host.hostname if self.host else None
+                devserver_url = dev_server.ImageServer.resolve(
+                        image_opt, hostname).url()
                 repo_url = tools.get_package_url(devserver_url, image_opt)
                 repos.append(repo_url)
         elif not server_utils.is_inside_chroot():