def startCommand(config): basedir = config['basedir'] if not base.isBuildslaveDir(basedir): return 1 if base.isBuildSlaveRunning(basedir, config['quiet']): return 1 return startSlave(basedir, config['quiet'], config['nodaemon'])
def test_slavedir_good(self): """Test checking valid buildslave directory.""" # patch open() to return file with valid buildslave tac contents self.setUpOpen("Application('buildslave')") # check that isBuildslaveDir() flags directory as good self.assertTrue(base.isBuildslaveDir("testdir")) # check that open() was called with correct path self.open.assert_called_once_with(self.tac_file_path)
def stop(config, signame="TERM"): quiet = config['quiet'] basedir = config['basedir'] if not base.isBuildslaveDir(basedir): sys.exit(1) try: stopSlave(basedir, quiet, signame) except SlaveNotRunning: if not quiet: print "buildslave not running"
def test_slavedir_good(self): """Test checking valid buildslave directory.""" # patch open() to return file with valid buildslave tac contents (fileobj_mock, open_mock) = \ self.setUpMockedTacFile("Application('buildslave')") # check that isBuildslaveDir() flags directory as good self.assertTrue(base.isBuildslaveDir("testdir")) # check that open() was called with correct path open_mock.assert_called_once_with("testdir/buildbot.tac")
def restart(config): quiet = config['quiet'] if not base.isBuildslaveDir(config['basedir']): sys.exit(1) from buildslave.scripts.startup import start if not stop(config, wait=True, returnFalseOnNotRunning=True): if not quiet: print "no old buildslave process found to stop" if not quiet: print "now restarting buildslave process.." start(config)
def stop(config, signame="TERM"): quiet = config['quiet'] basedir = config['basedir'] if not base.isBuildslaveDir(basedir): return 1 try: stopSlave(basedir, quiet, signame) except SlaveNotRunning: if not quiet: log.msg("buildslave not running") return 0
def stop(config, signame="TERM"): quiet = config["quiet"] basedir = config["basedir"] if not base.isBuildslaveDir(basedir): return 1 try: stopSlave(basedir, quiet, signame) except SlaveNotRunning: if not quiet: print "buildslave not running" return 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 isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("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)
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 isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("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)
def test_open_error(self): """Test that open() errors are handled.""" # patch open() to raise IOError open_mock = mock.Mock(side_effect=IOError(1, "open-error", "dummy")) self.patch(__builtin__, "open", open_mock) # check that isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("testdir")) # check that correct error message was printed to stdout self.assertReadErrorMessage("open-error") # check that open() was called with correct path open_mock.assert_called_once_with("testdir/buildbot.tac")
def restart(config): quiet = config['quiet'] if not base.isBuildslaveDir(config['basedir']): sys.exit(1) from buildslave.scripts.startup import start try: stopSlave(config['basedir'], quiet) except SlaveNotRunning: if not quiet: print "no old buildslave process found to stop" if not quiet: print "now restarting buildslave process.." start(config)
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 isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("testdir")) # check that correct error message was printed to the log self.assertLogged("unexpected content in '%s'" % self.tac_file_path, "invalid buildslave 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)
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 isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("testdir")) # check that correct error message was printed to stdout self.assertEqual(self.mocked_stdout.getvalue(), "unexpected content in 'testdir/buildbot.tac'\n" "invalid buildslave directory 'testdir'\n", "unexpected error message on stdout") # check that open() was called with correct path self.open.assert_called_once_with("testdir/buildbot.tac")
def test_unexpected_tac_contents(self): """Test that unexpected contents in buildbot.tac is handled.""" # patch open() to return file with unexpected contents (fileobj_mock, open_mock) = self.setUpMockedTacFile("dummy-contents") # check that isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("testdir")) # check that correct error message was printed to stdout self.assertEqual(self.mocked_stdout.getvalue(), "unexpected content in 'testdir/buildbot.tac'\n" "invalid buildslave directory 'testdir'\n", "unexpected error message on stdout") # check that open() was called with correct path open_mock.assert_called_once_with("testdir/buildbot.tac")
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'])
def upgradeSlave(config): basedir = os.path.expanduser(config['basedir']) if not base.isBuildslaveDir(basedir): sys.exit(1) buildbot_tac = open(os.path.join(basedir, "buildbot.tac")).read() new_buildbot_tac = buildbot_tac.replace( "from buildbot.slave.bot import BuildSlave", "from buildslave.bot import BuildSlave") if new_buildbot_tac != buildbot_tac: open(os.path.join(basedir, "buildbot.tac"), "w").write(new_buildbot_tac) print "buildbot.tac updated" else: print "No changes made" return 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() fileobj_mock = mock.Mock() fileobj_mock.read = mock.Mock(side_effect=IOError(1, "read-error", "dummy")) open_mock = mock.Mock(return_value=fileobj_mock) self.patch(__builtin__, "open", open_mock) # check that isBuildslaveDir() flags directory as invalid self.assertFalse(base.isBuildslaveDir("testdir")) # check that correct error message was printed to stdout self.assertReadErrorMessage("read-error") # check that open() was called with correct path open_mock.assert_called_once_with("testdir/buildbot.tac")
def start(config): if not base.isBuildslaveDir(config['basedir']): sys.exit(1) os.chdir(config['basedir']) if config['quiet'] or config['nodaemon']: return launch(config) # we probably can't do this os.fork under windows from twisted.python.runtime import platformType if platformType == "win32": return launch(config) # fork a child to launch the daemon, while the parent process tails the # logfile if os.fork(): # this is the parent rc = Follower().follow() sys.exit(rc) # this is the child: give the logfile-watching parent a chance to start # watching it before we start the daemon time.sleep(0.2) launch(config)
def start(config): if not base.isBuildslaveDir(config['basedir']): sys.exit(1) os.chdir(config['basedir']) if config['quiet']: return launch(config) # we probably can't do this os.fork under windows from twisted.python.runtime import platformType if platformType == "win32": return launch(config) # fork a child to launch the daemon, while the parent process tails the # logfile if os.fork(): # this is the parent rc = Follower().follow() sys.exit(rc) # this is the child: give the logfile-watching parent a chance to start # watching it before we start the daemon time.sleep(0.2) launch(config)
def stop(config, signame="TERM", wait=False, returnFalseOnNotRunning=False): import signal basedir = config['basedir'] quiet = config['quiet'] if not base.isBuildslaveDir(config['basedir']): sys.exit(1) os.chdir(basedir) try: f = open("twistd.pid", "rt") except: if returnFalseOnNotRunning: return False if not quiet: print "buildslave not running." sys.exit(0) pid = int(f.read().strip()) signum = getattr(signal, "SIG"+signame) timer = 0 try: os.kill(pid, signum) except OSError, e: if e.errno != 3: raise
def startCommand(config): basedir = config["basedir"] if not base.isBuildslaveDir(basedir): return 1 return startSlave(basedir, config["quiet"], config["nodaemon"])
def startCommand(config): basedir = config['basedir'] if not base.isBuildslaveDir(basedir): return 1 return startSlave(basedir, config['quiet'], config['nodaemon'])