Create a function that all AU tests can call to get an update url.

Each AU test needs a slightly different setup but ultimately they just
want an update url to call and don't care about where that url comes
from or where the payloads are staged.

This functionality has lived in each test but I think it is
cleaner to have one function in the base test class that figures it out and
just returns the test the update url to use.

BUG=chromium:799713
TEST=autoupdate_P2P, autoupdate_ForcedOOBEUpdate,
autoupdate_EndToEndTest still pass

Change-Id: I56c6b00f0fbc8f9a3b7b988c9f3f252960364d9b
Reviewed-on: https://chromium-review.googlesource.com/865287
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Haddock <dhaddock@chromium.org>
Reviewed-by: danny chan <dchan@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py b/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
index b800b37..6520eb0 100644
--- a/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
+++ b/server/site_tests/autoupdate_ForcedOOBEUpdate/autoupdate_ForcedOOBEUpdate.py
@@ -6,12 +6,8 @@
 import os
 import time
 
-from autotest_lib.client.common_lib import error
 from autotest_lib.client.common_lib import lsbrelease_utils
-from autotest_lib.client.common_lib.cros import dev_server
 from autotest_lib.server import autotest
-from autotest_lib.server.cros.dynamic_suite import tools
-from autotest_lib.server.cros.update_engine import omaha_devserver
 from autotest_lib.server.cros.update_engine import update_engine_test
 
 
@@ -29,13 +25,7 @@
     _ROOTFS_HOSTLOG_EVENTS = 4
 
 
-    def setup(self):
-        self._omaha_devserver = None
-
-
     def cleanup(self):
-        if self._omaha_devserver is not None:
-            self._omaha_devserver.stop_devserver()
         self._host.run('rm %s' % self._CUSTOM_LSB_RELEASE, ignore_status=True)
 
         # Get the last two update_engine logs: before and after reboot.
@@ -44,7 +34,7 @@
         for i in range(2):
             self._host.get_file('/var/log/update_engine/%s' % files[i],
                                 self.resultsdir)
-
+        super(autoupdate_ForcedOOBEUpdate, self).cleanup()
 
     def _get_chromeos_version(self):
         """Read the ChromeOS version from /etc/lsb-release."""
@@ -52,32 +42,6 @@
         return lsbrelease_utils.get_chromeos_release_version(lsb)
 
 
-    def _get_payload_url_from_job_repo_url(self, job_repo_url):
-        """Get the payload to update to.
-
-        We will use the job_repo_url to get a payload that matches the build
-        number that the DUT is currently running. That way we will update
-        from N->N at OOBE.
-
-        @param job_repo_url: a url you can pass to the test for local debugging.
-        """
-        if job_repo_url is None:
-            info = self._host.host_info_store.get()
-            job_repo_url = info.attributes.get(
-                self._host.job_repo_url_attribute, '')
-        if not job_repo_url:
-            raise error.TestFail('There was no job_repo_url so we cannot get '
-                                 'a payload to use.')
-        ds_url, build = tools.get_devserver_build_from_package_url(job_repo_url)
-        self._autotest_devserver = dev_server.ImageServer(ds_url)
-        self._autotest_devserver.stage_artifacts(build, ['full_payload'])
-        payload_url = self._autotest_devserver.get_full_payload_url(build)
-
-        # The devserver adds on the update.gz filename again during
-        # HandleUpdatePing() so we take it off here.
-        return payload_url.rpartition('/')[0]
-
-
     def _create_hostlog_files(self):
         """Create the two hostlog files for the update.
 
@@ -122,22 +86,16 @@
 
     def run_once(self, host, job_repo_url=None):
         self._host = host
-
-        # Get a payload that matches the current build on the DUT.
-        update_url = self._get_payload_url_from_job_repo_url(job_repo_url)
-        logging.info('Payload url to use: %s', update_url)
-
-        # Start a devserver in the lab that will serve a critical update.
-        self._omaha_devserver = omaha_devserver.OmahaDevserver(
-            self._autotest_devserver.hostname, update_url)
-        self._omaha_devserver.start_devserver()
-
+        update_url = self.get_update_url_for_test(job_repo_url,
+                                                  full_payload=True,
+                                                  critical_update=True)
+        logging.info('Update url: %s', update_url)
         before = self._get_chromeos_version()
 
         # Call client test to start the forced OOBE update.
         client_at = autotest.Autotest(self._host)
         client_at.run_test('autoupdate_StartOOBEUpdate',
-                           image_url=self._omaha_devserver.get_update_url())
+                           image_url=update_url)
 
         # Don't continue the test if the client failed for any reason.
         client_at._check_client_test_result(self._host,