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 an XMLRPC server and exposes the functions in RPCRouter(). 8""" 9 10import logging 11import os 12from optparse import OptionParser 13 14import common 15from autotest_lib.client.cros import xmlrpc_server 16from autotest_lib.client.cros.faft.utils import os_interface 17from autotest_lib.client.common_lib import logging_config 18 19 20def main(): 21 """The Main program, to run the XMLRPC server.""" 22 parser = OptionParser(usage='Usage: %prog [options]') 23 parser.add_option( 24 '--port', 25 type='int', 26 dest='port', 27 default=9990, 28 help='port number of XMLRPC server') 29 (options, _) = parser.parse_args() 30 31 config = logging_config.LoggingConfig() 32 config.configure_logging(use_console=True, verbose=True) 33 34 logging.debug('faft.rpc_server[%s] main...', os.getpid()) 35 xmlrpc_server.terminate_old(__file__) 36 37 # Import after terminate, so old process is killed even if import fails 38 from autotest_lib.client.cros.faft import rpc_functions 39 40 # Launch the XMLRPC server to provide FAFTClient commands. 41 os_if = os_interface.OSInterface() 42 os.chdir(os_if.state_dir) 43 44 server = xmlrpc_server.XmlRpcServer('localhost', options.port) 45 router = rpc_functions.FaftXmlRpcDelegate(os_if) 46 server.register_delegate(router) 47 server.run() 48 logging.debug('faft.rpc_server[%s] done.\n', os.getpid()) 49 50 51if __name__ == '__main__': 52 main() 53