Пример #1
0
def _dangling_proc(procstrlist):
    stdout, _, _ = ssh_output(['ps', 'aux'])
    for line in stdout.splitlines():
        for pstr in procstrlist:
            if pstr in line:
                return True
    return False
Пример #2
0
def _tunnel_runner(ttype, tunnel_args, args, delay=30):
    tunnel = _tunnel(ttype, tunnel_args)
    success = False
    endtime = time.time() + delay
    while time.time() < endtime:
        stdout, stderr, ret = ssh_output(args)
        stdout_str = stdout.decode()
        stderr_str = stderr.decode()
        print("tunnel runner query stdout: {}".format(stdout_str))
        print("tunnel runner query stderr: {}".format(stderr_str))
        if ret == 0 and json.loads(stdout.decode()) == {"pong": True}:
            success = True
            break

    if sys.platform == 'win32':
        os.kill(tunnel.pid, signal.CTRL_BREAK_EVENT)
    else:
        try:
            os.killpg(os.getpgid(tunnel.pid), signal.SIGTERM)
        except OSError:
            print("ERROR: Process did not exist")

    tout, terr = tunnel.communicate()
    print('Runner STDOUT: {}'.format(tout.decode()))
    print('Runner STDERR: {}'.format(terr.decode()))

    return (success, tunnel.returncode)
Пример #3
0
def _tunnel_runner(ttype, tunnel_args, args, delay=30):
    tunnel = _tunnel(ttype, tunnel_args)
    success = False
    endtime = time.time() + delay
    while time.time() < endtime:
        stdout, stderr, ret = ssh_output(args)
        stdout_str = stdout.decode()
        stderr_str = stderr.decode()
        print("tunnel runner query stdout: {}".format(stdout_str))
        print("tunnel runner query stderr: {}".format(stderr_str))
        if ret == 0 and json.loads(stdout.decode()) == {"pong": True}:
            success = True
            break

    if sys.platform == 'win32':
        os.kill(tunnel.pid, signal.CTRL_BREAK_EVENT)
    else:
        try:
            os.killpg(os.getpgid(tunnel.pid), signal.SIGTERM)
        except OSError:
            print("ERROR: Process did not exist")

    tout, terr = tunnel.communicate()
    print('Runner STDOUT: {}'.format(tout.decode()))
    print('Runner STDERR: {}'.format(terr.decode()))

    return (success, tunnel.returncode)
Пример #4
0
def _dangling_proc(procstrlist):
    stdout, _, _ = ssh_output(['ps', 'aux'])
    for line in stdout.splitlines():
        line = line.decode()
        for pstr in procstrlist:
            if pstr in line:
                return True
    return False
Пример #5
0
def _node_tunnel_runner(ttype, tunnel_args, args, delay=5, sudo=False):
    tunnel = _node_tunnel(ttype, tunnel_args, sudo=sudo)
    time.sleep(delay)
    stdout, stderr, ret = ssh_output(args)

    if sys.platform == 'win32':
        os.kill(tunnel.pid, signal.CTRL_BREAK_EVENT)
    else:
        os.killpg(os.getpgid(tunnel.pid), signal.SIGTERM)

    return (stdout, stderr, ret)
Пример #6
0
def _tunnel_runner(ttype, tunnel_args, args, delay=15):
    tunnel = _tunnel(ttype, tunnel_args)
    endtime = time.time() + delay
    while time.time() < endtime:
        stdout, stderr, ret = ssh_output(args)
        if ret == 0:
            break

    if sys.platform == 'win32':
        os.kill(tunnel.pid, signal.CTRL_BREAK_EVENT)
    else:
        try:
            os.killpg(os.getpgid(tunnel.pid), signal.SIGTERM)
        except OSError:
            print("ERROR: Process did not exist")

    tout, terr = tunnel.communicate()
    print('Runner STDOUT: {}'.format(tout.decode()))
    print('Runner STDERR: {}'.format(terr.decode()))

    return (stdout, stderr, ret, tunnel.returncode)
Пример #7
0
def _tunnel_runner(ttype, tunnel_args, args, delay=5, sudo=False):
    tunnel = _tunnel(ttype, tunnel_args, sudo=sudo)
    time.sleep(delay)
    stdout, stderr, ret = ssh_output(args)

    if sys.platform == 'win32':
        os.kill(tunnel.pid, signal.CTRL_BREAK_EVENT)
    else:
        if sudo:
            cmd = ("sudo python -c 'import os, signal; "
                   "os.killpg(os.getpgid({}), signal.SIGTERM)'").format(
                       tunnel.pid)
            subprocess.call(shlex.split(cmd))
        else:
            try:
                os.killpg(os.getpgid(tunnel.pid), signal.SIGTERM)
            except OSError:
                print("ERROR: Process did not exist")

    tout, terr = tunnel.communicate()
    print('Runner STDOUT: {}'.format(tout.decode('utf-8')))
    print('Runner STDERR: {}'.format(terr.decode('utf-8')))

    return (stdout, stderr, ret)