Ejemplo n.º 1
0
    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 = r'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: it refuses to touch the existing database

        self.failUnlessRaises(DBAlreadyExistsError,
                              runner.createMaster, options)
Ejemplo n.º 2
0
    def testUpgradeMaster(self):
        # first, create a master, run it briefly, then upgrade it. Nothing
        # should change.
        basedir = "test_runner.master2"
        options = runner.MasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        runner.createMaster(options)
        os.chdir(cwd)

        f = open(os.path.join(basedir, "master.cfg"), "w")
        f.write(open(os.path.join(basedir, "master.cfg.sample"), "r").read())
        f.close()

        # the upgrade process (specifically the verify-master.cfg step) will
        # create any builder status directories that weren't already created.
        # Create those ahead of time.
        os.mkdir(os.path.join(basedir, "full"))

        files1 = self.record_files(basedir)

        # upgrade it
        options = runner.UpgradeMasterOptions()
        options.parseOptions(["--quiet", basedir])
        cwd = os.getcwd()
        runner.upgradeMaster(options)
        os.chdir(cwd)

        files2 = self.record_files(basedir)
        self.failUnlessSameFiles(files1, files2)

        # now make it look like the one that 0.7.5 creates: no public_html
        for fn in os.listdir(os.path.join(basedir, "public_html")):
            os.unlink(os.path.join(basedir, "public_html", fn))
        os.rmdir(os.path.join(basedir, "public_html"))

        # and make sure that upgrading it re-populates public_html
        options = runner.UpgradeMasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        runner.upgradeMaster(options)
        os.chdir(cwd)

        files3 = self.record_files(basedir)
        self.failUnlessSameFiles(files1, files3)

        # now induce an error in master.cfg and make sure that upgrade
        # notices it.
        f = open(os.path.join(basedir, "master.cfg"), "a")
        f.write("raise RuntimeError('catch me please')\n")
        f.close()

        options = runner.UpgradeMasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        rc = runner.upgradeMaster(options)
        os.chdir(cwd)
        self.failUnless(rc != 0, rc)
Ejemplo n.º 3
0
    def testUpgradeMaster(self):
        # first, create a master, run it briefly, then upgrade it. Nothing
        # should change.
        basedir = "test_runner.master2"
        options = runner.MasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        runner.createMaster(options)
        os.chdir(cwd)

        f = open(os.path.join(basedir, "master.cfg"), "w")
        f.write(open(os.path.join(basedir, "master.cfg.sample"), "r").read())
        f.close()

        # the upgrade process (specifically the verify-master.cfg step) will
        # create any builder status directories that weren't already created.
        # Create those ahead of time.
        os.mkdir(os.path.join(basedir, "full"))

        files1 = self.record_files(basedir)

        # upgrade it
        options = runner.UpgradeMasterOptions()
        options.parseOptions(["--quiet", basedir])
        cwd = os.getcwd()
        runner.upgradeMaster(options)
        os.chdir(cwd)

        files2 = self.record_files(basedir)
        self.failUnlessSameFiles(files1, files2)

        # now make it look like the one that 0.7.5 creates: no public_html
        for fn in os.listdir(os.path.join(basedir, "public_html")):
            os.unlink(os.path.join(basedir, "public_html", fn))
        os.rmdir(os.path.join(basedir, "public_html"))

        # and make sure that upgrading it re-populates public_html
        options = runner.UpgradeMasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        runner.upgradeMaster(options)
        os.chdir(cwd)

        files3 = self.record_files(basedir)
        self.failUnlessSameFiles(files1, files3)

        # now induce an error in master.cfg and make sure that upgrade
        # notices it.
        f = open(os.path.join(basedir, "master.cfg"), "a")
        f.write("raise RuntimeError('catch me please')\n")
        f.close()

        options = runner.UpgradeMasterOptions()
        options.parseOptions(["-q", basedir])
        cwd = os.getcwd()
        rc = runner.upgradeMaster(options)
        os.chdir(cwd)
        self.failUnless(rc != 0, rc)
Ejemplo n.º 4
0
    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 = r'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")
Ejemplo n.º 5
0
    try:
        config.parseOptions(options=options)
    except usage.error, e:
        print "%s:  %s" % (options[0], e)
        print
        c = getattr(config, 'subOptions', config)
        print str(c)
        return 1

    command = config.subCommand
    so = config.subOptions

    if command == "create-master":
        if not os.path.exists(BUILDBOT_MASTERS):
            os.makedirs(BUILDBOT_MASTERS)
        createMaster(so)
    elif command == "upgrade-master":
        upgradeMaster(so)
    elif command == "create-slave":
        if not os.path.exists(BUILDBOT_SLAVES):
            os.makedirs(BUILDBOT_SLAVES)
        createSlave(so)
    elif command == "start":
    ## adapted from
    ## http://stackoverflow.com/questions/972362/spawning-process-from-python
    ## similar recipe http://code.activestate.com/recipes/278731/
        child_pid = os.fork()
        if child_pid == 0:
            # forked child becomes session leader
            os.setsid()
            g_child_pid = os.fork()
    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 = r'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")