Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1286)

Unified Diff: testing/legion/host_controller.py

Issue 890773003: Adding the initial code for Omnibot multi-machine support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing some silly subprocess code. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4ec4cb5fc7f64f94609f68452bf6623d8f00d698
--- /dev/null
+++ b/testing/legion/host_controller.py
@@ -0,0 +1,70 @@
+# 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.
+
+"""Defines the host controller base library.
+
+This module is the basis on which host controllers are built and executed.
+"""
+
+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."""
+
+ def __init__(self):
+ self._discovery_server = discovery_server.DiscoveryServer()
+
+ def SetUp(self):
+ """Setup method used by the subclass."""
+ pass
+
+ def Task(self):
+ """Main task method used by the subclass."""
+ pass
+
+ def TearDown(self):
+ """Teardown method used by the subclass."""
+ pass
+
+ def NewClient(self, *args, **kwargs):
+ controller = client_lib.ClientController(*args, **kwargs)
+ self._discovery_server.RegisterClientCallback(
+ controller.otp, controller.OnConnect)
+ return controller
+
+ def RunController(self):
+ """Main entry point for the controller."""
+ common_lib.PrintCommandLine()
+ common_lib.InitLogging()
+ self._discovery_server.Start()
+
+ error = None
+ tb = None
+ try:
+ self.SetUp()
+ self.Task()
+ except Exception, e:
M-A Ruel 2015/02/03 01:48:41 except Exception as e: everywhere
Mike Meade 2015/02/03 17:47:57 Old habits die hard. Not sure why I did this.
+ # 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._discovery_server.Shutdown()
+ client_lib.ClientController.ReleaseAllControllers()
+ if error:
+ raise error, None, tb #pylint: disable=raising-bad-type

Powered by Google App Engine
This is Rietveld 408576698