Пример #1
0
    def test_successful_stop(self):
        """
        test stopWorker() on a successful worker stop
        """

        def emulated_kill(pid, sig):
            if sig == 0:
                # when probed if a signal can be send to the process
                # emulate that it is dead with 'No such process' error
                raise OSError(errno.ESRCH, "dummy")

        # patch open() to return a pid file
        self.setUpOpen(str(self.PID))

        # patch os.kill to emulate successful kill
        mocked_kill = mock.Mock(side_effect=emulated_kill)
        self.patch(os, "kill", mocked_kill)

        # don't waste time
        self.patch(time, "sleep", mock.Mock())

        # check that stopWorker() sends expected signal to right PID
        # and print correct message to the log
        stop.stopWorker(None, False)
        mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM),
                                      mock.call(self.PID, 0)])

        self.assertLogged("buildworker process %s is dead" % self.PID)
Пример #2
0
def restart(config):
    quiet = config['quiet']
    basedir = config['basedir']

    if not base.isBuildworkerDir(basedir):
        return 1

    try:
        stop.stopWorker(basedir, quiet)
    except stop.WorkerNotRunning:
        if not quiet:
            log.msg("no old buildworker process found to stop")
    if not quiet:
        log.msg("now restarting buildworker process..")

    return start.startWorker(basedir, quiet, config['nodaemon'])