def prepare_network_bench(bench, mode):
    global hosts_state
    nb_hosts = bench['nb-hosts']
    msg = HM(HM.MODULE, HM.NETWORK, mode)
    msg.network_test = bench['mode']
    msg.network_connection = bench['connection']
    msg.peer_servers = bench['ip-list'].items()
    msg.ports_list = bench['port-list']

    for hv in bench['hosts-list']:
        for host in bench['hosts-list'][hv]:
            if nb_hosts == 0:
                break
            if host not in get_host_list(NETWORK_RUN).keys():
                hosts_state[host] |= NETWORK_RUN
                nb_hosts = nb_hosts - 1
                lock_socket_list.acquire()
                msg.my_peer_name = bench['ip-list'][host]
                HP.send_hm_message(socket_list[host], msg)
                lock_socket_list.release()

    string_mode = ""
    if mode == HM.INIT:
        string_mode = "Initialisation"
    else:
        string_mode = "Cleaning"

    HP.logger.info("NETWORK: %s in progress" % string_mode)
    max_timeout = 45
    timeout = 0
    while (get_host_list(NETWORK_RUN).keys()):
        timeout = timeout + 1
        time.sleep(1)
        if timeout == max_timeout:
            HP.logger.error("NETWORK: Failed to %s the following hosts : " % string_mode + str(get_host_list(NETWORK_RUN).keys()))
            return False
    return True
dataset/ETHPy150Open redhat-cip/edeploy/src/health-server.py/prepare_network_bench/original