[autotest] Delay retrieving IP address of a host.

The error raised in initializer will lead to CrosHost failed to be initialized.
We need to delay this action only when it's requested. so CrosHost can be
initialized and continue working for cases like repairing, in which case the
dut can be down and don't have an IP address if DHCP server does not have
static IP for it.

BUG=chromium:441511
TEST=local test.

Change-Id: I3e83c4a9ddfd00add4b373f5a2c9339d77f61aa6
Reviewed-on: https://chromium-review.googlesource.com/234851
Trybot-Ready: Dan Shi <[email protected]>
Tested-by: Dan Shi <[email protected]>
Reviewed-by: Richard Barnette <[email protected]>
Commit-Queue: Dan Shi <[email protected]>
diff --git a/server/hosts/abstract_ssh.py b/server/hosts/abstract_ssh.py
index 39af9f9..fb87e81 100644
--- a/server/hosts/abstract_ssh.py
+++ b/server/hosts/abstract_ssh.py
@@ -23,7 +23,9 @@
                     *args, **dargs):
         super(AbstractSSHHost, self)._initialize(hostname=hostname,
                                                  *args, **dargs)
-        self.ip = socket.getaddrinfo(self.hostname, None)[0][4][0]
+        # IP address is retrieved only on demand. Otherwise the host
+        # initialization will fail for host is not online.
+        self._ip = None
         self.user = user
         self.port = port
         self.password = password
@@ -40,6 +42,15 @@
         self.master_ssh_option = ''
 
 
+    @property
+    def ip(self):
+        """@return IP address of the host.
+        """
+        if not self._ip:
+            self._ip = socket.getaddrinfo(self.hostname, None)[0][4][0]
+        return self._ip
+
+
     def make_ssh_command(self, user="root", port=22, opts='',
                          hosts_file='/dev/null',
                          connect_timeout=30, alive_interval=300):