| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """The registration server used to register tasks. | 5 """The registration server used to register tasks. |
| 6 | 6 |
| 7 The registration server is started by the test controller and allows the tasks | 7 The registration server is started by the test controller and allows the tasks |
| 8 to register themselves when they start. Authentication of the tasks controllers | 8 to register themselves when they start. Authentication of the tasks controllers |
| 9 is based on an OTP passed to the run_task binary on startup. | 9 is based on an OTP passed to the run_task binary on startup. |
| 10 """ | 10 """ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 cb = self._expected_tasks.pop(otp) | 32 cb = self._expected_tasks.pop(otp) |
| 33 cb(ip) | 33 cb(ip) |
| 34 | 34 |
| 35 def RegisterTaskCallback(self, otp, callback): | 35 def RegisterTaskCallback(self, otp, callback): |
| 36 """Registers a callback associated with an OTP.""" | 36 """Registers a callback associated with an OTP.""" |
| 37 assert callable(callback) | 37 assert callable(callback) |
| 38 self._expected_tasks[otp] = callback | 38 self._expected_tasks[otp] = callback |
| 39 | 39 |
| 40 def Start(self): | 40 def Start(self): |
| 41 """Starts the registration server.""" | 41 """Starts the registration server.""" |
| 42 logging.debug('Starting task registration server') | 42 logging.info('Starting task registration server') |
| 43 self._rpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( | 43 self._rpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( |
| 44 (common_lib.SERVER_ADDRESS, common_lib.SERVER_PORT), | 44 (common_lib.SERVER_ADDRESS, common_lib.SERVER_PORT), |
| 45 allow_none=True, logRequests=False) | 45 allow_none=True, logRequests=False) |
| 46 self._rpc_server.register_function( | 46 self._rpc_server.register_function( |
| 47 self._RegisterTaskRPC, 'RegisterTask') | 47 self._RegisterTaskRPC, 'RegisterTask') |
| 48 self._thread = threading.Thread(target=self._rpc_server.serve_forever) | 48 self._thread = threading.Thread(target=self._rpc_server.serve_forever) |
| 49 self._thread.start() | 49 self._thread.start() |
| 50 | 50 |
| 51 def Shutdown(self): | 51 def Shutdown(self): |
| 52 """Shuts the discovery server down.""" | 52 """Shuts the discovery server down.""" |
| 53 if self._thread and self._thread.is_alive(): | 53 if self._thread and self._thread.is_alive(): |
| 54 logging.debug('Shutting down task registration server') | 54 logging.info('Shutting down task registration server') |
| 55 self._rpc_server.shutdown() | 55 self._rpc_server.shutdown() |
| OLD | NEW |