autoserv: Infer require_ssp from control file passed to autoserv

Unlike Autotest, Skylab does not pass in a control file to execute by
autoserv, nor does Skylab parse the control file to obtain the options
specified within control files.

Instead, Skylab passes in the name of the control file to execute and
autoserv must infer and respect the options set by a test via its
control file.

This CL makes autoserv respect the REQUIRE_SSP directive in the control
file, if the control file was passed in via --control-name

BUG=chromium:871439
TEST=manual skylab task for dummy_ServerPass.ssp and .nossp

Change-Id: I367d11d7bf74fafed2ae7ca2184856ca707f8367
Reviewed-on: https://chromium-review.googlesource.com/1173137
Commit-Ready: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Xixuan Wu <xixuan@chromium.org>
diff --git a/server/autoserv b/server/autoserv
index e8d8b89..f6b475e 100755
--- a/server/autoserv
+++ b/server/autoserv
@@ -633,6 +633,33 @@
     return task_mapping[match[0]] if match else s.RUNNING
 
 
+def _require_ssp_from_control(control_name):
+    """Read the value of REQUIRE_SSP from test control file.
+
+    This reads the control file from the prod checkout of autotest and uses that
+    to determine whether to even stage the SSP package on a devserver.
+
+    This means:
+    [1] Any change in REQUIRE_SSP directive in a test requires a prod-push to go
+    live.
+    [2] This function may find that the control file does not exist but the SSP
+    package may contain the test file. This function conservatively returns True
+    in that case.
+
+    This function is called very early in autoserv, before logging is setup.
+    """
+    if not control_name:
+        return True
+    path = _control_path_on_disk(control_name)
+    if not os.path.isfile(path):
+        return True
+    control = control_data.parse_control(path)
+    # There must be explicit directive in the control file to disable SSP.
+    if not control or control.require_ssp is None:
+        return True
+    return control.require_ssp
+
+
 def main():
     start_time = datetime.datetime.now()
     parser = autoserv_parser.autoserv_parser
@@ -642,8 +669,6 @@
         parser.parser.print_help()
         sys.exit(1)
 
-    use_ssp = parser.options.require_ssp
-
     if parser.options.no_logging:
         results = None
     else:
@@ -666,6 +691,14 @@
         if not os.path.isdir(results):
             os.makedirs(results)
 
+    if parser.options.require_ssp:
+        # This is currently only used for skylab (i.e., when --control-name is
+        # used).
+        use_ssp = _require_ssp_from_control(parser.options.control_name)
+    else:
+        use_ssp = False
+
+
     if use_ssp:
         log_dir = os.path.join(results, 'ssp_logs') if results else None
         if log_dir and not os.path.exists(log_dir):