def test_successful_stop(self):
        """
        test stopSlave() on a successful slave 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 stopSlave() sends expected signal to right PID
        # and print correct message to the log
        stop.stopSlave(None, False)
        mocked_kill.assert_has_calls(
            [mock.call(self.PID, signal.SIGTERM),
             mock.call(self.PID, 0)])

        self.assertLogged("buildslave process %s is dead" % self.PID)
    def test_successful_stop(self):
        """
        test stopSlave() on a successful slave 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 stopSlave() sends expected signal to right PID
        # and print correct message to the log
        stop.stopSlave(None, False)
        mocked_kill.assert_has_calls([mock.call(self.PID, signal.SIGTERM), mock.call(self.PID, 0)])

        self.assertLogged("buildslave process %s is dead" % self.PID)
示例#3
0
def restart(config):
    quiet = config['quiet']
    basedir = config['basedir']

    if not base.isBuildslaveDir(basedir):
        return 1

    try:
        stop.stopSlave(basedir, quiet)
    except stop.SlaveNotRunning:
        if not quiet:
            log.msg("no old buildslave process found to stop")
    if not quiet:
        log.msg("now restarting buildslave process..")

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