[Autotest] merge cleanup and verify

The objective of this CL is to merge cleanup and verify into a single job to
reduce run time of each test. In existing design, by default, a cleanup job is
scheduled after a test is finished, and a verify job is scheduled before a
test is started. By merging these two jobs together, we are seeing the total
run time of these two jobs is reduced from about 47s to 37s, around 10s saving.
That does not include the saving on scheduler to schedule two jobs, which may
take another 5-10s.

The design is to create a new special task, reset, which runs at the beginning
of a job by default. Verify task is changed to not to run by default before a
job starts. Cleanup job will only be run if a job is scheduled to reboot and
any test failed in that job.

BUG=chromium:220679
TEST=tested with run_suite in local machine
DEPLOY=afe,apache,scheduler,change all users' preference on reboot_after to
Never, sql: |update chromeos_autotest_db.afe_users set reboot_after=0|

Change-Id: Ia38baf6b73897b7e09fdf635eadedc752b5eba2f
Reviewed-on: https://gerrit.chromium.org/gerrit/48685
Commit-Queue: Dan Shi <dshi@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
diff --git a/server/control_segments/reset b/server/control_segments/reset
new file mode 100644
index 0000000..90dd651
--- /dev/null
+++ b/server/control_segments/reset
@@ -0,0 +1,27 @@
+import sys
+
+from autotest_lib.site_utils.graphite import stats
+
+def reset(machine):
+    print 'Starting to reset host ' + machine
+    timer = None
+    try:
+        host = hosts.create_host(machine, initialize=False, auto_monitor=False)
+        timer = stats.Timer('reset_time.%s' %
+                            host._get_board_from_afe())
+        timer.start()
+        # Assume cleanup always runs first.
+        host.cleanup()
+        host.verify()
+        job.record('GOOD', None, 'reset',
+                   '%s is reset successfully' % machine)
+    except Exception as e:
+        msg = 'reset failed: %s' % e
+        job.record('FAIL', None, 'reset', msg)
+        raise
+    finally:
+        if timer:
+            timer.stop()
+
+
+job.parallel_simple(reset, machines)