[Buildbot-commits] buildbot/buildbot master.py,1.88,1.89 locks.py,1.3,1.4

Brian Warner warner at users.sourceforge.net
Sat Nov 26 02:14:33 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10491/buildbot

Modified Files:
	master.py locks.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-440
Creator:  Brian Warner <warner at lothar.com>

fix the multiple-equivalent-Lock-instances bug on config-file reload

	* buildbot/locks.py: fix the problem in which loading a master.cfg
	file that changes some Builders (but not all of them) can result
	in having multiple copies of the same Lock. Now, the real Locks
	are kept in a table inside the BotMaster, and the Builders/Steps
	use "LockIDs", which are still instances of MasterLock and
	SlaveLock. The real Locks are instances of the new RealMasterLock
	and RealSlaveLock classes.
	* buildbot/master.py (BotMaster.getLockByID): new method to
	convert LockIDs into real Locks.
	* buildbot/process/base.py (Build.startBuild): convert LockIDs
	into real Locks before building
	* buildbot/process/step.py (BuildStep.startStep): same
	* buildbot/test/test_locks.py (Locks.testLock1a): add a test which
	exercises the problem


Index: locks.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/locks.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- locks.py	11 Aug 2005 20:27:48 -0000	1.3
+++ locks.py	26 Nov 2005 02:14:31 -0000	1.4
@@ -46,20 +46,18 @@
         d,owner = self.waiting.pop(0)
         d.callback(self)
 
-
-class MasterLock(BaseLock, util.ComparableMixin):
-    compare_attrs = ['name']
+class RealMasterLock(BaseLock):
     def __init__(self, name):
         BaseLock.__init__(self, name)
-        self.description = "<MasterLock(%s) %d>" % (name, id(self))
+        self.description = "<MasterLock(%s)>" % (name,)
 
     def getLock(self, slave):
         return self
 
-class SlaveLock(util.ComparableMixin):
-    compare_attrs = ['name']
+class RealSlaveLock(BaseLock):
     def __init__(self, name):
-        self.name = name
+        BaseLock.__init__(self, name)
+        self.description = "<SlaveLock(%s)>" % (name,)
         self.locks = {}
 
     def getLock(self, slavebuilder):
@@ -72,3 +70,20 @@
             self.locks[slavename] = lock
         return self.locks[slavename]
 
+
+# master.cfg should only reference the following MasterLock and SlaveLock
+# classes. They are identifiers that will be turned into real Locks later,
+# via the BotMaster.getLockByID method.
+
+class MasterLock(util.ComparableMixin):
+    compare_attrs = ['name']
+    lockClass = RealMasterLock
+    def __init__(self, name):
+        self.name = name
+
+class SlaveLock(util.ComparableMixin):
+    compare_attrs = ['name']
+    lockClass = RealSlaveLock
+    def __init__(self, name):
+        self.name = name
+

Index: master.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/master.py,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- master.py	25 Nov 2005 01:25:11 -0000	1.88
+++ master.py	26 Nov 2005 02:14:31 -0000	1.89
@@ -299,6 +299,8 @@
         self.statusClientService = None
         self.watchers = {}
 
+        # self.locks holds the real Lock instances
+        self.locks = {}
 
     # these four are convenience functions for testing
 
@@ -410,6 +412,15 @@
             b.builder_status.saveYourself()
         return service.Service.stopService(self)
 
+    def getLockByID(self, lockid):
+        """Convert a Lock identifier into an actual Lock instance.
+        @param lockid: a locks.MasterLock or locks.SlaveLock instance
+        @return: a locks.RealMasterLock or locks.RealSlaveLock instance
+        """
+        k = (lockid.__class__, lockid.name)
+        if not k in self.locks:
+            self.locks[k] = lockid.lockClass(lockid.name)
+        return self.locks[k]
 
 ########################################
 





More information about the Commits mailing list