Index: testing/legion/host_controller.py |
diff --git a/testing/legion/host_controller.py b/testing/legion/host_controller.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..95ab35e9031d3d69bc99f57375d295edf2223804 |
--- /dev/null |
+++ b/testing/legion/host_controller.py |
@@ -0,0 +1,86 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+"""The host controller base library. |
+ |
+This module is the basis on which host controllers are built and executed. |
+""" |
+import json |
+import logging |
+import sys |
+ |
+#pylint: disable=relative-import |
+import client_lib |
+import common_lib |
+import discovery_server |
+ |
+ |
+class HostController(object): |
+ """The base host controller class.""" |
+ |
+ clients = [] |
+ |
+ def __init__(self): |
+ self._discovery_server = discovery_server.DiscoveryServer() |
+ |
+ def _SetUp(self): |
+ """Perform private internal setup operations.""" |
+ common_lib.InitLogging() |
+ common_lib.LogCommandLine() |
+ self._discovery_server.Start() |
+ |
+ def SetUp(self): |
+ """Setup method used by the subclass.""" |
+ pass |
+ |
+ def Test(self): |
+ """Main test method used by the subclass.""" |
+ pass |
+ |
+ def TearDown(self): |
+ """Teardown method used by the subclass.""" |
+ pass |
+ |
+ def _TearDown(self): |
+ """Private internal teardown method.""" |
+ self._discovery_server.Shutdown() |
+ for client in self.clients: |
+ client.Release() |
+ |
+ def NewClient(self, isolate_file): |
+ """Creates a new client object given an isolate file. |
+ |
+ Args: |
+ isolate_file: The path to an isolate file for the client machine. |
+ |
+ Returns: |
+ A new client_lib.Client object. |
+ """ |
+ client = client_lib.Client(isolate_file, self._discovery_server) |
+ self.clients.append(client) |
+ return client |
+ |
+ def RunController(self): |
+ """Main entry point for the controller.""" |
+ error = None |
+ tb = None |
+ try: |
+ self._SetUp() |
+ self.SetUp() |
+ self.Test() |
+ except Exception, e: |
+ # Defer raising exceptions until after TearDown and _TearDown are called. |
+ error = e |
+ tb = sys.exc_info()[-1] |
+ try: |
+ self.TearDown() |
+ except Exception, e: |
+ # Defer raising exceptions until after _TearDown is called. |
+ # Note that an error raised here will obscure any errors raised |
+ # previously. |
+ error = e |
+ tb = sys.exc_info()[-1] |
+ |
+ self._TearDown() |
+ if error: |
+ raise error, None, tb #pylint: disable=raising-bad-type |