[Buildbot-commits] buildbot/buildbot/test test_runner.py,1.5,1.6
Brian Warner
warner at users.sourceforge.net
Tue May 17 20:04:11 UTC 2005
Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9329/buildbot/test
Modified Files:
test_runner.py
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-191
Creator: Brian Warner <warner at monolith.lothar.com>
clean up 'buildbot start', change to Makefile.buildbot
* buildbot/scripts/runner.py (start): change 'buildbot start' to
look for Makefile.buildbot instead of a bare Makefile . The
'buildbot start' does not install this file, so you have to
manually copy it if you want to customize startup behavior.
(createMaster): change 'buildbot master' command to create
Makefile.sample instead of Makefile, to create master.cfg.sample
instead of master.cfg (requiring you to copy it before the
buildmaster can be started). Both sample files are kept up to
date, i.e. they are overwritten if they have been changed. The
'buildbot.tac' file is *not* overwritten, but if the new contents
don't match the old, a 'buildbot.tac.new' file is created and the
user is warned. This seems to be a much more sane way to handle
startup files. Also, don't sys.exit(0) when done, so we can run
unit tests against it.
(createSlave): same. Don't overwrite the sample info/ files.
* buildbot/scripts/sample.mk: remove. the contents were pulled
into runner.py, since they need to match the behavior of start()
* setup.py: same
* MANIFEST.in: same
Index: test_runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_runner.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_runner.py 26 Apr 2005 20:10:07 -0000 1.5
+++ test_runner.py 17 May 2005 20:04:08 -0000 1.6
@@ -40,3 +40,154 @@
self.home = os.path.abspath("nothome")
os.makedirs(os.sep.join(["nothome", "dir1"]))
self.check(["nothome", "dir1"], None)
+
+class Create(unittest.TestCase):
+ def failUnlessIn(self, substring, string, msg=None):
+ # trial provides a version of this that requires python-2.3 to test
+ # strings.
+ self.failUnless(string.find(substring) != -1, msg)
+ def failUnlessExists(self, filename):
+ self.failUnless(os.path.exists(filename), "%s should exist" % filename)
+ def failIfExists(self, filename):
+ self.failIf(os.path.exists(filename), "%s should not exist" % filename)
+
+ def testMaster(self):
+ basedir = "test_runner.master"
+ options = runner.MasterOptions()
+ options.parseOptions(["-q", basedir])
+ cwd = os.getcwd()
+ runner.createMaster(options)
+ os.chdir(cwd)
+
+ tac = os.path.join(basedir, "buildbot.tac")
+ self.failUnless(os.path.exists(tac))
+ tacfile = open(tac,"rt").read()
+ self.failUnlessIn("basedir", tacfile)
+ self.failUnlessIn("configfile = 'master.cfg'", tacfile)
+ self.failUnlessIn("BuildMaster(basedir, configfile)", tacfile)
+
+ cfg = os.path.join(basedir, "master.cfg")
+ self.failIfExists(cfg)
+ samplecfg = os.path.join(basedir, "master.cfg.sample")
+ self.failUnlessExists(samplecfg)
+ cfgfile = open(samplecfg,"rt").read()
+ self.failUnlessIn("This is a sample buildmaster config file", cfgfile)
+
+ makefile = os.path.join(basedir, "Makefile.sample")
+ self.failUnlessExists(makefile)
+
+ # now verify that running it a second time (with the same options)
+ # does the right thing: nothing changes
+ runner.createMaster(options)
+ os.chdir(cwd)
+
+ self.failIfExists(os.path.join(basedir, "buildbot.tac.new"))
+ self.failUnlessExists(os.path.join(basedir, "master.cfg.sample"))
+
+ oldtac = open(os.path.join(basedir, "buildbot.tac"), "rt").read()
+
+ # mutate Makefile.sample, since it should be rewritten
+ f = open(os.path.join(basedir, "Makefile.sample"), "rt")
+ oldmake = f.read()
+ f = open(os.path.join(basedir, "Makefile.sample"), "wt")
+ f.write(oldmake)
+ f.write("# additional line added\n")
+ f.close()
+
+ # also mutate master.cfg.sample
+ f = open(os.path.join(basedir, "master.cfg.sample"), "rt")
+ oldsamplecfg = f.read()
+ f = open(os.path.join(basedir, "master.cfg.sample"), "wt")
+ f.write(oldsamplecfg)
+ f.write("# additional line added\n")
+ f.close()
+
+ # now run it again (with different options)
+ options = runner.MasterOptions()
+ options.parseOptions(["-q", "--config", "other.cfg", basedir])
+ runner.createMaster(options)
+ os.chdir(cwd)
+
+ tac = open(os.path.join(basedir, "buildbot.tac"), "rt").read()
+ self.failUnlessEqual(tac, oldtac, "shouldn't change existing .tac")
+ self.failUnlessExists(os.path.join(basedir, "buildbot.tac.new"))
+
+ make = open(os.path.join(basedir, "Makefile.sample"), "rt").read()
+ self.failUnlessEqual(make, oldmake, "*should* rewrite Makefile.sample")
+
+ samplecfg = open(os.path.join(basedir, "master.cfg.sample"),
+ "rt").read()
+ self.failUnlessEqual(samplecfg, oldsamplecfg,
+ "*should* rewrite master.cfg.sample")
+
+
+ def testSlave(self):
+ basedir = "test_runner.slave"
+ options = runner.SlaveOptions()
+ options.parseOptions(["-q", basedir, "buildmaster:1234",
+ "botname", "passwd"])
+ cwd = os.getcwd()
+ runner.createSlave(options)
+ os.chdir(cwd)
+
+ tac = os.path.join(basedir, "buildbot.tac")
+ self.failUnless(os.path.exists(tac))
+ tacfile = open(tac,"rt").read()
+ self.failUnlessIn("basedir", tacfile)
+ self.failUnlessIn("host = 'buildmaster'", tacfile)
+ self.failUnlessIn("port = 1234", tacfile)
+ self.failUnlessIn("slavename = 'botname'", tacfile)
+ self.failUnlessIn("passwd = 'passwd'", tacfile)
+ self.failUnlessIn("keepalive = 0", tacfile)
+ self.failUnlessIn("BuildSlave(host, port, slavename", tacfile)
+
+ makefile = os.path.join(basedir, "Makefile.sample")
+ self.failUnlessExists(makefile)
+
+ self.failUnlessExists(os.path.join(basedir, "info", "admin"))
+ self.failUnlessExists(os.path.join(basedir, "info", "host"))
+ # edit one to make sure the later install doesn't change it
+ f = open(os.path.join(basedir, "info", "admin"), "wt")
+ f.write("updated at buildbot.example.org\n")
+ f.close()
+
+ # now verify that running it a second time (with the same options)
+ # does the right thing: nothing changes
+ runner.createSlave(options)
+ os.chdir(cwd)
+
+ self.failIfExists(os.path.join(basedir, "buildbot.tac.new"))
+ admin = open(os.path.join(basedir, "info", "admin"), "rt").read()
+ self.failUnlessEqual(admin, "updated at buildbot.example.org\n")
+
+
+ # mutate Makefile.sample, since it should be rewritten
+ oldmake = open(os.path.join(basedir, "Makefile.sample"), "rt").read()
+ f = open(os.path.join(basedir, "Makefile.sample"), "wt")
+ f.write(oldmake)
+ f.write("# additional line added\n")
+ f.close()
+ oldtac = open(os.path.join(basedir, "buildbot.tac"), "rt").read()
+
+ # now run it again (with different options)
+ options = runner.SlaveOptions()
+ options.parseOptions(["-q", "--keepalive", "600",
+ basedir, "buildmaster:9999",
+ "newbotname", "passwd"])
+ runner.createSlave(options)
+ os.chdir(cwd)
+
+ tac = open(os.path.join(basedir, "buildbot.tac"), "rt").read()
+ self.failUnlessEqual(tac, oldtac, "shouldn't change existing .tac")
+ self.failUnlessExists(os.path.join(basedir, "buildbot.tac.new"))
+ tacfile = open(os.path.join(basedir, "buildbot.tac.new"),"rt").read()
+ self.failUnlessIn("basedir", tacfile)
+ self.failUnlessIn("host = 'buildmaster'", tacfile)
+ self.failUnlessIn("port = 9999", tacfile)
+ self.failUnlessIn("slavename = 'newbotname'", tacfile)
+ self.failUnlessIn("passwd = 'passwd'", tacfile)
+ self.failUnlessIn("keepalive = 600", tacfile)
+ self.failUnlessIn("BuildSlave(host, port, slavename", tacfile)
+
+ make = open(os.path.join(basedir, "Makefile.sample"), "rt").read()
+ self.failUnlessEqual(make, oldmake, "*should* rewrite Makefile.sample")
More information about the Commits
mailing list