Forced OOBE Update over cellular.

We already have a forced OOBE update test but we want to have a test for
cellular as a few devices will be shipping with LTE.

Working with cellular means the test can no longer use a devserver in the lab.
It cannot verify the update worked successfully by checking the hostlog.

To make this work it requires enabling updates over cellular in the
server test. Then making the payload public so it can be reached over
cellular. Then checking the update engine log for cellular entries and update
successful entries.

The client test will need to switch to cellular, start an omaha instance
and watch the update until just before reboot.

BUG=chromium:809719
BUG=chromium:809681
TEST=autoupdate_ForcedOOBEUpdate.cellular.{full|delta} passes
TEST=autoupdate_Cellular still passes
TEST=autoupdate_ForcedOOBEUpdate still passes
Change-Id: Iad1b1aadd6f437aebc8026bb3ce612466fa78fb4
Reviewed-on: https://chromium-review.googlesource.com/911605
Commit-Ready: David Haddock <dhaddock@chromium.org>
Tested-by: David Haddock <dhaddock@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Harpreet Grewal <harpreet@chromium.org>
diff --git a/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py b/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
index adb62b7..f5921d0 100644
--- a/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
+++ b/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
@@ -10,7 +10,7 @@
 from autotest_lib.client.common_lib import lsbrelease_utils
 from autotest_lib.server import autotest
 from autotest_lib.server.cros.update_engine import update_engine_test
-
+from chromite.lib import retry_util
 
 class autoupdate_ForcedOOBEUpdate(update_engine_test.UpdateEngineTest):
     """Runs a forced autoupdate during OOBE."""
@@ -35,6 +35,9 @@
         for i in range(2):
             self._host.get_file('/var/log/update_engine/%s' % files[i],
                                 self.resultsdir)
+        cmd = 'update_engine_client --update_over_cellular=no'
+        retry_util.RetryException(error.AutoservRunError, 2, self._host.run,
+                                  cmd)
         super(autoupdate_ForcedOOBEUpdate, self).cleanup()
 
     def _get_chromeos_version(self):
@@ -85,7 +88,8 @@
             time.sleep(1)
 
 
-    def run_once(self, host, full_payload=True, job_repo_url=None):
+    def run_once(self, host, full_payload=True, cellular=False,
+                 job_repo_url=None):
         self._host = host
 
         # veyron_rialto is a medical device with a different OOBE that auto
@@ -95,14 +99,27 @@
 
         update_url = self.get_update_url_for_test(job_repo_url,
                                                   full_payload=full_payload,
-                                                  critical_update=True)
+                                                  critical_update=True,
+                                                  cellular=cellular)
         logging.info('Update url: %s', update_url)
         before = self._get_chromeos_version()
+        payload_info = None
+        if cellular:
+            cmd = 'update_engine_client --update_over_cellular=yes'
+            retry_util.RetryException(error.AutoservRunError, 2, self._host.run,
+                                      cmd)
+            # Get the payload's information (size, SHA256 etc) since we will be
+            # setting up our own omaha instance on the DUT. We pass this to
+            # the client test.
+            payload = self._get_payload_url(full_payload=full_payload)
+            staged_url = self._stage_payload_by_uri(payload)
+            payload_info = self._get_staged_file_info(staged_url)
 
         # Call client test to start the forced OOBE update.
         client_at = autotest.Autotest(self._host)
-        client_at.run_test('autoupdate_StartOOBEUpdate',
-                           image_url=update_url)
+        client_at.run_test('autoupdate_StartOOBEUpdate', image_url=update_url,
+                           cellular=cellular, payload_info=payload_info,
+                           full_payload=full_payload)
 
         # Don't continue the test if the client failed for any reason.
         client_at._check_client_test_result(self._host,
@@ -110,6 +127,26 @@
 
         self._wait_for_update_to_complete()
 
+        if cellular:
+            # We didn't have a devserver so we cannot check the hostlog to
+            # ensure the update completed successfully. Instead we can check
+            # that the second-to-last update engine log has the successful
+            # update message. Second to last because its the one before OOBE
+            # rebooted.
+            update_engine_files_cmd = 'ls -t -1 /var/log/update_engine/'
+            files = self._host.run(update_engine_files_cmd).stdout.splitlines()
+            before_reboot_file = self._host.run('cat /var/log/update_engine/%s'
+                                                % files[1]).stdout
+            self._check_for_cellular_entries_in_update_log(before_reboot_file)
+
+            success = 'Update successfully applied, waiting to reboot.'
+            update_ec = self._host.run('cat /var/log/update_engine/%s | grep '
+                                       '"%s"' % (files[1], success)).exit_status
+            if update_ec != 0:
+                raise error.TestFail('We could not verify that the update '
+                                     'completed successfully. Check the logs.')
+            return
+
         # Verify that the update completed successfully by checking hostlog.
         rootfs_hostlog, reboot_hostlog = self._create_hostlog_files()
         self.verify_update_events(self._CUSTOM_LSB_VERSION, rootfs_hostlog)