import time


def mongod_wait_for_primary(mongo, timeout=60, sleep_interval=3):
    """Return True if mongod primary is available in replica set, within the specified timeout."""

    start = time.time()
    while not mongo.admin.command("isMaster")["ismaster"]:
        time.sleep(sleep_interval)
        if time.time() - start >= timeout:
            return False
    return True