Wait until psexec connection can be established.

def wait_for_psexecsvc(host, port, username, password, timeout=900):
    '''
    Wait until psexec connection can be established.
    '''
    if has_winexe() and not HAS_PSEXEC:
        return wait_for_winexe(host, port, username, password, timeout)
    start = time.time()
    try_count = 0
    while True:
        try_count += 1
        ret_code = 1
        try:
            stdout, stderr, ret_code = run_psexec_command(
                'cmd.exe', '/c hostname', host, username, password, port=port
            )
        except Exception as exc:
            log.exception("Unable to execute command")
        if ret_code == 0:
            log.debug('psexec connected...')
            return True
        if time.time() - start > timeout:
            return False
        log.debug(
            'Retrying psexec connection to host %s on port %s (try %s)',
            host, port, try_count
        )
        time.sleep(1)