Example #1
0
    def test_workerdir_good(self):
        """Test checking valid buildworker directory."""

        # patch open() to return file with valid buildworker tac contents
        self.setUpOpen("Application('buildworker')")

        # check that isBuildworkerDir() flags directory as good
        self.assertTrue(base.isBuildworkerDir("testdir"))

        # check that open() was called with correct path
        self.open.assert_called_once_with(self.tac_file_path)
Example #2
0
def stop(config, signame="TERM"):
    quiet = config['quiet']
    basedir = config['basedir']

    if not base.isBuildworkerDir(basedir):
        return 1

    try:
        stopWorker(basedir, quiet, signame)
    except WorkerNotRunning:
        if not quiet:
            log.msg("buildworker not running")

    return 0
Example #3
0
    def test_read_error(self):
        """Test that read() errors on buildbot.tac file are handled."""

        # patch open() to return file object that raises IOError on read()
        self.setUpReadError(1, "read-error", "dummy")

        # check that isBuildworkerDir() flags directory as invalid
        self.assertFalse(base.isBuildworkerDir("testdir"))

        # check that correct error message was printed to stdout
        self.assertReadErrorMessage("read-error")

        # check that open() was called with correct path
        self.open.assert_called_once_with(self.tac_file_path)
Example #4
0
    def test_open_error(self):
        """Test that open() errors are handled."""

        # patch open() to raise IOError
        self.setUpOpenError(1, "open-error", "dummy")

        # check that isBuildworkerDir() flags directory as invalid
        self.assertFalse(base.isBuildworkerDir("testdir"))

        # check that correct error message was printed to stdout
        self.assertReadErrorMessage("open-error")

        # check that open() was called with correct path
        self.open.assert_called_once_with(self.tac_file_path)
Example #5
0
    def test_unexpected_tac_contents(self):
        """Test that unexpected contents in buildbot.tac is handled."""

        # patch open() to return file with unexpected contents
        self.setUpOpen("dummy-contents")

        # check that isBuildworkerDir() flags directory as invalid
        self.assertFalse(base.isBuildworkerDir("testdir"))

        # check that correct error message was printed to the log
        self.assertLogged("unexpected content in '%s'" % self.tac_file_path,
                         "invalid buildworker directory 'testdir'",
                         "unexpected error message on stdout")
        # check that open() was called with correct path
        self.open.assert_called_once_with(self.tac_file_path)
Example #6
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'])
Example #7
0
def upgradeWorker(config):
    basedir = os.path.expanduser(config['basedir'])

    if not base.isBuildworkerDir(basedir):
        return 1

    buildbot_tac = open(os.path.join(basedir, "buildbot.tac")).read()
    new_buildbot_tac = buildbot_tac.replace(
        "from buildbot.worker.bot import BuildWorker",
        "from buildworker.bot import BuildWorker")
    if new_buildbot_tac != buildbot_tac:
        open(os.path.join(basedir, "buildbot.tac"), "w").write(new_buildbot_tac)
        log.msg("buildbot.tac updated")
    else:
        log.msg("No changes made")

    return 0
Example #8
0
def startCommand(config):
    basedir = config['basedir']
    if not base.isBuildworkerDir(basedir):
        return 1

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