def METHOD_NAME(remote_ip, timeout=300):
    """
    Test for how long a target host went down.
    :param remote_ip: IP address or hostname of target host.
    :param timeout: For how long will return a timeout exception
                    if host is not recovered.
    :return: Time elapsed before target host is pingable.
    :raise TimeoutExpection: :
    """
    start_time = time.time()
    end_time = time.time() + timeout
    ping_cmd = 'ping -c 1 -W 1 ' + remote_ip
    logging.debug('Wait for host shutting down.')
    while True:
        if time.time() > end_time:
            raise TimeoutError(
                'Downtime %s exceeds maximum allowed %s' %
                (time.time() - start_time, timeout))
        res = process.run(ping_cmd, ignore_status=True, verbose=False, shell=True)
        if res.exit_status:
            logging.debug('Host %s is down.', remote_ip)
            break
        else:
            logging.debug('Host %s is up.', remote_ip)
            time.sleep(1)
    logging.debug('Time elapsed before host down: %.2fs',
                  (time.time() - start_time))
    logging.debug('Wait for host recover from sleep.')
    while True:
        if time.time() > end_time:
            raise TimeoutError(
                'Downtime %s exceeds maximum allowed %s' %
                (time.time() - start_time, timeout))
        res = process.run(ping_cmd, ignore_status=True, verbose=False, shell=True)
        if res.exit_status:
            logging.debug('Host %s is down.', remote_ip)
        else:
            logging.debug('Host %s is up.', remote_ip)
            break
    down_time = time.time() - start_time
    logging.debug('Time elapsed before host up: %.2fs', down_time)
    return down_time