예제 #1
0
    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("buildmaster_host = 'buildmaster'", tacfile)
        self.failUnlessIn("port = 1234", tacfile)
        self.failUnlessIn("slavename = 'botname'", tacfile)
        self.failUnlessIn("passwd = 'passwd'", tacfile)
        self.failUnlessIn("keepalive = 600", tacfile)
        self.failUnlessIn("BuildSlave(buildmaster_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("[email protected]\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, "[email protected]\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", "30",
                              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("buildmaster_host = 'buildmaster'", tacfile)
        self.failUnlessIn("port = 9999", tacfile)
        self.failUnlessIn("slavename = 'newbotname'", tacfile)
        self.failUnlessIn("passwd = 'passwd'", tacfile)
        self.failUnlessIn("keepalive = 30", tacfile)
        self.failUnlessIn("BuildSlave(buildmaster_host, port, slavename",
                          tacfile)

        make = open(os.path.join(basedir, "Makefile.sample"), "rt").read()
        self.failUnlessEqual(make, oldmake, "*should* rewrite Makefile.sample")
예제 #2
0
    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("buildmaster_host = 'buildmaster'", tacfile)
        self.failUnlessIn("port = 1234", tacfile)
        self.failUnlessIn("slavename = 'botname'", tacfile)
        self.failUnlessIn("passwd = 'passwd'", tacfile)
        self.failUnlessIn("keepalive = 600", tacfile)
        self.failUnlessIn("BuildSlave(buildmaster_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("[email protected]\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, "[email protected]\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", "30",
                              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("buildmaster_host = 'buildmaster'", tacfile)
        self.failUnlessIn("port = 9999", tacfile)
        self.failUnlessIn("slavename = 'newbotname'", tacfile)
        self.failUnlessIn("passwd = 'passwd'", tacfile)
        self.failUnlessIn("keepalive = 30", tacfile)
        self.failUnlessIn("BuildSlave(buildmaster_host, port, slavename",
                          tacfile)

        make = open(os.path.join(basedir, "Makefile.sample"), "rt").read()
        self.failUnlessEqual(make, oldmake, "*should* rewrite Makefile.sample")
예제 #3
0
        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()
            if g_child_pid == 0:
                # second forked process now a non-session-leader,
                # detached from parent, must now close all open files
                try:
                    maxfd = os.sysconf("SC_OPEN_MAX")
                except (AttributeError, ValueError):