autotest: Fix site_wifitest errors for tests in wifi_matfunc suite

site_wifitest was erroneously trying to call sync_host_times on the host
objects for the client, router, and server rather than the appropriate
wrappers.  The command lookup was broken on RSPro/Netgear setups.  RSPro
cells need a different command line to start hostapd and send its logs
to a file.  The hostapd on those setups also doesn't seem to write out
its PID file, so move the logic that checks hostapd start health

BUG=None
TEST=network_WiFiManager tests pass again on stumpy cells.  092* passes
on an RSPro cell.  The remaining 3 Manager tests still fail on RSPro
cells, but this is because wait_service expects to find that the service
is online, when it is only portalled in those setups.

Change-Id: I5db662d1567bed812c7a1879b750d870bbed0048
Reviewed-on: https://chromium-review.googlesource.com/171792
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
diff --git a/server/site_linux_router.py b/server/site_linux_router.py
index 09a8718..aa45297 100644
--- a/server/site_linux_router.py
+++ b/server/site_linux_router.py
@@ -6,7 +6,6 @@
 import random
 import re
 import string
-import time
 
 from autotest_lib.client.common_lib import error
 from autotest_lib.server import site_linux_system
@@ -70,8 +69,8 @@
         self.cmd_dhcpd = params.get('cmd_dhcpd', '/usr/sbin/dhcpd')
         self.cmd_hostapd = wifi_test_utils.must_be_installed(
                 host, params.get('cmd_hostapd', '/usr/sbin/hostapd'))
-        self.cmd_hostapd_cli = params.get('cmd_hostapd_cli',
-                                          '/usr/sbin/hostapd_cli')
+        self.cmd_hostapd_cli = wifi_test_utils.must_be_installed(
+                host, params.get('cmd_hostapd_cli', '/usr/sbin/hostapd_cli'))
         self.dhcpd_conf = '/tmp/dhcpd.%s.conf'
         self.dhcpd_leases = '/tmp/dhcpd.leases'
 
@@ -187,6 +186,11 @@
         pass
 
 
+    def get_hostapd_start_command(self, log_file, pid_file, conf_file):
+        return '%s -dd -t -P %s %s &> %s &' % (
+                self.cmd_hostapd, pid_file, conf_file, log_file)
+
+
     def start_hostapd(self, conf, params):
         """Start a hostapd instance described by conf.
 
@@ -216,39 +220,9 @@
         self.router.run('rm %s' % log_file, ignore_status=True)
         self.router.run('rm %s' % pid_file, ignore_status=True)
         self._pre_start_hook(params)
-        self.router.run("%s -dd -B -t -f %s -P %s %s" %
-            (self.cmd_hostapd, log_file, pid_file, conf_file))
-        pid = int(self.router.run('cat %s' % pid_file).stdout)
-
-        # Wait for confirmation that the router came up.
-        logging.info('Waiting for hostapd to startup.')
-        start_time = time.time()
-        while time.time() - start_time < self.STARTUP_TIMEOUT_SECONDS:
-            success = self.router.run(
-                    'grep "Completing interface initialization" %s' % log_file,
-                    ignore_status=True).exit_status == 0
-            if success:
-                break
-
-            # A common failure is to request an invalid router configuration.
-            # Detect this and exit early if we see it.
-            bad_config = self.router.run(
-                    'grep "Interface initialization failed" %s' % log_file,
-                    ignore_status=True).exit_status == 0
-            if bad_config:
-                raise error.TestFail('hostapd failed to initialize AP '
-                                     'interface.')
-
-            early_exit = self.router.run('kill -0 %d' % pid,
-                                         ignore_status=True).exit_status
-            if early_exit:
-                raise error.TestFail('hostapd process terminated.')
-
-            time.sleep(self.STARTUP_POLLING_INTERVAL_SECONDS)
-        else:
-            raise error.TestFail('Timed out while waiting for hostapd '
-                                 'to start.')
-
+        start_command = self.get_hostapd_start_command(
+                log_file, pid_file, conf_file)
+        self.router.run(start_command)
         self.hostapd_instances.append({
             'conf_file': conf_file,
             'log_file': log_file,
@@ -740,10 +714,15 @@
                     self._remove_interface(instance['interface'], True)
 
                 self.kill_hostapd_instance(instance['conf_file'])
-                self.router.get_file(instance['log_file'],
-                                     'debug/hostapd_router_%d_%s.log' %
-                                     (self.hostapd['log_count'],
-                                      instance['interface']))
+                if wifi_test_utils.is_installed(self.host,
+                                                instance['log_file']):
+                    self.router.get_file(instance['log_file'],
+                                         'debug/hostapd_router_%d_%s.log' %
+                                         (self.hostapd['log_count'],
+                                          instance['interface']))
+                else:
+                    logging.error('Did not collect hostapd log file because '
+                                  'it was missing.')
                 self._release_wlanif(instance['interface'])
 #               self.router.run("rm -f %(log_file)s %(conf_file)s" % instance)
             self.hostapd['log_count'] += 1