Modify dynamic suite pathway to allow some artifacts to be staged in the bgnd.

This change modifies the site_rpc_interface->dynamic_suite.py workflow to allow
autotest to stage larger build components while imaging devices. It uses
the download/wait_for_status interface provided by the devserver to
accomplish it.

BUG=chromium-os:27285
TEST=All effected unittests pass. Staging larger test on local devserver in
parallel.

Change-Id: Iae2a20762c565b8e6d440c9a501c1f99c73129ed
Reviewed-on: https://gerrit.chromium.org/gerrit/19328
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Tested-by: Scott Zawalski <scottz@chromium.org>
Commit-Ready: Scott Zawalski <scottz@chromium.org>
diff --git a/server/cros/dynamic_suite.py b/server/cros/dynamic_suite.py
index 5d114b3..a1b01fe 100644
--- a/server/cros/dynamic_suite.py
+++ b/server/cros/dynamic_suite.py
@@ -15,6 +15,12 @@
 CONFIG = global_config.global_config
 
 
+class AsynchronousBuildFailure(Exception):
+    """Raised when the dev server throws 500 while finishing staging of a build.
+    """
+    pass
+
+
 class SuiteArgumentException(Exception):
     """Raised when improper arguments are used to run a suite."""
     pass
@@ -51,6 +57,8 @@
                          Default: False
     @param add_experimental: schedule experimental tests as well, or not.
                              Default: True
+    @raises AsynchronousBuildFailure: if there was an issue finishing staging
+                                      from the devserver.
     """
     (build, board, name, job, pool, num, check_hosts, skip_reimage,
      add_experimental) = _vet_reimage_and_run_args(**dargs)
@@ -61,6 +69,13 @@
 
     if skip_reimage or reimager.attempt(build, board, job.record, check_hosts,
                                         num=num):
+
+        # Ensure that the image's artifacts have completed downloading.
+        ds = dev_server.DevServer.create()
+        if not ds.finish_download(build):
+            raise AsynchronousBuildFailure(
+                "Server error completing staging for " + build)
+
         suite = Suite.create_from_name(name, build, pool=pool,
                                        results_dir=job.resultdir)
         suite.run_and_wait(job.record, add_experimental=add_experimental)