示例#1
0
def wait_for_flapping_host(hosts_service, dc_name, host_id=None):
    """
    There's a bug in oVirt that causes a freshly added host to reach
    'UP' status, switch to other status for a moment and then 'UP' back
    again. To handle this so called 'host flapping' we track the status
    of the hosts and wait some time for it to settle.
    """

    query = f'datacenter={dc_name} AND status={types.HostStatus.UP.value}'

    if host_id is not None:
        query += f' AND id={host_id}'

    hosts_up_seen = 0

    for _ in general_utils.linear_retrier(attempts=12, iteration_sleeptime=10):
        up_host_count = len(hosts_service.list(search=query))
        LOGGER.debug(f'Query: "{query}" found {up_host_count} hosts up')

        if up_host_count >= hosts_up_seen:
            if hosts_up_seen:
                return
            hosts_up_seen = up_host_count
        else:
            if hosts_up_seen > 0:
                LOGGER.warning('Host flapping detected!')
            hosts_up_seen = 0

    raise RuntimeError('Host flapping detection failed!')
def _wait_for_status(hosts_service, dc_name, status):
    up_status_seen = False
    for _ in general_utils.linear_retrier(attempts=12, iteration_sleeptime=10):
        all_hosts = hosts_service.list(search='datacenter={}'.format(dc_name))
        up_hosts = [host for host in all_hosts if host.status == status]
        LOGGER.info(_host_status_to_print(hosts_service, all_hosts))
        # we use up_status_seen because we make sure the status is not flapping
        if up_hosts:
            if up_status_seen:
                break
            up_status_seen = True
        else:
            up_status_seen = False
    return all_hosts
示例#3
0
def _wait_for_engine_command(engine, command):
    for _ in general_utils.linear_retrier(attempts=120, iteration_sleeptime=1):
        if _execute_on_engine(engine, command).code == 0:
            break
    else:
        raise Exception("Engine command didn't come up: %s" % (command, ))