def launch_api_server(test_id, listen_ip, listen_port, http_server_port, admin_port, conf_sections): kombu_mock = mock.Mock() kombu_patch = mock.patch('vnc_cfg_api_server.api_server.KombuAmqpClient') kombu_init_mock = kombu_patch.start() kombu_init_mock.side_effect = kombu_mock args_str = "" args_str = args_str + "--listen_ip_addr %s " % (listen_ip) args_str = args_str + "--listen_port %s " % (listen_port) args_str = args_str + "--http_server_port %s " % (http_server_port) args_str = args_str + "--admin_port %s " % (admin_port) args_str = args_str + "--cassandra_server_list 0.0.0.0:9160 " args_str = args_str + "--log_local " args_str = args_str + "--log_file api_server_%s.log " % (test_id) args_str = args_str + "--cluster_id %s " % (test_id) vnc_cgitb.enable(format='text') with tempfile.NamedTemporaryFile(mode='w+') as conf, \ tempfile.NamedTemporaryFile(mode='w+') as logconf: cfg_parser = generate_conf_file_contents(conf_sections) cfg_parser.write(conf) conf.flush() cfg_parser = generate_logconf_file_contents() cfg_parser.write(logconf) logconf.flush() args_str = args_str + "--conf_file %s " % (conf.name) args_str = args_str + "--logging_conf %s " % (logconf.name) server = api_server.VncApiServer(args_str) gevent.getcurrent().api_server = server api_server.main(args_str, server)
def start(): print "start service" pid = os.getpid() #print "pid:%d" %pid #print "__file__" #print __file__ #print os.path.split(os.path.realpath(__file__)) path = os.path.split(os.path.realpath(__file__))[0] f = os.path.join(path, "api.pid") fp = open(f, "w") fp.writelines(str(pid)) fp.close() print "pid in " + f #os.system("/root/pre-online/pre_online/pre_online_api/api_server.py &") main()