Convert platform_Shutdown into a server-side test as it needs a host to reboot.

Originally, platform_Shutdown was written as a client-side job that required
it to be run after a system has rebooted. Instead, platform_Shutdown should
work stand-alone and in order for this to happen, it must be a server-side
test that initiates a reboot on its host object.

BUG=chromium-os:35160
TEST=Ran with cros_run_vm_test platform_Shutdown with 0 state before.

Change-Id: Ia1b0d1642b9b050e928e19b497085bed55b676a6
Reviewed-on: https://gerrit.chromium.org/gerrit/36830
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
diff --git a/client/site_tests/platform_Shutdown/platform_Shutdown.py b/client/site_tests/platform_Shutdown/platform_Shutdown.py
deleted file mode 100644
index 74cf44e..0000000
--- a/client/site_tests/platform_Shutdown/platform_Shutdown.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import os, re
-from autotest_lib.client.bin import test
-from autotest_lib.client.common_lib import error
-
-class platform_Shutdown(test.test):
-    version = 1
-
-    def _parse_shutdown_statistics(self, filename):
-        statfile = open(filename, "r")
-        uptime = float(statfile.readline())
-        read_sectors = float(statfile.readline())
-        write_sectors = float(statfile.readline())
-        statfile.close()
-        return (uptime, read_sectors, write_sectors)
-
-    def run_once(self):
-        try:
-            prefix = "/var/log/metrics/shutdown_"
-            startstats = self._parse_shutdown_statistics(prefix + "start")
-            stopstats = self._parse_shutdown_statistics(prefix + "stop")
-            results = {}
-            results['seconds_shutdown'] = stopstats[0] - startstats[0]
-            results['sectors_read_shutdown'] = stopstats[1] - startstats[1]
-            results['sectors_written_shutdown'] = stopstats[2] - startstats[2]
-            self.write_perf_keyval(results)
-        except IOError, e:
-            print e
-            raise error.TestFail('Chrome OS shutdown metrics are missing')
diff --git a/client/site_tests/platform_Shutdown/control b/server/site_tests/platform_Shutdown/control
similarity index 68%
rename from client/site_tests/platform_Shutdown/control
rename to server/site_tests/platform_Shutdown/control
index b9f8ebd..a611c8b 100644
--- a/client/site_tests/platform_Shutdown/control
+++ b/server/site_tests/platform_Shutdown/control
@@ -2,18 +2,23 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+
 AUTHOR = "Chrome OS Team"
 NAME = "platform_Shutdown"
-PURPOSE = "Collect shutdown metrics."
-CRITERIA = "This test is a benchmark."
-SUITE = "bvt, kaen_bvt"
 TIME = "SHORT"
 TEST_CATEGORY = "Logging"
 TEST_CLASS = "platform"
-TEST_TYPE = "client"
+TEST_TYPE = "server"
+SUITE = "bvt"
 
 DOC = """
 This test collects the shutdown metrics from a system that has rebooted.
 """
 
-job.run_test('platform_Shutdown')
+
+def run(machine):
+    host = hosts.create_host(machine)
+    job.run_test("platform_Shutdown", host=host)
+
+
+parallel_simple(run, machines)
\ No newline at end of file
diff --git a/server/site_tests/platform_Shutdown/platform_Shutdown.py b/server/site_tests/platform_Shutdown/platform_Shutdown.py
new file mode 100644
index 0000000..64c4e7a
--- /dev/null
+++ b/server/site_tests/platform_Shutdown/platform_Shutdown.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+import StringIO
+
+
+from autotest_lib.client.common_lib import error
+from autotest_lib.server import test
+
+
+class platform_Shutdown(test.test):
+    version = 1
+
+
+    def _parse_shutdown_statistics(self, filename):
+        """Returns a tuple containing uptime, read_sectors, and write_sectors.
+        """
+        statfile = StringIO.StringIO(self.client.run_output(
+                'cat %s' % filename))
+        uptime = float(statfile.readline())
+        read_sectors = float(statfile.readline())
+        write_sectors = float(statfile.readline())
+        statfile.close()
+        return uptime, read_sectors, write_sectors
+
+
+    def run_once(self, host):
+        self.client = host
+        self.client.reboot()
+        prefix = '/var/log/metrics/shutdown_'
+
+        try:
+            startstats = self._parse_shutdown_statistics(prefix + 'start')
+            stopstats = self._parse_shutdown_statistics(prefix + 'stop')
+        except AutotestHostRunError, e:
+            logging.error(e)
+            raise error.TestFail('Chrome OS shutdown metrics are missing')
+
+        results = {}
+        results['seconds_shutdown'] = stopstats[0] - startstats[0]
+        results['sectors_read_shutdown'] = stopstats[1] - startstats[1]
+        results['sectors_written_shutdown'] = stopstats[2] - startstats[2]
+        self.write_perf_keyval(results)