Remove use of --remote_payload in autoupdate tests.

The remote_payload flag lets you stage payloads on one devserver and use
a different devserver for the omaha component. This is an unneccesarily
complicated setup for the AU tests. We can just use one devserver for
both tasks.

This will help with the effort to deprecate the flag.

BUG=chromium:980362
TEST=autoupdate_ForcedOOBEUpdate, autoupdate_NonBlockingOOBEUpdate

Change-Id: I29840927270ccec3a57749bdb2b066106fa4a63b
Reviewed-on: https://chromium-review.googlesource.com/1692004
Tested-by: David Haddock <dhaddock@chromium.org>
Commit-Ready: David Haddock <dhaddock@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: David Haddock <dhaddock@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
(cherry picked from commit 530f09c841eb21209d02f87ddc8e1efe7c4a544b)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/autotest/+/1700165
Commit-Queue: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
diff --git a/server/cros/update_engine/omaha_devserver.py b/server/cros/update_engine/omaha_devserver.py
index 0e6c9eb..cdc8f55 100644
--- a/server/cros/update_engine/omaha_devserver.py
+++ b/server/cros/update_engine/omaha_devserver.py
@@ -4,6 +4,7 @@
 
 import json
 import logging
+import os
 import socket
 import time
 import urllib2
@@ -46,30 +47,27 @@
     _DEVSERVER_TIMELIMIT_SECONDS = 12 * 60 * 60
 
 
-    def __init__(self, omaha_host, update_payload_staged_url, max_updates=1,
+    def __init__(self, omaha_host, payload_location, max_updates=1,
                  critical_update=True):
         """Starts a private devserver instance, operating at Omaha capacity.
 
         @param omaha_host: host address where the devserver is spawned.
-        @param update_payload_staged_url: URL to provision for update requests.
+        @param payload_location: partial path from static dir to payload.
         @param max_updates: int number of updates this devserver will handle.
                             This is passed to src/platform/dev/devserver.py.
         @param critical_update: Whether to set a deadline in responses.
         """
         self._devserver_dir = '/home/chromeos-test/chromiumos/src/platform/dev'
 
-        if not update_payload_staged_url:
-            raise error.TestError('Missing update payload url')
-
         self._critical_update = critical_update
         self._max_updates = max_updates
         self._omaha_host = omaha_host
         self._devserver_pid = 0
         self._devserver_port = 0  # Determined later from devserver portfile.
-        self._update_payload_staged_url = update_payload_staged_url
 
         self._devserver_ssh = hosts.SSHHost(self._omaha_host,
                                             user='chromeos-test')
+        self._payload_location = payload_location
 
         # Temporary files for various devserver outputs.
         self._devserver_logfile = None
@@ -196,9 +194,6 @@
             OmahaDevserverFailedToStart: If the time limit is reached and we
                                          cannot connect to the devserver.
         """
-        update_payload_url_base, update_payload_path = self._split_url(
-                self._update_payload_staged_url)
-
         # Allocate temporary files for various server outputs.
         self._devserver_logfile = self._create_tempfile_on_devserver('log')
         self._devserver_stdoutfile = self._create_tempfile_on_devserver(
@@ -215,16 +210,15 @@
                 'timeout', '-s', 'TERM', '-k', '30',
                 str(self._DEVSERVER_TIMELIMIT_SECONDS),
                 '%s/devserver.py' % self._devserver_dir,
-                '--payload=%s' % update_payload_path,
                 '--port=0',
                 '--pidfile=%s' % self._devserver_pidfile,
                 '--portfile=%s' % self._devserver_portfile,
                 '--logfile=%s' % self._devserver_logfile,
-                '--remote_payload',
-                '--urlbase=%s' % update_payload_url_base,
                 '--max_updates=%s' % self._max_updates,
                 '--host_log',
-                '--static_dir=%s' % self._devserver_static_dir
+                '--static_dir=%s' % self._devserver_static_dir,
+                '--payload=%s' % os.path.join(self._devserver_static_dir,
+                                              self._payload_location),
         ]
 
         if self._critical_update:
@@ -367,16 +361,6 @@
                     snippet(self._get_devserver_log()))
 
 
-    @staticmethod
-    def _split_url(url):
-        """Splits a URL into the URL base and path."""
-        split_url = urlparse.urlsplit(url)
-        url_base = urlparse.urlunsplit(
-                (split_url.scheme, split_url.netloc, '', '', ''))
-        url_path = split_url.path
-        return url_base, url_path.lstrip('/')
-
-
     def stop_devserver(self):
         """Kill remote process and wait for it to die, dump its output."""
         if not self._devserver_pid:
diff --git a/server/cros/update_engine/update_engine_test.py b/server/cros/update_engine/update_engine_test.py
index 7210bd0..d28966a 100644
--- a/server/cros/update_engine/update_engine_test.py
+++ b/server/cros/update_engine/update_engine_test.py
@@ -88,6 +88,7 @@
 
 
     def cleanup(self):
+        """Clean up update_engine autotests."""
         if self._omaha_devserver is not None:
             self._omaha_devserver.stop_devserver()
         if self._host:
@@ -396,6 +397,21 @@
         return payloads[0]
 
 
+    def _get_partial_path_from_url(self, url):
+        """
+        Strip partial path to payload from GS Url.
+
+        Example: gs://chromeos-image-archive/samus-release/R77-112.0.0/bla.bin
+        returns samus-release/R77-112.0.0/bla.bin.
+
+        @param url: The Google Storage url.
+
+        """
+        gs = dev_server._get_image_storage_server()
+        staged_path = url.partition(gs)
+        return staged_path[2]
+
+
     def _get_staged_file_info(self, staged_url, retries=5):
         """
         Gets the staged files info that includes SHA256 and size.
@@ -642,8 +658,8 @@
         ds_url, build = tools.get_devserver_build_from_package_url(
             self._job_repo_url)
 
-        # We always stage the payloads on the existing lab devservers.
-        self._autotest_devserver = dev_server.ImageServer(ds_url)
+        # The lab devserver assigned to this test.
+        lab_devserver = dev_server.ImageServer(ds_url)
 
         if public:
             # Get the google storage url of the payload. We will be copying
@@ -656,24 +672,35 @@
             return url
 
         if full_payload:
-            self._autotest_devserver.stage_artifacts(build, ['full_payload'])
             if not critical_update:
-                # We can use the same lab devserver to handle the update.
+                # Stage payloads on the lab devserver.
+                self._autotest_devserver = lab_devserver
+                self._autotest_devserver.stage_artifacts(build,
+                                                         ['full_payload'])
+                # Use the same lab devserver to also handle the update.
                 url = self._autotest_devserver.get_update_url(build)
                 logging.info('Full payload, non-critical update URL: %s', url)
                 return url
             else:
-                staged_url = self._autotest_devserver._get_image_url(build)
+                url_to_stage = self._get_payload_url(build, full_payload=True)
         else:
             # We need to stage delta ourselves due to crbug.com/793434.
-            delta_payload = self._get_payload_url(build, full_payload=False)
-            staged_url = self._stage_payload_by_uri(delta_payload)
+            url_to_stage = self._get_payload_url(build, full_payload=False)
 
-        # We need to start our own devserver for the rest of the cases.
+        # Get partial path to payload eg samus-release/R77-113.0,0/blah.bin
+        payload_location = self._get_partial_path_from_url(url_to_stage)
+
+        # We need to start our own devserver instance on the lab devserver
+        # for the rest of the test scenarios.
         self._omaha_devserver = omaha_devserver.OmahaDevserver(
-            self._autotest_devserver.hostname, staged_url,
-            max_updates=max_updates, critical_update=critical_update)
+            lab_devserver.hostname, payload_location, max_updates=max_updates,
+            critical_update=critical_update)
         self._omaha_devserver.start_devserver()
+
+        # Stage the payloads on our new devserver.
+        ds_url = 'http://%s' % self._omaha_devserver.get_netloc()
+        self._autotest_devserver = dev_server.ImageServer(ds_url)
+        self._stage_payload_by_uri(url_to_stage)
         url = self._omaha_devserver.get_update_url()
         logging.info('Update URL: %s', url)
         return url