OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 """The host controller base library. | |
5 | |
6 This module is the basis on which host controllers are built and executed. | |
7 """ | |
8 | |
9 import json | |
10 import logging | |
11 import sys | |
12 | |
13 #pylint: disable=relative-import | |
14 import client_lib | |
15 import common_lib | |
16 import discovery_server | |
17 | |
18 | |
19 class HostController(object): | |
20 """The base host controller class.""" | |
21 | |
22 clients = [] | |
23 | |
24 def __init__(self): | |
25 self._discovery_server = discovery_server.DiscoveryServer() | |
26 | |
27 def _SetUp(self): | |
28 """Perform private internal setup operations.""" | |
29 common_lib.InitLogging() | |
30 common_lib.LogCommandLine() | |
31 self._discovery_server.Start() | |
32 | |
33 def SetUp(self): | |
34 """Setup method used by the subclass.""" | |
35 pass | |
36 | |
37 def Test(self): | |
Marc-Antoine Ruel (Google)
2015/01/30 21:58:41
I'd prefer if you used Task instead of Test. Somet
Mike Meade
2015/02/03 01:18:09
Good idea. I wasn't sure of the best name for it.
| |
38 """Main test method used by the subclass.""" | |
39 pass | |
40 | |
41 def TearDown(self): | |
42 """Teardown method used by the subclass.""" | |
43 pass | |
44 | |
45 def _TearDown(self): | |
46 """Private internal teardown method.""" | |
47 self._discovery_server.Shutdown() | |
48 for client in self.clients: | |
49 client.Release() | |
50 | |
51 def NewClient(self, isolate_file): | |
52 """Creates a new client object given an isolate file. | |
53 | |
54 Args: | |
55 isolate_file: The path to an isolate file for the client machine. | |
56 | |
57 Returns: | |
58 A new client_lib.Client object. | |
59 """ | |
60 client = client_lib.Client(isolate_file, self._discovery_server) | |
61 self.clients.append(client) | |
62 return client | |
63 | |
64 def RunController(self): | |
65 """Main entry point for the controller.""" | |
66 error = None | |
67 tb = None | |
68 try: | |
69 self._SetUp() | |
70 self.SetUp() | |
71 self.Test() | |
72 except Exception, e: | |
73 # Defer raising exceptions until after TearDown and _TearDown are called. | |
74 error = e | |
75 tb = sys.exc_info()[-1] | |
76 try: | |
77 self.TearDown() | |
78 except Exception, e: | |
79 # Defer raising exceptions until after _TearDown is called. | |
80 # Note that an error raised here will obscure any errors raised | |
81 # previously. | |
82 error = e | |
83 tb = sys.exc_info()[-1] | |
84 | |
85 self._TearDown() | |
86 if error: | |
87 raise error, None, tb #pylint: disable=raising-bad-type | |
OLD | NEW |