コード例 #1
0
ファイル: subprocess.py プロジェクト: kentwills/pgctl
def run(cmd, **popen_args):
    """run the command, show the output, and return (stdout, stderr, returncode)"""
    from pgctl.subprocess import Popen, PIPE
    process = Popen(cmd, stdout=PIPE, stderr=PIPE, **popen_args)
    stdout, stderr = process.communicate()
    stdout, stderr = stdout.decode('UTF-8'), stderr.decode('UTF-8')
    show_both(stdout, stderr)
    return stdout, stderr, process.returncode
コード例 #2
0
def it_is_disallowed():
    assert_command(
        ('pgctl', 'start'),
        '',
        '''\
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
        0,
    )

    first = Popen(('pgctl', 'restart'), stdout=PIPE, stderr=PIPE)

    # slow-shutdown takes two seconds to shut down; aim for the middle:
    sleep(1)

    second = Popen(('pgctl', 'restart'), stdout=PIPE, stderr=PIPE)

    first_stdout, first_stderr = first.communicate()
    first_stdout, first_stderr = first_stdout.decode('UTF-8'), first_stderr.decode('UTF-8')
    show_both(first_stdout, first_stderr)
    assert norm.pgctl(first_stderr) == '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, its status is ready (pid {PID}) {TIME} seconds
==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/sweet/log
[pgctl] ERROR: Some services failed to stop: sweet
'''
    assert first_stdout == ''
    assert first.returncode == 1

    second_stdout, second_stderr = second.communicate()
    second_stdout, second_stderr = second_stdout.decode('UTF-8'), second_stderr.decode('UTF-8')
    show_both(second_stdout, second_stderr)
    assert norm.pgctl(second_stderr) == '''\
[pgctl] ERROR: another pgctl command is currently managing this service: (playground/sweet/.pgctl.lock)
{PS-HEADER}
{PS-STATS} ${PREFIX}/bin/python ${PREFIX}/bin/pgctl restart

'''
    assert second_stdout == ''
    assert second.returncode == 1
コード例 #3
0
def run(cmd, **popen_args):
    """run the command, show the output, and return (stdout, stderr, returncode)"""
    from pgctl.subprocess import Popen, PIPE
    process = Popen(cmd, stdout=PIPE, stderr=PIPE, **popen_args)
    stdout, stderr = process.communicate()
    stdout, stderr = stdout.decode('UTF-8'), stderr.decode('UTF-8')
    show_both(stdout, stderr)
    return stdout, stderr, process.returncode
コード例 #4
0
ファイル: parallel.py プロジェクト: kleopatra999/pgctl
def it_is_disallowed():
    assert_command(
        ('pgctl-2015', 'start'),
        '',
        '''\
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
        0,
    )

    first = Popen(('pgctl-2015', 'restart'), stdout=PIPE, stderr=PIPE)

    # slow-shutdown takes two seconds to shut down; aim for the middle:
    sleep(1)

    second = Popen(('pgctl-2015', 'restart'), stdout=PIPE, stderr=PIPE)

    first_stdout, first_stderr = first.communicate()
    first_stdout, first_stderr = first_stdout.decode('UTF-8'), first_stderr.decode('UTF-8')
    show_both(first_stdout, first_stderr)
    assert norm.pgctl(first_stderr) == '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, its status is ready (pid {PID}) {TIME} seconds
==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/sweet/log
[pgctl] ERROR: Some services failed to stop: sweet
'''
    assert first_stdout == ''
    assert first.returncode == 1

    second_stdout, second_stderr = second.communicate()
    second_stdout, second_stderr = second_stdout.decode('UTF-8'), second_stderr.decode('UTF-8')
    show_both(second_stdout, second_stderr)
    assert norm.pgctl(second_stderr) == '''\
[pgctl] ERROR: another pgctl command is currently managing this service: (playground/sweet/.pgctl.lock)
{PS-HEADER}
{PS-STATS} ${PREFIX}/bin/python ${PREFIX}/bin/pgctl-2015 restart

'''
    assert second_stdout == ''
    assert second.returncode == 1
コード例 #5
0
ファイル: debug.py プロジェクト: struys/pgctl
def it_disables_polling_heartbeat():
    from mock import patch
    with patch.dict(os.environ, [('PGCTL_TIMEOUT', '5')]):
        proc = Popen(('pgctl-2015', 'debug', 'slow-startup'), stdin=open(os.devnull), stdout=PIPE, stderr=PIPE)

    from testing.assertions import wait_for
    wait_for(lambda: assert_svstat('playground/slow-startup', state='ready'))

    check_call(('pgctl-2015', 'stop'))
    stdout, stderr = proc.communicate()
    stdout, stderr = stdout.decode('UTF-8'), stderr.decode('UTF-8')

    assert stderr == '''\
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
pgctl-poll-ready: service's ready check succeeded
pgctl-poll-ready: heartbeat is disabled during debug -- quitting
'''
    assert stdout == ''
    assert proc.returncode == 0