[Buildbot-devel] [PATCH 2/4] canStartBuild

Dustin J. Mitchell dustin at zmanda.com
Fri Jun 22 18:04:16 UTC 2007


2007-06-22  Dustin J. Mitchell <dustin at zmanda.com>
    * buildbot/buildslave.py: add canStartBuild()
    * buildbot/process/builder.py: call BuildSlave's canStartBuild();
      replace isAvailable() with canStartBuild(), as a better description 
      of its functionality; add isBusy() to check whether the BuildSlave
      itself is busy.

Index: wip/buildbot/buildslave.py
===================================================================
--- wip.orig/buildbot/buildslave.py	2007-06-22 12:39:29.489069819 -0500
+++ wip/buildbot/buildslave.py	2007-06-22 12:39:39.392755280 -0500
@@ -5,7 +5,7 @@
 from buildbot.master import BotPerspective
 
 class BuildSlave(BotPerspective):
-    """I represent a build slave -- a connection from a remote machine capable of
+    """I represent a build slave -- a remote machine capable of
     running builds.  I am instantiated by the configuration file, and can be
     subclassed to add extra functionality."""
 
@@ -27,3 +27,11 @@
         return "<BuildSlave '%s', current builders: %s>" % \
                (self.slavename,
                 string.join(map(lambda b: b.name, builders), ','))
+
+    def canStartBuild(self):
+        """
+        I am called when a build is requested to see if this buildslave is
+        can start a build.  This function can be used to limit overall
+        concurrency on the buildslave.
+        """
+        return True
Index: wip/buildbot/process/builder.py
===================================================================
--- wip.orig/buildbot/process/builder.py	2007-06-22 12:30:25.562284504 -0500
+++ wip/buildbot/process/builder.py	2007-06-22 12:39:39.392755280 -0500
@@ -37,12 +37,28 @@
             return oldversion
         return self.remoteCommands.get(command)
 
-    def isAvailable(self):
-        if self.state == IDLE:
-            return True
+    def canStartBuild(self):
+        # if this SlaveBuilder is busy, then it's definitely not available
+        if self.state != IDLE:
+            return False
+
+        # otherwise, check in with the BuildSlave
+        if self.slave:
+            return self.slave.canStartBuild()
+
+        # no slave? not very available.
         return False
 
     def attached(self, slave, remote, commands):
+        """
+        @type  slave: L{buildbot.buildslave.BuildSlave}
+        @param slave: the BuildSlave that represents the buildslave as a
+                      whole
+        @type  remote: L{twisted.spread.pb.RemoteReference}
+        @param remote: a reference to the L{buildbot.slave.bot.SlaveBuilder}
+        @type  commands: dict: string -> string, or None
+        @param commands: provides the slave's version of each RemoteCommand
+        """
         self.slave = slave
         self.remote = remote
         self.remoteCommands = commands # maps command name to version
@@ -392,8 +408,8 @@
         """This is invoked by the BotPerspective when the self.slavename bot
         registers their builder.
 
-        @type  slave: L{buildbot.master.BotPerspective}
-        @param slave: the BotPerspective that represents the buildslave as a
+        @type  slave: L{buildbot.buildslave.BuildSlave}
+        @param slave: the BuildSlave that represents the buildslave as a
                       whole
         @type  remote: L{twisted.spread.pb.RemoteReference}
         @param remote: a reference to the L{buildbot.slave.bot.SlaveBuilder}
@@ -502,9 +518,9 @@
         if not self.buildable:
             self.updateBigStatus()
             return # nothing to do
-        # find the first idle slave
+        # find the first slave that can run this build
         for sb in self.slaves:
-            if sb.isAvailable():
+            if sb.canStartBuild():
                 break
         else:
             log.msg("%s: want to start build, but we don't have a remote"

-- 
        Dustin J. Mitchell
        Storage Software Engineer, Zmanda, Inc.
        http://www.zmanda.com/




More information about the devel mailing list