autotest (wifi): Do not try to write to /tmp on an ADBHost

Because the root filesystem is read-only and writing to /data/local/tmp
is a more appropriate location on that platform.

The file will now be placed into a subdirectory named autoserv-<random>
under the base temporary directory (be it /tmp or /data/local/tmp) for
each test run. The temporary directories all get cleaned up after the
end of the test run.

BUG=chrome-os-partner:42310
TEST=Ran network_WiFi_SimpleConnect through adb successfully.
  Also ran it on samus and confirmed it did not cause any regressions.

Change-Id: I1f7e94c3aad91c05cd958698a44c491b4ed673ee
Signed-off-by: Filipe Brandenburger <filbranden@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/306115
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Bindu Mahadev <bmahadev@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
diff --git a/client/common_lib/cros/network/iw_event_logger.py b/client/common_lib/cros/network/iw_event_logger.py
index c3aec91..54d8a41 100644
--- a/client/common_lib/cros/network/iw_event_logger.py
+++ b/client/common_lib/cros/network/iw_event_logger.py
@@ -4,9 +4,10 @@
 
 import collections
 import logging
+import os
 import re
 
-IW_REMOTE_EVENT_LOG_FILE = '/tmp/iw_event.log'
+IW_REMOTE_EVENT_LOG_FILE_NAME = 'iw_event.log'
 
 LogEntry = collections.namedtuple('LogEntry', ['timestamp',
                                                'interface',
@@ -17,6 +18,8 @@
     def __init__(self, host, command_iw, local_file):
         self._host = host
         self._command_iw = command_iw
+        self._iw_event_log_path = os.path.join(self._host.get_tmp_dir(),
+                                               IW_REMOTE_EVENT_LOG_FILE_NAME)
         self._local_file = local_file
         self._pid = None
         self._start_time = 0
@@ -60,7 +63,7 @@
 
         """
         command = 'nohup %s event -t </dev/null >%s 2>&1 & echo $!' % (
-                self._command_iw, IW_REMOTE_EVENT_LOG_FILE)
+                self._command_iw, self._iw_event_log_path)
         command += ';date +%s'
         out_lines = self._host.run(command).stdout.splitlines()
         self._pid = int(out_lines[0])
@@ -80,7 +83,7 @@
         self._host.run('kill %d' % self._pid, ignore_status=True)
         self._pid = None
         # Copy iw event log file from remote host
-        self._host.get_file(IW_REMOTE_EVENT_LOG_FILE, self._local_file)
+        self._host.get_file(self._iw_event_log_path, self._local_file)
         logging.info('iw event log saved to %s', self._local_file)