def wait_for_condition(condition_fn, *args, **kwargs):
    """
    Periodically calls condition_fn function passing args as positional
    arguments and kwargs as keyword arguments and terminate when this function
    will return True.
    If after timeout seconds function didn't terminate, TimeoutException is
    raised.
    :param condition_fn: predicate function
    :param timeout: for how many seconds to wait for condition_fn to return
                    True before raising TimeoutException
    :raise TimeoutException: when function didn't terminate after timeout
                             seconds
    """
    timeout = kwargs.pop('timeout', 60)
    delay = 1
    while delay <= timeout:
        if condition_fn(*args, **kwargs):
            break
        time.sleep(delay)
        delay *= 2
    else:
        raise exception.TimeoutException(None, None, "Timeout exp")


# TODO: move following function to utils and reuse in other parts of CloudFerry
dataset/ETHPy150Open MirantisWorkloadMobility/CloudFerry/cloudferry/lib/os/compute/cold_evacuate.py/wait_for_condition/original