[autotest] Save preserved log during autoupdate.

In following test, add a logdir to job.sysinfo.test_loggables to save files in
/mnt/stateful_partition/unencrypted/preserve/log

server/control/segments/provision
server/site_tests/autoupdate
server/site_tests/autoupdate_EndToEndTest
server/site_tests/provision_AutoUpdate

The logdir will enable autotest to collect the preserved logs and save to
results folder:
[test]/sysinfo/mnt/stateful_partition/unencrypted/preserve/log

BUG=chromium:276919
TEST=test_that 172.22.75.106 dummy_Pass -i lumpy-release/R34-5233.0.0
trybot build trybot-lumpy-release/R34-5238.0.0-b1752

Change-Id: Ia4beee8a43a3b9c0959ce00b514eda5f29f27f71
Reviewed-on: https://chromium-review.googlesource.com/182948
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Alex Miller <milleral@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/client/bin/site_sysinfo.py b/client/bin/site_sysinfo.py
index 4bd75e3..250fb27 100755
--- a/client/bin/site_sysinfo.py
+++ b/client/bin/site_sysinfo.py
@@ -396,4 +396,4 @@
                          from, e.g.,
                          /mnt/stateful_partition/unencrypted/preserve/log
         """
-        self.test_loggables.add(logdir(log_path))
\ No newline at end of file
+        self.test_loggables.add(logdir(log_path))
diff --git a/client/cros/constants.py b/client/cros/constants.py
index ad3730b..7dbfde8 100644
--- a/client/cros/constants.py
+++ b/client/cros/constants.py
@@ -18,6 +18,9 @@
 CHROME_CORE_MAGIC_FILE = '/mnt/stateful_partition/etc/collect_chrome_crashes'
 CHROME_LOG_DIR = '/var/log/chrome'
 
+# Directory to save log files preserved during autoupdate.
+AUTOUPDATE_PRESERVE_LOG = '/mnt/stateful_partition/unencrypted/preserve/log'
+
 CLEANUP_LOGS_PAUSED_FILE = '/var/lib/cleanup_logs_paused'
 
 CLIENT_LOGIN_URL = '/accounts/ClientLogin'
diff --git a/server/control_segments/provision b/server/control_segments/provision
index 6cef6f3..d2503bc 100644
--- a/server/control_segments/provision
+++ b/server/control_segments/provision
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 
+from autotest_lib.client.cros import constants
 from autotest_lib.server.cros import provision
 
 
@@ -31,6 +32,9 @@
 
     try:
         for name, value in provision.split_labels(provisionable).items():
+            # Save preserved log after autoupdate is completed.
+            job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
+
             test = provision.provisioner_for(name)
             # sysinfo isn't really going to get us anything incredibly
             # interesting here, and it takes a non-trivial amount of time, so
diff --git a/server/site_tests/autoupdate/control b/server/site_tests/autoupdate/control
index c6ce87f..582b389 100644
--- a/server/site_tests/autoupdate/control
+++ b/server/site_tests/autoupdate/control
@@ -19,10 +19,14 @@
 @param image_name: the name of the image, used to label the device a.k.a. build
 """
 
+from autotest_lib.client.cros import constants
 from autotest_lib.server.cros.dynamic_suite import frontend_wrappers
 
 
 def run(machine):
+    # Save preserved log after autoupdate is completed.
+    job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
+
     host = hosts.create_host(machine, initialize=False)
     host.clear_cros_version_labels_and_job_repo_url()
     job.run_test('autoupdate', host=host, update_url=image_url)
diff --git a/server/site_tests/autoupdate/control.local b/server/site_tests/autoupdate/control.local
index 733711a..4f1da0d 100644
--- a/server/site_tests/autoupdate/control.local
+++ b/server/site_tests/autoupdate/control.local
@@ -23,9 +23,13 @@
 
 import socket
 from autotest_lib.client.common_lib import utils
+from autotest_lib.client.cros import constants
 
 
 def run(machine):
+    # Save preserved log after autoupdate is completed.
+    job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
+
     hostname = socket.getfqdn()
     args_dict = utils.args_to_dict(args)
     port = args_dict.get('port', '8080')
diff --git a/server/site_tests/autoupdate/control.repair b/server/site_tests/autoupdate/control.repair
index 9e9af24..f74b03e 100644
--- a/server/site_tests/autoupdate/control.repair
+++ b/server/site_tests/autoupdate/control.repair
@@ -16,8 +16,12 @@
 Assumes that a label including the image name has already been created.
 """
 
+from autotest_lib.client.cros import constants
 
 def run(machine):
+    # Save preserved log after autoupdate is completed.
+    job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
+
     host = hosts.create_host(machine, initialize=False)
     job.run_test('autoupdate', host=host, update_url=None, repair=True,
                  disable_sysinfo=True)
diff --git a/server/site_tests/autoupdate_EndToEndTest/control b/server/site_tests/autoupdate_EndToEndTest/control
index 54e8846..9f638f0 100644
--- a/server/site_tests/autoupdate_EndToEndTest/control
+++ b/server/site_tests/autoupdate_EndToEndTest/control
@@ -4,6 +4,7 @@
 
 import logging
 from autotest_lib.client.common_lib import error, utils
+from autotest_lib.client.cros import constants
 from autotest_lib.server import host_attributes
 
 AUTHOR = "Chromium OS"
@@ -144,6 +145,8 @@
 def run_test(machine):
     """Execute a test configuration on a given machine."""
     host = hosts.create_host(machine, servo_args=servo_args)
+    # Save preserved log after autoupdate is completed.
+    job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
     try:
         job.run_test(
                 "autoupdate_EndToEndTest",
diff --git a/server/site_tests/provision_AutoUpdate/control b/server/site_tests/provision_AutoUpdate/control
index 9d53671..5b4c64a 100644
--- a/server/site_tests/provision_AutoUpdate/control
+++ b/server/site_tests/provision_AutoUpdate/control
@@ -18,6 +18,7 @@
 
 
 from autotest_lib.client.common_lib import error, utils
+from autotest_lib.client.cros import constants
 
 
 # Uncomment the below line, and change it to the correct value if you are
@@ -33,6 +34,9 @@
 
 
 def run(machine):
+    # Save preserved log after autoupdate is completed.
+    job.sysinfo.add_logdir(constants.AUTOUPDATE_PRESERVE_LOG)
+
     host = hosts.create_host(machine, initialize=False)
     job.run_test('provision_AutoUpdate', host=host, value=value,
                  disable_sysinfo=True)