Exemple #1
0
def it_times_out():
    assert_command(
        ('pgctl', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/slow-startup/log
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Exemple #2
0
def it_fails_with_multiple_services():
    assert_command(
        ('pgctl', 'debug', 'abc', 'def'),
        '',
        '[pgctl] ERROR: Must debug exactly one service, not: abc, def\n',
        1,
    )
Exemple #3
0
    def it_shows_error_on_stop_for_sweet(self):
        assert_command(
            ('pgctl-2015', 'start', 'sweet'),
            '',
            '''\
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
            0,
        )
        assert_command(
            ('pgctl-2015', 'restart', 'sweet'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep infinity

There are two ways you can fix this:
  * temporarily: lsof -t playground/sweet | xargs kill -9
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Exemple #4
0
def it_times_out():
    assert_command(
        ('pgctl-2015', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/slow-startup/log
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Exemple #5
0
 def it_can_detect_cycles(self, in_example_dir):
     assert_command(
         ('pgctl', 'start', 'b'),
         '',
         "[pgctl] ERROR: Circular aliases! Visited twice during alias expansion: 'b'\n",
         1,
     )
Exemple #6
0
    def it_can_be_run_via_python_m(self, tmpdir):
        a = tmpdir.ensure_dir('a')
        b = a.ensure_dir('b')
        c = b.ensure_dir('c')

        prefix = str(uuid.uuid4())
        tmpdir.ensure(prefix + '.ini')
        a.ensure(prefix + '.yaml')
        b.ensure(prefix + '.conf')
        c.ensure(prefix + '.a')
        c.ensure(prefix + '.b')

        with c.as_cwd():
            assert_command(
                (executable, '-m', 'pgctl.configsearch', prefix + '*'),
                '''\
{tmpdir}/a/b/c/{prefix}.a
{tmpdir}/a/b/c/{prefix}.b
{tmpdir}/a/b/{prefix}.conf
{tmpdir}/a/{prefix}.yaml
{tmpdir}/{prefix}.ini
'''.format(tmpdir=tmpdir.strpath, prefix=prefix),
                '',
                0,
            )
Exemple #7
0
    def it_shows_error_on_stop_for_slow_start(self):
        assert_command(
            ('pgctl', 'start', 'slow-startup'),
            '',
            '''\
[pgctl] Starting: slow-startup
[pgctl] Started: slow-startup
''',
            0,
        )
        assert_command(
            ('pgctl', 'restart', 'slow-startup'),
            '',
            '''\
[pgctl] Stopping: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep 987654

There are two ways you can fix this:
  * temporarily: lsof -t playground/slow-startup | xargs kill -9
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/slow-startup/log
[pgctl] ERROR: Some services failed to stop: slow-startup
''',
            1,
            norm=norm.pgctl,
        )
Exemple #8
0
    def it_shows_stdout_and_stderr(self, in_example_dir):
        check_call(('pgctl', 'start', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/logs/current <==

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('pgctl', 'restart', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/logs/current <==

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #9
0
    def it_runs_before_starting_a_service(self):
        assert_command(
            ('pgctl', 'start'),
            '',
            '''\
hello, i am a pre-start script
--> $PWD basename: pre-start-hook
--> cwd basename: pre-start-hook
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
            0,
            norm=norm.pgctl,
        )

        # starting when already up doesn't trigger pre-start to run again
        assert_command(
            ('pgctl', 'start'),
            '',
            '''\
[pgctl] Already started: sweet
''',
            0,
            norm=norm.pgctl,
        )
Exemple #10
0
 def it_can_detect_cycles(self, in_example_dir):
     assert_command(
         ('pgctl', 'start', 'b'),
         '',
         "[pgctl] ERROR: Circular aliases! Visited twice during alias expansion: 'b'\n",
         1,
     )
Exemple #11
0
    def it_can_accept_different_environment_variables(self, in_example_dir):
        check_call(('sh', '-c', 'MYVAR=ohhi pgctl start'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/environment/logs/current <==
{TIMESTAMP} ohhi
''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('sh', '-c', 'MYVAR=bye pgctl restart'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/environment/logs/current <==
{TIMESTAMP} ohhi
{TIMESTAMP} bye
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #12
0
    def it_can_still_show_help(self, tmpdir):
        with tmpdir.as_cwd():
            assert_command(
                ('pgctl', '--help'),
                '''\
usage: pgctl [-h] [--version] [--pgdir PGDIR] [--pghome PGHOME] [--json]
             [--all]
             {start,stop,status,restart,reload,log,debug,config}
             [services [services ...]]

positional arguments:
  {start,stop,status,restart,reload,log,debug,config}
                        specify what action to take
  services              specify which services to act upon

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --pgdir PGDIR         name the playground directory
  --pghome PGHOME       directory to keep user-level playground state
  --json                output in JSON (only supported by some commands)
  --all, -a             act upon all services
''',
                '',
                0,
            )
Exemple #13
0
def it_restarts_on_unready():

    def it_is_ready():
        assert_svstat('playground/slow-startup', state='ready')

    def it_becomes_unready():
        from testfixtures import Comparison as C
        from pgctl.daemontools import svstat
        assert svstat('playground/slow-startup') != C(SvStat, {'state': 'ready'}, strict=False)

    it_can_succeed()
    os.remove('playground/slow-startup/readyfile')
    wait_for(it_becomes_unready)
    wait_for(it_is_ready)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} pgctl-poll-ready: service's ready check failed -- we are restarting it for you
{TIMESTAMP} [pgctl] Stopping: slow-startup
{TIMESTAMP} [pgctl] Stopped: slow-startup
{TIMESTAMP} [pgctl] Starting: slow-startup
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} [pgctl] Started: slow-startup
''',
        '',
        0,
        norm=norm.pgctl,
    )
Exemple #14
0
    def it_can_be_run_via_python_m(self, tmpdir):
        from sys import executable
        expected_output = '''\
{
    "app": "app",
    "app/a": "app/a",
    "app/b": "app/b",
    "apps": [
        "1",
        "2",
        "3"
    ],
    "environ": "environ",
    "environs": [
        "1",
        "2",
        "3"
    ],
    "etc": "etc",
    "home": "home"
}
'''
        with setup(tmpdir):
            assert_command(
                (executable, '-m', 'pgctl.config', 'my'),
                expected_output,
                '',
                0,
                norm=norm_trailing_whitespace_json,
            )
Exemple #15
0
def it_times_out():
    assert_command(
        ('pgctl-2015', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Exemple #16
0
    def it_shows_error_on_stop_for_sweet(self):
        check_call(('pgctl', 'start', 'sweet'))
        assert_command(
            ('pgctl', 'restart', 'sweet'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep infinity

There are two ways you can fix this:
  * temporarily: pgctl stop sweet --force
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> playground/sweet/logs/current <==
{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/logs/current
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Exemple #17
0
    def it_starts_up_fine(self):
        assert_command(
            ('pgctl', 'start'),
            '',
            '''\
[pgctl] Starting: slow-startup, sweet
[pgctl] Started: sweet
[pgctl] Started: slow-startup
''',
            0,
        )
        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/slow-startup/logs/current <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #18
0
def it_fails_twice_but_doesnt_restart():

    def it_is_ready():
        assert_svstat('playground/unreliable', state='ready')

    assert_command(
        ('pgctl-2015', 'start'),
        '',
        '[pgctl] Starting: unreliable\n[pgctl] Started: unreliable\n',
        0
    )
    wait_for(it_is_ready)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/unreliable/log <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} pgctl-poll-ready: failed (restarting in 2.00 seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in 1.99 seconds)
''',
        '',
        0,
        norm=norm.timestamp,
    )
Exemple #19
0
def assert_does_not_find(path):
    assert_command(
        ('pgctl-fuser', path),
        '',
        '',
        0,
    )
Exemple #20
0
    def it_works(self, in_example_dir):
        assert_command(
            ('pgctl', 'start', 'A'),
            '',
            '''\
[pgctl] Starting: A
[pgctl] Started: A
''',
            0,
        )
        wait_for(lambda: assert_command(
            ('pgctl', 'log', 'A'),
            '''\
==> playground/A/logs/current <==
{TIMESTAMP} [pgctl] Starting: B
{TIMESTAMP} [pgctl] DEBUG: parentlock: '%s/playground/A'
{TIMESTAMP} [pgctl] DEBUG: LOCK: ${LOCK}
{TIMESTAMP} [pgctl] DEBUG: loop: check_time $TIME
{TIMESTAMP} [pgctl] Started: B
{TIMESTAMP} this is stdout
{TIMESTAMP} this is stderr
''' % in_example_dir,
            '',
            0,
            norm=norm.pgctl,
        ))
        assert_command(
            ('pgctl', 'stop', 'A'),
            '',
            '''\
[pgctl] Stopping: A
[pgctl] Stopped: A
''',
            0,
        )
Exemple #21
0
    def it_works(self, in_example_dir):
        assert_command(
            ('pgctl', 'start', 'A'),
            '',
            '''\
[pgctl] Starting: A
[pgctl] Started: A
''',
            0,
        )
        wait_for(lambda: assert_command(
            ('pgctl', 'log', 'A'),
            '''\
==> playground/A/log <==
{TIMESTAMP} [pgctl] Starting: B
{TIMESTAMP} [pgctl] DEBUG: parentlock: '%s/playground/A'
{TIMESTAMP} [pgctl] DEBUG: LOCK: ${LOCK}
{TIMESTAMP} [pgctl] DEBUG: loop: check_time $TIME
{TIMESTAMP} [pgctl] Started: B
{TIMESTAMP} this is stdout
{TIMESTAMP} this is stderr
''' % in_example_dir,
            '',
            0,
            norm=norm.pgctl,
        ))
        assert_command(
            ('pgctl', 'stop', 'A'),
            '',
            '''\
[pgctl] Stopping: A
[pgctl] Stopped: A
''',
            0,
        )
Exemple #22
0
    def it_can_still_show_config(self, tmpdir):
        expected_output = '''\
{
    "aliases": {
        "default": [
            "(all services)"
        ]
    },
    "command": "config",
    "pgdir": "playground",
    "pghome": "~/.run/pgctl",
    "poll": ".01",
    "services": [
        "default"
    ],
    "timeout": "2.0"
}
'''

        with tmpdir.as_cwd():
            assert_command(
                ('pgctl', 'config'),
                expected_output,
                '',
                0,
                norm=norm_trailing_whitespace_json,
            )
Exemple #23
0
    def it_can_be_run_via_python_m(self, tmpdir):
        from sys import executable
        expected_output = '''\
{
    "app": "app",
    "app/a": "app/a",
    "app/b": "app/b",
    "apps": [
        "1",
        "2",
        "3"
    ],
    "environ": "environ",
    "environs": [
        "1",
        "2",
        "3"
    ],
    "etc": "etc",
    "home": "home"
}
'''
        with setup(tmpdir):
            assert_command(
                (executable, '-m', 'pgctl.config', 'my'),
                expected_output,
                '',
                0,
                norm=norm_trailing_whitespace_json,
            )
Exemple #24
0
    def it_runs_before_starting_a_service(self):
        assert_command(
            ('pgctl', 'start'),
            'hello, i am a pre-start script in stdout\n',
            '''\
hello, i am a pre-start script in stderr
--> $PWD basename: pre-start-hook
--> cwd basename: pre-start-hook
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
            0,
            norm=norm.pgctl,
        )

        # starting when already up doesn't trigger pre-start to run again
        assert_command(
            ('pgctl', 'start'),
            '',
            '''\
[pgctl] Already started: sweet
''',
            0,
            norm=norm.pgctl,
        )
Exemple #25
0
    def it_starts_up_fine(self):
        assert_command(
            ('pgctl', 'start'),
            '',
            '''\
[pgctl] Starting: slow-startup, sweet
[pgctl] Started: sweet
[pgctl] Started: slow-startup
''',
            0,
        )
        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #26
0
    def it_shows_error_on_stop_for_slow_start(self):
        assert_command(
            ('pgctl-2015', 'start', 'slow-startup'),
            '',
            '''\
[pgctl] Starting: slow-startup
[pgctl] Started: slow-startup
''',
            0,
        )
        assert_command(
            ('pgctl-2015', 'restart', 'slow-startup'),
            '',
            '''\
[pgctl] Stopping: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep 987654

There are two ways you can fix this:
  * temporarily: lsof -t playground/slow-startup | xargs kill -9
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
[pgctl] ERROR: Some services failed to stop: slow-startup
''',
            1,
            norm=norm.pgctl,
        )
Exemple #27
0
    def it_shows_error_on_stop_for_sweet(self):
        assert_command(
            ('pgctl', 'start', 'sweet'),
            '',
            '''\
[pgctl] Starting: sweet
[pgctl] Started: sweet
''',
            0,
        )
        assert_command(
            ('pgctl', 'restart', 'sweet'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep infinity

There are two ways you can fix this:
  * temporarily: lsof -t playground/sweet | xargs kill -9
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> 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
''',
            1,
            norm=norm.pgctl,
        )
Exemple #28
0
    def it_can_still_show_help(self, tmpdir):
        with tmpdir.as_cwd():
            assert_command(
                ('pgctl', '--help'),
                '''\
usage: pgctl [-h] [--version] [--verbose] [--pgdir PGDIR] [--pghome PGHOME]
             [--json] [--force] [--all]
             {start,stop,status,restart,reload,log,debug,config}
             [services [services ...]]

positional arguments:
  {start,stop,status,restart,reload,log,debug,config}
                        specify what action to take
  services              specify which services to act upon

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --verbose             show additional service action information
  --pgdir PGDIR         name the playground directory
  --pghome PGHOME       directory to keep user-level playground state
  --json                output in JSON (only supported by some commands)
  --force               forcefully terminate runaway processes that prevent
                        services from starting/stopping
  --all, -a             act upon all services
''',
                '',
                0,
            )
Exemple #29
0
    def it_can_accept_different_environment_variables(self, in_example_dir):
        check_call(("sh", "-c", "MYVAR=ohhi pgctl-2015 start"))

        assert_command(
            ("pgctl-2015", "log"),
            """\
==> playground/environment/log <==
{TIMESTAMP} ohhi
""",
            "",
            0,
            norm=norm.pgctl,
        )

        check_call(("sh", "-c", "MYVAR=bye pgctl-2015 restart"))

        assert_command(
            ("pgctl-2015", "log"),
            """\
==> playground/environment/log <==
{TIMESTAMP} ohhi
{TIMESTAMP} bye
""",
            "",
            0,
            norm=norm.pgctl,
        )
Exemple #30
0
def it_fails_with_multiple_services():
    assert_command(
        ('pgctl-2015', 'debug', 'abc', 'def'),
        '',
        '[pgctl] ERROR: Must debug exactly one service, not: abc, def\n',
        1,
    )
Exemple #31
0
 def it_can_detect_cycles(self, in_example_dir):
     assert_command(
         ("pgctl-2015", "start", "b"),
         "",
         "[pgctl] ERROR: Circular aliases! Visited twice during alias expansion: 'b'\n",
         1,
     )
Exemple #32
0
def assert_does_not_find(path):
    assert_command(
        ('pgctl-fuser', path),
        '',
        '',
        0,
    )
Exemple #33
0
    def it_shows_stdout_and_stderr(self, in_example_dir):
        check_call(('pgctl', 'start', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/log <==

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('pgctl', 'restart', 'sweet'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/log <==

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #34
0
    def it_can_accept_different_environment_variables(self, in_example_dir):
        check_call(('sh', '-c', 'MYVAR=ohhi pgctl start'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/environment/log <==
{TIMESTAMP} ohhi
''',
            '',
            0,
            norm=norm.pgctl,
        )

        check_call(('sh', '-c', 'MYVAR=bye pgctl restart'))

        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/environment/log <==
{TIMESTAMP} ohhi
{TIMESTAMP} bye
''',
            '',
            0,
            norm=norm.pgctl,
        )
Exemple #35
0
    def it_can_still_show_config(self, tmpdir):
        expected_output = '''\
{
    "aliases": {
        "default": [
            "(all services)"
        ]
    },
    "command": "config",
    "force": false,
    "json": false,
    "pgdir": "playground",
    "pghome": "~/.run/pgctl",
    "poll": ".01",
    "services": [
        "default"
    ],
    "timeout": "2.0",
    "verbose": false
}
'''

        with tmpdir.as_cwd():
            assert_command(
                ('pgctl', 'config'),
                expected_output,
                '',
                0,
                norm=norm_trailing_whitespace_json,
            )
Exemple #36
0
    def it_shows_stdout_and_stderr(self, in_example_dir):
        check_call(("pgctl-2015", "start", "sweet"))

        assert_command(
            ("pgctl-2015", "log"),
            """\
==> playground/ohhi/log <==

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
""",
            "",
            0,
            norm=norm.pgctl,
        )

        check_call(("pgctl-2015", "restart", "sweet"))

        assert_command(
            ("pgctl-2015", "log"),
            """\
==> playground/ohhi/log <==

==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
""",
            "",
            0,
            norm=norm.pgctl,
        )
Exemple #37
0
def assert_does_not_find(path):
    assert_command(
        ('pgctl-fuser', path),
        '',
        '',
        0,
        close_fds=True,
    )
Exemple #38
0
def it_shows_help_given_no_arguments():
    from pgctl.fuser import __doc__
    assert_command(
        ('pgctl-fuser', ),
        '',
        __doc__ + '\n',
        1,
    )
Exemple #39
0
def it_shows_help_given_no_arguments():
    from pgctl.fuser import __doc__
    assert_command(
        ('pgctl-fuser',),
        '',
        __doc__ + '\n',
        1,
    )
Exemple #40
0
 def it_shows_an_error(self, command, tmpdir):
     with tmpdir.as_cwd():
         assert_command(
             ('pgctl', command),
             '',
             "[pgctl] ERROR: could not find any directory named 'playground'\n",
             1,
         )
Exemple #41
0
 def it_shows_an_error(self, command, tmpdir):
     with tmpdir.as_cwd():
         assert_command(
             ('pgctl', command),
             '',
             "[pgctl] ERROR: could not find any directory named 'playground'\n",
             1,
         )
Exemple #42
0
    def it_fails_given_unknown(self, in_example_dir):
        assert_command(
            ('pgctl', 'stop', 'unknown'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/unknown'
''',
            1,
        )
Exemple #43
0
    def it_fails_for_nonexistent_services(self, in_example_dir):
        assert_command(
            ('pgctl', 'log', 'i-dont-exist'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/i-dont-exist'
''',
            1,
        )
Exemple #44
0
 def it_shows_version(self):
     version_s = __version__ + '\n'
     assert_command(
         ('pgctl', '--version'),
         # argparse changes where `version` goes in py3
         '' if six.PY2 else version_s,
         version_s if six.PY2 else '',
         0,  # too few arguments
     )
Exemple #45
0
    def it_displays_status_for_unknown_services(self, in_example_dir):
        assert_command(
            ('pgctl', 'status', 'garbage'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/garbage'
''',
            1,
        )
Exemple #46
0
 def it_displays_correctly_when_the_service_is_down(self, in_example_dir):
     check_call(('pgctl', 'start', 'sleep'))
     check_call(('pgctl', 'stop', 'sleep'))
     assert_command(
         ('pgctl', 'status', 'sleep'),
         ' ● sleep: down\n',
         '',
         0,
     )
Exemple #47
0
    def it_fails_given_unknown(self, in_example_dir):
        assert_command(
            ('pgctl', 'stop', 'unknown'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/unknown'
''',
            1,
        )
Exemple #48
0
    def it_fails_for_nonexistent_services(self, in_example_dir):
        assert_command(
            ('pgctl', 'log', 'i-dont-exist'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/i-dont-exist'
''',
            1,
        )
Exemple #49
0
 def it_displays_correctly_when_the_service_is_up(self, in_example_dir):
     check_call(('pgctl-2015', 'start', 'sleep'))
     assert_command(
         ('pgctl-2015', 'status', 'sleep'),
         'sleep: ready (pid {PID}) {TIME} seconds\n',
         '',
         0,
         norm=norm.pgctl,
     )
Exemple #50
0
 def it_displays_correctly_when_the_service_is_down(self, in_example_dir):
     check_call(('pgctl', 'start', 'sleep'))
     check_call(('pgctl', 'stop', 'sleep'))
     assert_command(
         ('pgctl', 'status', 'sleep'),
         'sleep: down\n',
         '',
         0,
     )
Exemple #51
0
 def it_displays_correctly_when_the_service_is_up(self, in_example_dir):
     check_call(('pgctl', 'start', 'sleep'))
     assert_command(
         ('pgctl', 'status', 'sleep'),
         'sleep: ready (pid {PID}) {TIME} seconds\n',
         '',
         0,
         norm=norm.pgctl,
     )
Exemple #52
0
    def it_displays_status_for_unknown_services(self, in_example_dir):
        assert_command(
            ('pgctl', 'status', 'garbage'),
            '',
            '''\
[pgctl] ERROR: No such service: 'playground/garbage'
''',
            1,
        )
Exemple #53
0
    def it_runs_after_all_services_have_stopped(self):
        assert_command(
            ('pgctl', 'start', 'A'),
            '',
            '''\
[pgctl] Starting: A
[pgctl] Started: A
''',
            0,
            norm=norm.pgctl,
        )
        assert_command(
            ('pgctl', 'start', 'B'),
            '',
            '''\
[pgctl] Starting: B
[pgctl] Started: B
''',
            0,
            norm=norm.pgctl,
        )

        assert_command(
            ('pgctl', 'stop', 'A'),
            '',
            '''\
[pgctl] Stopping: A
[pgctl] Stopped: A
''',
            0,
            norm=norm.pgctl,
        )
        assert_command(
            ('pgctl', 'stop', 'B'),
            '',
            '''\
[pgctl] Stopping: B
[pgctl] Stopped: B
hello, i am a post-stop script
--> $PWD basename: post-stop-hook
--> cwd basename: post-stop-hook
''',
            0,
            norm=norm.pgctl,
        )

        # stopping when already down doesn't trigger post-stop to run again
        assert_command(
            ('pgctl', 'stop', 'A'),
            '',
            '''\
[pgctl] Already stopped: A
''',
            0,
            norm=norm.pgctl,
        )
Exemple #54
0
    def it_is_unimplemented(self, in_example_dir):
        assert_command(
            ('pgctl', 'reload'),
            '',
            '''\
[pgctl] reload: sleep
[pgctl] ERROR: reloading is not yet implemented.
''',
            1,
        )
Exemple #55
0
def it_can_succeed():
    from mock import patch, ANY
    with patch.dict(os.environ, [('PGCTL_TIMEOUT', str(SLOW_STARTUP_TIME))]):
        assert_command(
            ('pgctl', 'start'),
            '',
            #'[pgctl] Starting: slow-startup\n[pgctl] Started: slow-startup\n',
            ANY,
            0)
    assert_svstat('playground/slow-startup', state='ready')
Exemple #56
0
    def it_should_work_in_a_subdirectory(self, in_example_dir):
        os.chdir(in_example_dir.join('playground').strpath)
        assert_command(
            ('pgctl', 'start', 'sleep'),
            '',
            '''\
[pgctl] Starting: sleep
[pgctl] Started: sleep
''',
            0,
        )
Exemple #57
0
def it_restarts_on_unready():
    def it_is_ready():
        assert_svstat('playground/slow-startup', state='ready')

    def it_becomes_unready():
        from testfixtures import Comparison as C
        from pgctl.daemontools import svstat
        assert svstat('playground/slow-startup') != C(
            SvStat, {'state': 'ready'}, strict=False)

    it_can_succeed()
    os.remove('playground/slow-startup/readyfile')
    wait_for(it_becomes_unready)
    wait_for(it_is_ready)

    assert_command(
        ('pgctl', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed (restarting in {TIME} seconds)
{TIMESTAMP} pgctl-poll-ready: failed for more than {TIME} seconds -- we are restarting this service for you
{TIMESTAMP} [pgctl] Stopping: slow-startup
{TIMESTAMP} [pgctl] Stopped: slow-startup
{TIMESTAMP} [pgctl] Starting: slow-startup
{TIMESTAMP} pgctl-poll-ready: service's ready check succeeded
{TIMESTAMP} [pgctl] Started: slow-startup
''',
        '',
        0,
        norm=norm.pgctl,
    )
Exemple #58
0
        def assert_status():
            assert_command(
                ('pgctl', 'status'),
                '''\
sleep: down
tail: ready (pid {PID}) {TIME} seconds
''',
                '',
                0,
                norm=norm.pgctl,
            )
Exemple #59
0
    def it_is_empty_before_anything_starts(self, in_example_dir):
        assert_command(
            ('pgctl', 'log'),
            '''\
==> playground/ohhi/log <==

==> playground/sweet/log <==
''',
            '',
            0,
        )
Exemple #60
0
    def it_can_expand_properly(self, in_example_dir):
        assert_command(
            ('pgctl', 'start', 'a'),
            '',
            '''\
[pgctl] Starting: ohhi, sweet
[pgctl] Started: ohhi
[pgctl] Started: sweet
''',
            0,
        )