• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2 -u
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Exposes the FAFTClient interface over XMLRPC.
6
7It launches a XMLRPC server and exposes the functions in RPCRouter().
8"""
9import os
10from datetime import datetime
11from optparse import OptionParser
12from SimpleXMLRPCServer import SimpleXMLRPCServer
13
14import common
15from autotest_lib.client.cros.faft import rpc_functions
16from autotest_lib.client.cros.faft.utils import os_interface
17
18
19def main():
20    """The Main program, to run the XMLRPC server."""
21    parser = OptionParser(usage='Usage: %prog [options]')
22    parser.add_option(
23            '--port',
24            type='int',
25            dest='port',
26            default=9990,
27            help='port number of XMLRPC server')
28    (options, _) = parser.parse_args()
29
30    print '[%s] XMLRPC Server: Spinning up FAFT server' % str(datetime.now())
31    # Launch the XMLRPC server to provide FAFTClient commands.
32    os_if = os_interface.OSInterface()
33    os.chdir(os_if.state_dir)
34
35    router = rpc_functions.RPCRouter(os_if)
36
37    server = SimpleXMLRPCServer(('localhost', options.port),
38                                allow_none=True,
39                                logRequests=True)
40    server.register_introspection_functions()
41    server.register_instance(router)
42    print '[%s] XMLRPC Server: Serving FAFT functions on port %s' % (str(
43            datetime.now()), options.port)
44
45    server.serve_forever()
46
47
48if __name__ == '__main__':
49    main()
50