<s> from SocketServer import BaseRequestHandler , ThreadingTCPServer <EOL> import ConfigParser <EOL> import socket <EOL> import struct <EOL> from health_messages import Health_Message as HM <EOL> import health_libs as HL <EOL> import health_protocol as HP <EOL> import logging <EOL> import os <EOL> import pprint <EOL> import sys <EOL> import threading <EOL> import time <EOL> import yaml <EOL> import math <EOL> import shutil <EOL> import getopt <EOL> socket_list = { } <EOL> lock_socket_list = threading . RLock ( ) <EOL> hosts = { } <EOL> lock_host = threading . RLock ( ) <EOL> hosts_state = { } <EOL> results_cpu = { } <EOL> results_memory = { } <EOL> results_network = { } <EOL> results_storage = { } <EOL> serv = <NUM_LIT:0> <EOL> startup_date = "<STR_LIT>" <EOL> NOTHING_RUN = <NUM_LIT:0> <EOL> CPU_RUN = <NUM_LIT:1> << <NUM_LIT:0> <EOL> MEMORY_RUN = <NUM_LIT:1> << <NUM_LIT:1> <EOL> STORAGE_RUN = <NUM_LIT:1> << <NUM_LIT:2> <EOL> NETWORK_RUN = <NUM_LIT:1> << <NUM_LIT:3> <EOL> SCHED_FAIR = "<STR_LIT>" <EOL> start_jitter = { } <EOL> stop_jitter = { } <EOL> running_jitter = False <EOL> average = lambda x : sum ( x ) * <NUM_LIT:1.0> / len ( x ) <EOL> variance = lambda x : map ( lambda y : ( y - average ( x ) ) ** <NUM_LIT:2> , x ) <EOL> stdev = lambda x : math . sqrt ( average ( variance ( x ) ) ) <EOL> def print_help ( ) : <EOL> print '<STR_LIT>' <EOL> print <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> def init_jitter ( ) : <EOL> global start_jitter <EOL> global stop_jitter <EOL> global running_jitter <EOL> start_jitter = { } <EOL> stop_jitter = { } <EOL> running_jitter = True <EOL> def disable_jitter ( ) : <EOL> global running_jitter <EOL> running_jitter = False <EOL> def start_time ( host ) : <EOL> timestamp = time . time ( ) <EOL> global start_jitter <EOL> if host not in start_jitter : <EOL> start_jitter [ host ] = [ timestamp ] <EOL> else : <EOL> start_jitter [ host ] . append ( timestamp ) <EOL> def stop_time ( host ) : <EOL> timestamp = time . time ( ) <EOL> global stop_jitter <EOL> stop_jitter [ host ] = timestamp <EOL> class SocketHandler ( BaseRequestHandler ) : <EOL> global hosts <EOL> global lock_host <EOL> timeout = <NUM_LIT:5> <EOL> disable_nagle_algorithm = False <EOL> def handle ( self ) : <EOL> lock_socket_list . acquire ( ) <EOL> socket_list [ self . client_address ] = self . request <EOL> lock_socket_list . release ( ) <EOL> HP . logger . debug ( '<STR_LIT>' % self . client_address [ <NUM_LIT:0> ] ) <EOL> while True : <EOL> msg = HP . recv_hm_message ( socket_list [ self . client_address ] ) <EOL> if not msg : <EOL> continue <EOL> if msg . message != HM . ACK : <EOL> if msg . action == HM . STARTING : <EOL> start_time ( self . client_address ) <EOL> continue <EOL> if msg . message == HM . DISCONNECT : <EOL> HP . logger . debug ( '<STR_LIT>' % <EOL> self . client_address [ <NUM_LIT:0> ] ) <EOL> lock_host . acquire ( ) <EOL> del hosts [ self . client_address ] <EOL> del hosts_state [ self . client_address ] <EOL> lock_host . release ( ) <EOL> socket_list [ self . client_address ] . close ( ) <EOL> lock_socket_list . acquire ( ) <EOL> del socket_list [ self . client_address ] <EOL> lock_socket_list . release ( ) <EOL> return <EOL> else : <EOL> lock_host . acquire ( ) <EOL> hosts [ self . client_address ] = msg <EOL> hosts_state [ self . client_address ] = NOTHING_RUN <EOL> lock_host . release ( ) <EOL> if msg . message == HM . MODULE and msg . action == HM . COMPLETED : <EOL> if running_jitter is True : <EOL> stop_time ( self . client_address ) <EOL> if msg . module == HM . CPU : <EOL> cpu_completed ( self . client_address , msg ) <EOL> elif msg . module == HM . MEMORY : <EOL> memory_completed ( self . client_address , msg ) <EOL> elif msg . module == HM . NETWORK : <EOL> network_completed ( self . client_address , msg ) <EOL> elif msg . module == HM . STORAGE : <EOL> storage_completed ( self . client_address , msg ) <EOL> def createAndStartServer ( ) : <EOL> global serv <EOL> ThreadingTCPServer . allow_reuse_address = True <EOL> serv = ThreadingTCPServer ( ( '<STR_LIT>' , <NUM_LIT> ) , SocketHandler , <EOL> bind_and_activate = False ) <EOL> l_onoff = <NUM_LIT:1> <EOL> l_linger = <NUM_LIT:0> <EOL> serv . socket . setsockopt ( socket . SOL_SOCKET , socket . SO_LINGER , <EOL> struct . pack ( '<STR_LIT>' , l_onoff , l_linger ) ) <EOL> serv . server_bind ( ) <EOL> serv . server_activate ( ) <EOL> HP . logger . info ( '<STR_LIT>' ) <EOL> serv . serve_forever ( ) <EOL> def cpu_completed ( host , msg ) : <EOL> global hosts_state <EOL> global results_cpu <EOL> hosts_state [ host ] &= ~ CPU_RUN <EOL> results_cpu [ host ] = msg . hw <EOL> def memory_completed ( host , msg ) : <EOL> global hosts_state <EOL> global results_memory <EOL> hosts_state [ host ] &= ~ MEMORY_RUN <EOL> results_memory [ host ] = msg . hw <EOL> def network_completed ( host , msg ) : <EOL> global hosts_state <EOL> global results_network <EOL> hosts_state [ host ] &= ~ NETWORK_RUN <EOL> results_network [ host ] = msg . hw <EOL> def storage_completed ( host , msg ) : <EOL> global hosts_state <EOL> global results_storage <EOL> hosts_state [ host ] &= ~ STORAGE_RUN <EOL> results_storage [ host ] = msg . hw <EOL> def get_host_list ( item ) : <EOL> global hosts <EOL> global hosts_state <EOL> selected_hosts = { } <EOL> for host in hosts . keys ( ) : <EOL> if hosts_state [ host ] & item == item : <EOL> selected_hosts [ host ] = True <EOL> return selected_hosts <EOL> def compute_affinity ( bench = [ ] ) : <EOL> affinity = { } <EOL> global hosts <EOL> def acceptable_host ( host_list , host ) : <EOL> if ( len ( host_list ) == <NUM_LIT:0> ) : <EOL> return True <EOL> if host in host_list : <EOL> return True <EOL> return False <EOL> for host in hosts . keys ( ) : <EOL> hw = hosts [ host ] . hw <EOL> system_id = HL . get_value ( hw , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if len ( bench ) > <NUM_LIT:0> : <EOL> if acceptable_host ( bench [ '<STR_LIT>' ] , system_id ) is False : <EOL> continue <EOL> if system_id not in affinity . keys ( ) : <EOL> affinity [ system_id ] = [ host ] <EOL> else : <EOL> affinity [ system_id ] . append ( host ) <EOL> return affinity <EOL> def get_fair_hosts_list ( affinity_hosts_list , nb_hosts ) : <EOL> hosts_list = [ ] <EOL> while ( len ( hosts_list ) < nb_hosts ) : <EOL> for hypervisor in affinity_hosts_list . keys ( ) : <EOL> if ( len ( affinity_hosts_list [ hypervisor ] ) == <NUM_LIT:0> ) : <EOL> return hosts_list <EOL> hosts_list . append ( affinity_hosts_list [ hypervisor ] . pop ( ) ) <EOL> if ( len ( hosts_list ) == nb_hosts ) : <EOL> break <EOL> return hosts_list <EOL> def get_fair_hosts_list_per_hv ( affinity_hosts_list , nb_hosts ) : <EOL> hosts_list = { } <EOL> for hypervisor in affinity_hosts_list . keys ( ) : <EOL> hosts_list [ hypervisor ] = [ ] <EOL> selected_hosts = <NUM_LIT:0> <EOL> while ( selected_hosts < nb_hosts ) : <EOL> for hypervisor in affinity_hosts_list . keys ( ) : <EOL> if ( len ( affinity_hosts_list [ hypervisor ] ) == <NUM_LIT:0> ) : <EOL> return hosts_list <EOL> hosts_list [ hypervisor ] . append ( affinity_hosts_list [ hypervisor ] . pop ( ) ) <EOL> selected_hosts = selected_hosts + <NUM_LIT:1> <EOL> if ( selected_hosts == nb_hosts ) : <EOL> break <EOL> return hosts_list <EOL> def get_hosts_list_from_affinity ( bench , sorted_list = False ) : <EOL> affinity_hosts_list = compute_affinity ( bench ) <EOL> hosts_list = [ ] <EOL> if bench [ '<STR_LIT>' ] == SCHED_FAIR : <EOL> if sorted_list is False : <EOL> hosts_list = get_fair_hosts_list ( affinity_hosts_list , bench [ '<STR_LIT>' ] ) <EOL> else : <EOL> hosts_list = get_fair_hosts_list_per_hv ( affinity_hosts_list , bench [ '<STR_LIT>' ] ) <EOL> else : <EOL> HP . logger . error ( "<STR_LIT>" % bench [ '<STR_LIT>' ] ) <EOL> return hosts_list <EOL> def dump_affinity ( bench , bench_type ) : <EOL> HP . logger . debug ( "<STR_LIT>" % bench [ '<STR_LIT>' ] ) <EOL> host_affinity = compute_affinity ( bench ) <EOL> final_list = { } <EOL> if bench_type == HM . NETWORK : <EOL> return bench [ '<STR_LIT>' ] <EOL> for hypervisor in host_affinity . keys ( ) : <EOL> for hostname in bench [ '<STR_LIT>' ] : <EOL> if hostname in host_affinity [ hypervisor ] : <EOL> if hypervisor not in final_list . keys ( ) : <EOL> final_list [ hypervisor ] = [ hostname ] <EOL> else : <EOL> final_list [ hypervisor ] . append ( hostname ) <EOL> return final_list <EOL> def start_cpu_bench ( bench ) : <EOL> global hosts_state <EOL> nb_hosts = bench [ '<STR_LIT>' ] <EOL> msg = HM ( HM . MODULE , HM . CPU , HM . START ) <EOL> msg . cpu_instances = bench [ '<STR_LIT>' ] <EOL> msg . running_time = bench [ '<STR_LIT>' ] <EOL> for host in bench [ '<STR_LIT>' ] : <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> break <EOL> if host not in get_host_list ( CPU_RUN ) . keys ( ) : <EOL> hosts_state [ host ] |= CPU_RUN <EOL> nb_hosts = nb_hosts - <NUM_LIT:1> <EOL> lock_socket_list . acquire ( ) <EOL> start_time ( host ) <EOL> HP . send_hm_message ( socket_list [ host ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> def start_memory_bench ( bench ) : <EOL> global hosts_state <EOL> nb_hosts = bench [ '<STR_LIT>' ] <EOL> msg = HM ( HM . MODULE , HM . MEMORY , HM . START ) <EOL> msg . cpu_instances = bench [ '<STR_LIT>' ] <EOL> msg . block_size = bench [ '<STR_LIT>' ] <EOL> msg . running_time = bench [ '<STR_LIT>' ] <EOL> msg . mode = bench [ '<STR_LIT>' ] <EOL> for host in bench [ '<STR_LIT>' ] : <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> break <EOL> if host not in get_host_list ( MEMORY_RUN ) . keys ( ) : <EOL> hosts_state [ host ] |= MEMORY_RUN <EOL> nb_hosts = nb_hosts - <NUM_LIT:1> <EOL> lock_socket_list . acquire ( ) <EOL> start_time ( host ) <EOL> HP . send_hm_message ( socket_list [ host ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> def start_storage_bench ( bench ) : <EOL> global hosts_state <EOL> nb_hosts = bench [ '<STR_LIT>' ] <EOL> msg = HM ( HM . MODULE , HM . STORAGE , HM . START ) <EOL> msg . block_size = bench [ '<STR_LIT>' ] <EOL> msg . access = bench [ '<STR_LIT>' ] <EOL> msg . running_time = bench [ '<STR_LIT>' ] <EOL> msg . mode = bench [ '<STR_LIT>' ] <EOL> msg . device = bench [ '<STR_LIT>' ] <EOL> msg . rampup_time = bench [ '<STR_LIT>' ] <EOL> for host in bench [ '<STR_LIT>' ] : <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> break <EOL> if host not in get_host_list ( STORAGE_RUN ) . keys ( ) : <EOL> hosts_state [ host ] |= STORAGE_RUN <EOL> nb_hosts = nb_hosts - <NUM_LIT:1> <EOL> lock_socket_list . acquire ( ) <EOL> start_time ( host ) <EOL> HP . send_hm_message ( socket_list [ host ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> def prepare_network_bench ( bench , mode ) : <EOL> global hosts_state <EOL> nb_hosts = bench [ '<STR_LIT>' ] <EOL> msg = HM ( HM . MODULE , HM . NETWORK , mode ) <EOL> msg . network_test = bench [ '<STR_LIT>' ] <EOL> msg . network_connection = bench [ '<STR_LIT>' ] <EOL> msg . peer_servers = bench [ '<STR_LIT>' ] . items ( ) <EOL> msg . ports_list = bench [ '<STR_LIT>' ] <EOL> for hv in bench [ '<STR_LIT>' ] : <EOL> for host in bench [ '<STR_LIT>' ] [ hv ] : <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> break <EOL> if host not in get_host_list ( NETWORK_RUN ) . keys ( ) : <EOL> hosts_state [ host ] |= NETWORK_RUN <EOL> nb_hosts = nb_hosts - <NUM_LIT:1> <EOL> lock_socket_list . acquire ( ) <EOL> msg . my_peer_name = bench [ '<STR_LIT>' ] [ host ] <EOL> HP . send_hm_message ( socket_list [ host ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> string_mode = "<STR_LIT>" <EOL> if mode == HM . INIT : <EOL> string_mode = "<STR_LIT>" <EOL> else : <EOL> string_mode = "<STR_LIT>" <EOL> HP . logger . info ( "<STR_LIT>" % string_mode ) <EOL> max_timeout = <NUM_LIT> <EOL> timeout = <NUM_LIT:0> <EOL> while ( get_host_list ( NETWORK_RUN ) . keys ( ) ) : <EOL> timeout = timeout + <NUM_LIT:1> <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if timeout == max_timeout : <EOL> HP . logger . error ( "<STR_LIT>" % string_mode + str ( get_host_list ( NETWORK_RUN ) . keys ( ) ) ) <EOL> return False <EOL> return True <EOL> def start_network_bench ( bench ) : <EOL> global hosts_state <EOL> nb_hosts = bench [ '<STR_LIT>' ] <EOL> msg = HM ( HM . MODULE , HM . NETWORK , HM . START ) <EOL> msg . block_size = bench [ '<STR_LIT>' ] <EOL> msg . running_time = bench [ '<STR_LIT>' ] <EOL> msg . network_test = bench [ '<STR_LIT>' ] <EOL> msg . network_connection = bench [ '<STR_LIT>' ] <EOL> msg . ports_list = bench [ '<STR_LIT>' ] <EOL> bench [ '<STR_LIT>' ] = [ ] <EOL> arity_group = [ ] <EOL> used_hosts = [ ] <EOL> ip_list = { } <EOL> while nb_hosts > <NUM_LIT:0> : <EOL> for hv in bench [ '<STR_LIT>' ] : <EOL> for host in bench [ '<STR_LIT>' ] [ hv ] : <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> break <EOL> if host in used_hosts : <EOL> continue <EOL> used_hosts . append ( host ) <EOL> arity_group . append ( host ) <EOL> ip_list [ host ] = bench [ '<STR_LIT>' ] [ host ] <EOL> nb_hosts = nb_hosts - <NUM_LIT:1> <EOL> if len ( arity_group ) == bench [ '<STR_LIT>' ] : <EOL> bench [ '<STR_LIT>' ] . append ( arity_group ) <EOL> msg . peer_servers = ip_list . items ( ) <EOL> for peer_server in arity_group : <EOL> if peer_server not in get_host_list ( NETWORK_RUN ) . keys ( ) : <EOL> msg . my_peer_name = bench [ '<STR_LIT>' ] [ peer_server ] <EOL> hosts_state [ peer_server ] |= NETWORK_RUN <EOL> lock_socket_list . acquire ( ) <EOL> start_time ( peer_server ) <EOL> HP . send_hm_message ( socket_list [ peer_server ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> arity_group = [ ] <EOL> ip_list = { } <EOL> break <EOL> if nb_hosts == <NUM_LIT:0> : <EOL> return <EOL> def disconnect_clients ( ) : <EOL> global serv <EOL> global hosts <EOL> msg = HM ( HM . DISCONNECT ) <EOL> HP . logger . info ( "<STR_LIT>" % len ( hosts . keys ( ) ) ) <EOL> for host in hosts . keys ( ) : <EOL> lock_socket_list . acquire ( ) <EOL> HP . send_hm_message ( socket_list [ host ] , msg ) <EOL> lock_socket_list . release ( ) <EOL> while ( hosts . keys ( ) ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> HP . logger . info ( "<STR_LIT>" % len ( hosts . keys ( ) ) ) <EOL> HP . logger . info ( "<STR_LIT>" ) <EOL> serv . shutdown ( ) <EOL> serv . socket . close ( ) <EOL> def save_hw ( items , name , hwdir ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> filename = os . path . join ( hwdir , name + '<STR_LIT>' ) <EOL> pprint . pprint ( items , stream = open ( filename , '<STR_LIT:w>' ) ) <EOL> except Exception , xcpt : <EOL> HP . logger . error ( "<STR_LIT>" % str ( xcpt ) ) <EOL> def dump_hosts ( log_dir ) : <EOL> global hosts <EOL> unique_hosts_list = [ ] <EOL> for host in hosts . keys ( ) : <EOL> uuid = HL . get_value ( hosts [ host ] . hw , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> if uuid not in unique_hosts_list : <EOL> unique_hosts_list . append ( uuid ) <EOL> pprint . pprint ( unique_hosts_list , stream = open ( log_dir + "<STR_LIT>" , '<STR_LIT:w>' ) ) <EOL> pprint . pprint ( compute_affinity ( ) , stream = open ( log_dir + "<STR_LIT>" , '<STR_LIT:w>' ) ) <EOL> def prepare_metrics ( log_dir , bench , bench_type ) : <EOL> dest_dir = log_dir + '<STR_LIT>' % bench [ '<STR_LIT>' ] <EOL> if bench_type == HM . CPU : <EOL> dest_dir = dest_dir + "<STR_LIT>" + bench [ '<STR_LIT:name>' ] <EOL> elif bench_type == HM . MEMORY : <EOL> dest_dir = dest_dir + "<STR_LIT>" + bench [ '<STR_LIT:name>' ] <EOL> elif bench_type == HM . NETWORK : <EOL> dest_dir = dest_dir + "<STR_LIT>" + bench [ '<STR_LIT:name>' ] <EOL> elif bench_type == HM . STORAGE : <EOL> dest_dir = dest_dir + "<STR_LIT>" + bench [ '<STR_LIT:name>' ] <EOL> else : <EOL> HL . fatal_error ( "<STR_LIT>" ) <EOL> try : <EOL> if not os . path . isdir ( dest_dir ) : <EOL> os . makedirs ( dest_dir ) <EOL> except OSError , e : <EOL> HL . fatal_error ( "<STR_LIT>" % ( dest_dir , e . errno ) ) <EOL> output = { } <EOL> output [ '<STR_LIT>' ] = bench <EOL> output [ '<STR_LIT>' ] = dump_affinity ( bench , bench_type ) <EOL> pprint . pprint ( output , stream = open ( dest_dir + "<STR_LIT>" , '<STR_LIT:w>' ) ) <EOL> return dest_dir <EOL> def compute_metrics ( dest_dir , bench , bench_type ) : <EOL> if bench_type == HM . CPU : <EOL> results = results_cpu <EOL> elif bench_type == HM . MEMORY : <EOL> results = results_memory <EOL> elif bench_type == HM . NETWORK : <EOL> results = results_network <EOL> elif bench_type == HM . STORAGE : <EOL> results = results_storage <EOL> else : <EOL> HL . fatal_error ( "<STR_LIT>" ) <EOL> delta_start_jitter = { } <EOL> duration = { } <EOL> real_start = { } <EOL> for host in results . keys ( ) : <EOL> if host not in start_jitter : <EOL> HP . logger . error ( "<STR_LIT>" % host ) <EOL> else : <EOL> if len ( start_jitter [ host ] ) < <NUM_LIT:2> : <EOL> HP . logger . error ( "<STR_LIT>" % host ) <EOL> else : <EOL> real_start [ host ] = start_jitter [ host ] [ <NUM_LIT:1> ] <EOL> delta_start_jitter [ host ] = ( start_jitter [ host ] [ <NUM_LIT:1> ] - start_jitter [ host ] [ <NUM_LIT:0> ] ) <EOL> duration [ host ] = ( stop_jitter [ host ] - start_jitter [ host ] [ <NUM_LIT:1> ] ) <EOL> if ( float ( duration [ host ] ) > float ( bench [ '<STR_LIT>' ] + <NUM_LIT:1> ) ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( host , duration [ host ] , bench [ '<STR_LIT>' ] ) ) <EOL> HP . logger . debug ( "<STR_LIT>" % str ( host ) ) <EOL> filename_and_macs = HL . generate_filename_and_macs ( results [ host ] ) <EOL> save_hw ( results [ host ] , filename_and_macs [ '<STR_LIT>' ] , dest_dir ) <EOL> output = { } <EOL> output [ '<STR_LIT>' ] = bench <EOL> output [ '<STR_LIT>' ] = results . keys ( ) <EOL> output [ '<STR_LIT>' ] = dump_affinity ( bench , bench_type ) <EOL> output [ '<STR_LIT>' ] = real_start <EOL> output [ '<STR_LIT>' ] = delta_start_jitter <EOL> output [ '<STR_LIT>' ] = duration <EOL> pprint . pprint ( output , stream = open ( dest_dir + "<STR_LIT>" , '<STR_LIT:w>' ) ) <EOL> def get_default_value ( job , item , default_value ) : <EOL> return job . get ( item , default_value ) <EOL> def prepare_log_dir ( name ) : <EOL> config = ConfigParser . ConfigParser ( ) <EOL> config . read ( '<STR_LIT>' ) <EOL> def config_get ( section , name , default ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> return config . get ( section , name ) <EOL> except ( ConfigParser . NoOptionError , ConfigParser . NoSectionError ) : <EOL> return default <EOL> cfg_dir = os . path . normpath ( config_get ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) + '<STR_LIT:/>' <EOL> dirname = startup_date <EOL> dest_dir = cfg_dir + '<STR_LIT>' % name + dirname <EOL> try : <EOL> if not os . path . isdir ( dest_dir ) : <EOL> os . makedirs ( dest_dir ) <EOL> except OSError , e : <EOL> HL . fatal_error ( "<STR_LIT>" % ( dest_dir , e . errno ) ) <EOL> HP . logger . info ( "<STR_LIT>" % dest_dir ) <EOL> return dest_dir <EOL> def compute_nb_hosts_series ( bench ) : <EOL> nb_hosts_series = [ ] <EOL> nb_hosts_series . append ( bench [ '<STR_LIT>' ] ) <EOL> for modulo in xrange ( <NUM_LIT:1> , divmod ( bench [ '<STR_LIT>' ] , bench [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] + <NUM_LIT:1> ) : <EOL> nb_hosts = modulo * bench [ '<STR_LIT>' ] <EOL> if nb_hosts > bench [ '<STR_LIT>' ] : <EOL> nb_hosts_series . append ( nb_hosts ) <EOL> if bench [ '<STR_LIT>' ] not in nb_hosts_series : <EOL> nb_hosts_series . append ( bench [ '<STR_LIT>' ] ) <EOL> return nb_hosts_series <EOL> def parse_job_config ( bench , job , component , log_dir ) : <EOL> bench [ '<STR_LIT>' ] = component <EOL> bench [ '<STR_LIT>' ] = get_default_value ( job , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> bench [ '<STR_LIT:name>' ] = get_default_value ( job , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> bench [ '<STR_LIT>' ] = get_default_value ( job , '<STR_LIT>' , SCHED_FAIR ) <EOL> bench [ '<STR_LIT>' ] = get_default_value ( job , '<STR_LIT>' , bench [ '<STR_LIT>' ] ) <EOL> affinity_list = get_default_value ( job , '<STR_LIT>' , '<STR_LIT>' ) <EOL> affinity_hosts = [ ] <EOL> if affinity_list : <EOL> for manual_host in affinity_list . split ( "<STR_LIT:U+002C>" ) : <EOL> affinity_hosts . append ( manual_host . strip ( ) ) <EOL> bench [ '<STR_LIT>' ] = affinity_hosts <EOL> if len ( bench [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> if len ( bench [ '<STR_LIT>' ] ) != len ( compute_affinity ( bench ) ) : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> HP . logger . error ( "<STR_LIT>" % ( len ( compute_affinity ( bench ) ) , len ( bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % log_dir ) <EOL> return False <EOL> required_hosts = get_default_value ( job , '<STR_LIT>' , <EOL> bench [ '<STR_LIT>' ] ) <EOL> if "<STR_LIT:->" in str ( required_hosts ) : <EOL> min_hosts = int ( str ( required_hosts ) . split ( "<STR_LIT:->" ) [ <NUM_LIT:0> ] ) <EOL> max_hosts = int ( str ( required_hosts ) . split ( "<STR_LIT:->" ) [ <NUM_LIT:1> ] ) <EOL> else : <EOL> min_hosts = required_hosts <EOL> max_hosts = min_hosts <EOL> if max_hosts < <NUM_LIT:1> : <EOL> max_hosts = min_hosts <EOL> HP . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % max_hosts ) <EOL> return False <EOL> if max_hosts > bench [ '<STR_LIT>' ] : <EOL> HP . logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return False <EOL> bench [ '<STR_LIT>' ] = min_hosts <EOL> bench [ '<STR_LIT>' ] = max_hosts <EOL> return True <EOL> def select_vms_from_networks ( bench ) : <EOL> port_add = <NUM_LIT:0> <EOL> port_list = { } <EOL> hosts_selected_ip = { } <EOL> for hv in bench [ '<STR_LIT>' ] : <EOL> for host in bench [ '<STR_LIT>' ] [ hv ] : <EOL> ipv4_list = HL . get_multiple_values ( hosts [ host ] . hw , "<STR_LIT>" , "<STR_LIT:*>" , "<STR_LIT>" ) <EOL> match_network = False <EOL> for ip in ipv4_list : <EOL> for network in bench [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if HL . is_in_network ( ip , network . strip ( ) ) : <EOL> hosts_selected_ip [ host ] = ip <EOL> port_list [ host ] = HM . port_base + port_add <EOL> port_add += <NUM_LIT:1> <EOL> match_network = True <EOL> if match_network is False : <EOL> bench [ '<STR_LIT>' ] [ hv ] . remove ( host ) <EOL> bench [ '<STR_LIT>' ] = port_list <EOL> bench [ '<STR_LIT>' ] = hosts_selected_ip <EOL> def do_network_job ( bench_all , current_job , log_dir , total_runtime ) : <EOL> bench = dict ( bench_all ) <EOL> bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> if parse_job_config ( bench , current_job , HM . NETWORK , log_dir ) is True : <EOL> if ( int ( bench [ '<STR_LIT>' ] ) != int ( bench [ '<STR_LIT>' ] ) ) : <EOL> if ( ( int ( bench [ '<STR_LIT>' ] ) % int ( bench [ '<STR_LIT>' ] ) ) != <NUM_LIT:0> ) : <EOL> HP . logger . error ( "<STR_LIT>" % int ( bench [ '<STR_LIT>' ] ) ) <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> return False <EOL> if ( ( int ( bench [ '<STR_LIT>' ] ) % int ( bench [ '<STR_LIT>' ] ) ) != <NUM_LIT:0> ) or ( ( int ( bench [ '<STR_LIT>' ] ) % int ( bench [ '<STR_LIT>' ] ) ) != <NUM_LIT:0> ) : <EOL> HP . logger . error ( "<STR_LIT>" % int ( bench [ '<STR_LIT>' ] ) ) <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> return False <EOL> nb_loops = <NUM_LIT:0> <EOL> hosts_series = compute_nb_hosts_series ( bench ) <EOL> for nb_hosts in hosts_series : <EOL> nb_loops = nb_loops + <NUM_LIT:1> <EOL> iter_bench = dict ( bench ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT:0>" ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , HM . BANDWIDTH ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT>" ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , HM . TCP ) <EOL> iter_bench [ '<STR_LIT>' ] = nb_hosts <EOL> total_runtime += iter_bench [ '<STR_LIT>' ] <EOL> iter_bench [ '<STR_LIT>' ] = get_hosts_list_from_affinity ( iter_bench , True ) <EOL> unsorted_list = get_hosts_list_from_affinity ( iter_bench ) <EOL> if ( len ( unsorted_list ) < iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( unsorted_list ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> select_vms_from_networks ( iter_bench ) <EOL> if ( len ( iter_bench [ '<STR_LIT>' ] ) < iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> if ( nb_hosts % iter_bench [ '<STR_LIT>' ] != <NUM_LIT:0> ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> metrics_log_dir = prepare_metrics ( log_dir , iter_bench , HM . NETWORK ) <EOL> if prepare_network_bench ( iter_bench , HM . INIT ) is False : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> prepare_network_bench ( iter_bench , HM . CLEAN ) <EOL> continue <EOL> if iter_bench [ '<STR_LIT>' ] != "<STR_LIT:0>" : <EOL> HP . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , nb_loops , len ( hosts_series ) , <EOL> iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> HP . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , nb_loops , len ( hosts_series ) , <EOL> iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] ) ) <EOL> init_jitter ( ) <EOL> start_network_bench ( iter_bench ) <EOL> time . sleep ( bench [ '<STR_LIT>' ] ) <EOL> while ( get_host_list ( NETWORK_RUN ) . keys ( ) ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> disable_jitter ( ) <EOL> compute_metrics ( metrics_log_dir , iter_bench , HM . NETWORK ) <EOL> prepare_network_bench ( iter_bench , HM . CLEAN ) <EOL> else : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> def do_storage_job ( bench_all , current_job , log_dir , total_runtime ) : <EOL> bench = dict ( bench_all ) <EOL> if parse_job_config ( bench , current_job , HM . STORAGE , log_dir ) is True : <EOL> nb_loops = <NUM_LIT:0> <EOL> hosts_series = compute_nb_hosts_series ( bench ) <EOL> for nb_hosts in hosts_series : <EOL> nb_loops = nb_loops + <NUM_LIT:1> <EOL> iter_bench = dict ( bench ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT>" ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , HM . RANDOM ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , HM . READ ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT>" ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT:5>" ) <EOL> iter_bench [ '<STR_LIT>' ] = nb_hosts <EOL> total_runtime += iter_bench [ '<STR_LIT>' ] <EOL> iter_bench [ '<STR_LIT>' ] = get_hosts_list_from_affinity ( iter_bench ) <EOL> if ( iter_bench [ '<STR_LIT>' ] > iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % <EOL> ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> return <EOL> if ( len ( iter_bench [ '<STR_LIT>' ] ) < iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> HP . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] , nb_loops , len ( hosts_series ) , <EOL> iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] ) ) <EOL> metrics_log_dir = prepare_metrics ( log_dir , iter_bench , HM . STORAGE ) <EOL> init_jitter ( ) <EOL> start_storage_bench ( iter_bench ) <EOL> time . sleep ( bench [ '<STR_LIT>' ] ) <EOL> while ( get_host_list ( STORAGE_RUN ) . keys ( ) ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> disable_jitter ( ) <EOL> compute_metrics ( metrics_log_dir , iter_bench , HM . STORAGE ) <EOL> else : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> def do_memory_job ( bench_all , current_job , log_dir , total_runtime ) : <EOL> bench = dict ( bench_all ) <EOL> if parse_job_config ( bench , current_job , HM . MEMORY , log_dir ) is True : <EOL> nb_loops = <NUM_LIT:0> <EOL> hosts_series = compute_nb_hosts_series ( bench ) <EOL> for nb_hosts in hosts_series : <EOL> nb_loops = nb_loops + <NUM_LIT:1> <EOL> iter_bench = dict ( bench ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , "<STR_LIT>" ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , HM . FORKED ) <EOL> iter_bench [ '<STR_LIT>' ] = nb_hosts <EOL> total_runtime += iter_bench [ '<STR_LIT>' ] <EOL> iter_bench [ '<STR_LIT>' ] = get_hosts_list_from_affinity ( iter_bench ) <EOL> if ( len ( iter_bench [ '<STR_LIT>' ] ) < iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> HP . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , nb_loops , len ( hosts_series ) , <EOL> iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] ) ) <EOL> metrics_log_dir = prepare_metrics ( log_dir , iter_bench , HM . MEMORY ) <EOL> init_jitter ( ) <EOL> start_memory_bench ( iter_bench ) <EOL> time . sleep ( bench [ '<STR_LIT>' ] ) <EOL> while ( get_host_list ( MEMORY_RUN ) . keys ( ) ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> disable_jitter ( ) <EOL> compute_metrics ( metrics_log_dir , iter_bench , HM . MEMORY ) <EOL> else : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> def do_cpu_job ( bench_all , current_job , log_dir , total_runtime ) : <EOL> bench = dict ( bench_all ) <EOL> if parse_job_config ( bench , current_job , HM . CPU , log_dir ) is True : <EOL> nb_loops = <NUM_LIT:0> <EOL> hosts_series = compute_nb_hosts_series ( bench ) <EOL> for nb_hosts in hosts_series : <EOL> nb_loops = nb_loops + <NUM_LIT:1> <EOL> iter_bench = dict ( bench ) <EOL> iter_bench [ '<STR_LIT>' ] = get_default_value ( current_job , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> iter_bench [ '<STR_LIT>' ] = nb_hosts <EOL> total_runtime += iter_bench [ '<STR_LIT>' ] <EOL> iter_bench [ '<STR_LIT>' ] = get_hosts_list_from_affinity ( iter_bench ) <EOL> if ( len ( iter_bench [ '<STR_LIT>' ] ) < iter_bench [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( iter_bench [ '<STR_LIT>' ] , len ( iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" % ( ( iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] ) ) ) <EOL> continue <EOL> HP . logger . info ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( nb_loops , len ( hosts_series ) , <EOL> iter_bench [ '<STR_LIT>' ] , iter_bench [ '<STR_LIT>' ] , <EOL> iter_bench [ '<STR_LIT>' ] ) ) <EOL> metrics_log_dir = prepare_metrics ( log_dir , iter_bench , HM . CPU ) <EOL> init_jitter ( ) <EOL> start_cpu_bench ( iter_bench ) <EOL> time . sleep ( bench [ '<STR_LIT>' ] ) <EOL> while ( get_host_list ( CPU_RUN ) . keys ( ) ) : <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> disable_jitter ( ) <EOL> compute_metrics ( metrics_log_dir , iter_bench , HM . CPU ) <EOL> else : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> def non_interactive_mode ( filename , title ) : <EOL> global hosts <EOL> total_runtime = <NUM_LIT:0> <EOL> name = "<STR_LIT>" <EOL> bench_all = { } <EOL> bench_all [ '<STR_LIT:title>' ] = title <EOL> job = yaml . load ( file ( filename , '<STR_LIT:r>' ) ) <EOL> if job [ '<STR_LIT:name>' ] is None : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> disconnect_clients ( ) <EOL> return <EOL> else : <EOL> name = job [ '<STR_LIT:name>' ] <EOL> if job [ '<STR_LIT>' ] is None : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> disconnect_clients ( ) <EOL> return <EOL> bench_all [ '<STR_LIT>' ] = int ( job [ '<STR_LIT>' ] ) <EOL> if bench_all [ '<STR_LIT>' ] < <NUM_LIT:1> : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> disconnect_clients ( ) <EOL> return <EOL> bench_all [ '<STR_LIT>' ] = get_default_value ( job , '<STR_LIT>' , <NUM_LIT:10> ) <EOL> bench_all [ '<STR_LIT>' ] = get_default_value ( job , '<STR_LIT>' , <NUM_LIT:0> ) <EOL> log_dir = prepare_log_dir ( name ) <EOL> shutil . copy2 ( filename , log_dir ) <EOL> if ( int ( bench_all [ '<STR_LIT>' ] ) > <NUM_LIT:0> ) : <EOL> HP . logger . info ( "<STR_LIT>" % <EOL> ( bench_all [ '<STR_LIT>' ] , int ( bench_all [ '<STR_LIT>' ] ) , <EOL> name ) ) <EOL> else : <EOL> HP . logger . info ( "<STR_LIT>" % <EOL> ( bench_all [ '<STR_LIT>' ] , name ) ) <EOL> hosts_count = len ( hosts . keys ( ) ) <EOL> previous_hosts_count = hosts_count <EOL> while ( int ( hosts_count ) < bench_all [ '<STR_LIT>' ] ) : <EOL> if ( hosts_count != previous_hosts_count ) : <EOL> HP . logger . info ( "<STR_LIT>" % ( bench_all [ '<STR_LIT>' ] - int ( hosts_count ) ) ) <EOL> previous_hosts_count = hosts_count <EOL> dump_hosts ( log_dir ) <EOL> hosts_count = len ( hosts . keys ( ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> dump_hosts ( log_dir ) <EOL> if len ( compute_affinity ( ) ) < int ( bench_all [ '<STR_LIT>' ] ) : <EOL> HP . logger . error ( "<STR_LIT>" % ( bench_all [ '<STR_LIT>' ] , len ( compute_affinity ( ) ) ) ) <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> disconnect_clients ( ) <EOL> return <EOL> HP . logger . info ( "<STR_LIT>" % name ) <EOL> for next_job in job [ '<STR_LIT>' ] : <EOL> HP . logger . info ( "<STR_LIT>" % next_job ) <EOL> global results_network <EOL> global results_cpu <EOL> global results_memory <EOL> global results_storage <EOL> results_network = { } <EOL> results_cpu = { } <EOL> results_memory = { } <EOL> results_storage = { } <EOL> current_job = job [ '<STR_LIT>' ] [ next_job ] <EOL> current_job [ '<STR_LIT:name>' ] = next_job <EOL> if '<STR_LIT>' not in current_job . keys ( ) : <EOL> HP . logger . error ( "<STR_LIT>" % current_job [ '<STR_LIT:name>' ] ) <EOL> continue <EOL> if "<STR_LIT>" in current_job [ '<STR_LIT>' ] : <EOL> do_cpu_job ( bench_all , current_job , log_dir , total_runtime ) <EOL> if "<STR_LIT>" in current_job [ '<STR_LIT>' ] : <EOL> do_memory_job ( bench_all , current_job , log_dir , total_runtime ) <EOL> if "<STR_LIT>" in current_job [ '<STR_LIT>' ] : <EOL> do_network_job ( bench_all , current_job , log_dir , total_runtime ) <EOL> if "<STR_LIT>" in current_job [ '<STR_LIT>' ] : <EOL> do_storage_job ( bench_all , current_job , log_dir , total_runtime ) <EOL> HP . logger . info ( "<STR_LIT>" % name ) <EOL> HP . logger . info ( "<STR_LIT>" % log_dir ) <EOL> disconnect_clients ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> HP . start_log ( '<STR_LIT>' , logging . INFO ) <EOL> input_file = "<STR_LIT>" <EOL> title = "<STR_LIT>" <EOL> startup_date = time . strftime ( "<STR_LIT>" , time . localtime ( ) ) <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , "<STR_LIT>" , [ '<STR_LIT:file>' , '<STR_LIT:title>' ] ) <EOL> except getopt . GetoptError : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> for opt , arg in opts : <EOL> if opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> print_help ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> input_file = arg <EOL> elif opt in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> title = arg <EOL> if not input_file : <EOL> HP . logger . error ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if not title : <EOL> title = startup_date <EOL> HP . logger . info ( "<STR_LIT>" % title ) <EOL> myThread = threading . Thread ( target = createAndStartServer ) <EOL> myThread . start ( ) <EOL> non_interactive = threading . Thread ( target = non_interactive_mode , <EOL> args = tuple ( [ input_file , title ] ) ) <EOL> non_interactive . start ( ) </s>
