[autotest] Update shadow config in container with FQDN of db/afe server name.

container may not be able to resolve hostname like cautotest. The FQDN should be
used in db and afe server name in container's shadow config.

BUG=chromium:453624
TEST=lxc_functional_test. verify with a test drone

Change-Id: I6cf337edc8d36e8fbb9e58cbe5e43e3227b65f10
Reviewed-on: https://chromium-review.googlesource.com/262214
Trybot-Ready: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/site_utils/lxc.py b/site_utils/lxc.py
index 48f1f4f..751a806 100644
--- a/site_utils/lxc.py
+++ b/site_utils/lxc.py
@@ -622,7 +622,8 @@
         1. Disable master ssh connection in shadow config, as it is not working
            properly in container yet, and produces noise in the log.
         2. Update AUTOTEST_WEB/host and SERVER/hostname to be the IP of the host
-           if any is set to localhost or 127.0.0.1.
+           if any is set to localhost or 127.0.0.1. Otherwise, set it to be the
+           FQDN of the config value.
 
         @param container: The container object to be updated in shadow config.
         @param shadow_config: Path the the shadow config file to be used in the
@@ -639,14 +640,19 @@
 
         db_host = config.get_config_value('AUTOTEST_WEB', 'host')
         if db_host.lower() in local_names:
-            container.attach_run(
-                    'echo $\'\n[AUTOTEST_WEB]\nhost: %s\n\' >> %s' %
-                    (host_ip, shadow_config))
+            new_host = host_ip
+        else:
+            new_host = socket.getfqdn(db_host)
+        container.attach_run('echo $\'\n[AUTOTEST_WEB]\nhost: %s\n\' >> %s' %
+                             (new_host, shadow_config))
 
         afe_host = config.get_config_value('SERVER', 'hostname')
         if afe_host.lower() in local_names:
-            container.attach_run('echo $\'\n[SERVER]\nhostname: %s\n\' >> %s' %
-                                 (host_ip, shadow_config))
+            new_host = host_ip
+        else:
+            new_host = socket.getfqdn(afe_host)
+        container.attach_run('echo $\'\n[SERVER]\nhostname: %s\n\' >> %s' %
+                             (new_host, shadow_config))
 
 
     @timer.decorate