[Buildbot-commits] buildbot/buildbot/slave commands.py,1.15,1.16

Brian Warner warner at users.sourceforge.net
Thu Oct 28 07:27:10 UTC 2004


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

Modified Files:
	commands.py 
Log Message:
* buildbot/slave/commands.py (SourceBase): refactor subclasses to
have separate doVCUpdate/doVCFull methods. Catch an update failure
and respond by clobbering the source directory and re-trying. This
will handle local changes (like replacing a file with a directory)
that will cause CVS and SVN updates to fail.
* buildbot/test/test_vc.py (SetupMixin.do_vc): test the same


Index: commands.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/slave/commands.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- commands.py	14 Oct 2004 16:59:26 -0000	1.15
+++ commands.py	28 Oct 2004 07:27:08 -0000	1.16
@@ -316,9 +316,13 @@
         self.deferred.errback(failure.Failure(CommandInterrupted()))
 
     def _abandonOnFailure(self, rc):
+        if type(rc) is not int:
+            log.msg("weird, _abandonOnFailure was given rc=%s (%s)" % \
+                    (rc, type(rc)))
         assert type(rc) is int
         if rc != 0:
             raise AbandonChain(rc)
+        return rc
 
     def _sendRC(self, res):
         self.sendStatus({'rc': 0})
@@ -454,6 +458,7 @@
             d.addCallback(self.doClobber, self.srcdir)
 
         d.addCallback(self.doVC)
+
         if self.mode == "copy":
             d.addCallback(self.doCopy)
         if self.patch:
@@ -462,12 +467,36 @@
         return d
 
     def doVC(self, res):
-        c = self.buildVC()
-        d = c.start()
+        if self.sourcedirIsUpdateable():
+            d = self.doVCUpdate()
+            d.addCallback(self.maybeDoVCFallback)
+        else:
+            d = self.doVCFull()
+        d.addCallback(self._abandonOnFailure)
+        return d
+
+    def doVCUpdate(self):
+        raise NotImplementedError("this must be implemented in a subclass")
+
+    def doVCFull(self):
+        raise NotImplementedError("this must be implemented in a subclass")
+
+    def maybeDoVCFallback(self, rc):
+        if type(rc) is int and rc == 0:
+            return rc
+        msg = "update failed, clobbering and trying again"
+        self.sendStatus({'header': msg + "\n"})
+        log.msg(msg)
+        d = self.doClobber(None, self.srcdir)
+        d.addCallback(self.doVCFallback2)
+        return d
+
+    def doVCFallback2(self, res):
+        msg = "now retrying VC operation"
+        self.sendStatus({'header': msg + "\n"})
+        log.msg(msg)
+        d = self.doVCFull()
         d.addCallback(self._abandonOnFailure)
-        # TODO: if update fails (rc != 0), do clobber and full checkout. This
-        # probably wants doCVS to be split into doUpdate and doCheckout, to
-        # avoid loops
         return d
 
     def doClobber(self, dummy, dirname):
@@ -581,33 +610,34 @@
         # now we really start
         return SourceBase.start(self)
 
-    def buildVC(self):
-        if self.sourcedirIsUpdateable():
-            # update
-            d = os.path.join(self.builder.basedir, self.srcdir)
-            command = ['cvs', '-z3'] + self.global_options + ['update', '-dP']
-            if self.branch:
-                command += ['-r', self.branch]
-            if self.revision:
-                command += ['-D', self.revision]
+    def doVCUpdate(self):
+        d = os.path.join(self.builder.basedir, self.srcdir)
+        command = ['cvs', '-z3'] + self.global_options + ['update', '-dP']
+        if self.branch:
+            command += ['-r', self.branch]
+        if self.revision:
+            command += ['-D', self.revision]
+        c = ShellCommand(self.builder, command, d,
+                         sendRC=False, timeout=self.timeout)
+        return c.start()
+
+    def doVCFull(self):
+        d = self.builder.basedir
+        if self.mode == "export":
+            verb = "export"
         else:
-            # checkout
-            d = self.builder.basedir
-            if self.mode == "export":
-                verb = "export"
-            else:
-                verb = "checkout"
-            command = (['cvs', '-d', self.cvsroot, '-z3'] +
-                       self.global_options +
-                       [verb, '-d', self.srcdir])
-            if self.branch:
-                command += ['-r', self.branch]
-            if self.revision:
-                command += ['-D', self.revision]
-            command += [self.cvsmodule]
+            verb = "checkout"
+        command = (['cvs', '-d', self.cvsroot, '-z3'] +
+                   self.global_options +
+                   [verb, '-d', self.srcdir])
+        if self.branch:
+            command += ['-r', self.branch]
+        if self.revision:
+            command += ['-D', self.revision]
+        command += [self.cvsmodule]
         c = ShellCommand(self.builder, command, d,
                          sendRC=False, timeout=self.timeout)
-        return c
+        return c.start()
 
 registerSlaveCommand("cvs", CVS, cvs_ver)
 
@@ -630,25 +660,28 @@
         return os.path.isdir(os.path.join(self.builder.basedir,
                                           self.srcdir, ".svn"))
 
-    def buildVC(self):
+    def doVCUpdate(self):
         revision = self.args['revision'] or 'HEAD'
-        if self.sourcedirIsUpdateable():
-            # update: possible for mode in ('copy', 'update')
-            d = os.path.join(self.builder.basedir, self.srcdir)
-            command = ['svn', 'update', '--revision', str(revision)]
+        # update: possible for mode in ('copy', 'update')
+        d = os.path.join(self.builder.basedir, self.srcdir)
+        command = ['svn', 'update', '--revision', str(revision)]
+        c = ShellCommand(self.builder, command, d,
+                         sendRC=False, timeout=self.timeout)
+        return c.start()
+
+    def doVCFull(self):
+        revision = self.args['revision'] or 'HEAD'
+        d = self.builder.basedir
+        if self.mode == "export":
+            command = ['svn', 'export', '--revision', str(revision),
+                       self.svnurl, self.srcdir]
         else:
-            # checkout or export
-            d = self.builder.basedir
-            if self.mode == "export":
-                command = ['svn', 'export', '--revision', str(revision),
-                           self.svnurl, self.srcdir]
-            else:
-                # mode=='clobber', or copy/update on a broken workspace
-                command = ['svn', 'checkout', '--revision', str(revision),
-                           self.svnurl, self.srcdir]
+            # mode=='clobber', or copy/update on a broken workspace
+            command = ['svn', 'checkout', '--revision', str(revision),
+                       self.svnurl, self.srcdir]
         c = ShellCommand(self.builder, command, d,
                          sendRC=False, timeout=self.timeout)
-        return c
+        return c.start()
 
 registerSlaveCommand("svn", SVN, cvs_ver)
 
@@ -671,21 +704,25 @@
         return os.path.isdir(os.path.join(self.builder.basedir,
                                           self.srcdir, "_darcs"))
 
-    def buildVC(self):
+    def doVCUpdate(self):
         # TODO: revision
-        if self.sourcedirIsUpdateable():
-            # update: possible for mode in ('copy', 'update')
-            d = os.path.join(self.builder.basedir, self.srcdir)
-            command = ['darcs', 'pull', '--all', '--verbose']
-        else:
-            # checkout or export
-            d = self.builder.basedir
-            command = ['darcs', 'get', '--verbose', '--partial',
-                       '--repo-name', self.srcdir,
-                       self.repourl]
+        # update: possible for mode in ('copy', 'update')
+        d = os.path.join(self.builder.basedir, self.srcdir)
+        command = ['darcs', 'pull', '--all', '--verbose']
         c = ShellCommand(self.builder, command, d,
                          sendRC=False, timeout=self.timeout)
-        return c
+        return c.start()
+
+    def doVCFull(self):
+        # TODO: revision
+        # checkout or export
+        d = self.builder.basedir
+        command = ['darcs', 'get', '--verbose', '--partial',
+                   '--repo-name', self.srcdir,
+                   self.repourl]
+        c = ShellCommand(self.builder, command, d,
+                         sendRC=False, timeout=self.timeout)
+        return c.start()
 
 registerSlaveCommand("darcs", Darcs, cvs_ver)
 
@@ -714,17 +751,15 @@
         return os.path.isdir(os.path.join(self.builder.basedir,
                                           self.srcdir, "{arch}"))
 
-    def doVC(self, res):
-        if self.sourcedirIsUpdateable():
-            # update: possible for mode in ('copy', 'update')
-            d = os.path.join(self.builder.basedir, self.srcdir)
-            command = ['tla', 'update']
-            c = ShellCommand(self.builder, command, d,
-                             sendRC=False, timeout=self.timeout)
-            d = c.start()
-            d.addCallback(self._abandonOnFailure)
-            return d
+    def doVCUpdate(self):
+        # update: possible for mode in ('copy', 'update')
+        d = os.path.join(self.builder.basedir, self.srcdir)
+        command = ['tla', 'update']
+        c = ShellCommand(self.builder, command, d,
+                         sendRC=False, timeout=self.timeout)
+        return c.start()
 
+    def doVCFull(self):
         # to do a checkout, we first must register the archive. This
         # involves passing the URL to arch and letting it tell us the
         # archive name.
@@ -774,8 +809,8 @@
                          sendRC=False, timeout=self.timeout)
         d = c.start()
         d.addCallback(self._abandonOnFailure)
+        return d
 
-        
 registerSlaveCommand("arch", Arch, cvs_ver)
 
 
@@ -795,13 +830,16 @@
     def sourcedirIsUpdateable(self):
         return True
 
-    def buildVC(self):
+    def doVCUpdate(self):
         # TODO: revision
         d = os.path.join(self.builder.basedir, self.srcdir)
         command = ['p4', 'sync']
         env = {'P4PORT': self.p4port}
         c = ShellCommand(self.builder, command, d, environ=env,
                          sendRC=False, timeout=self.timeout)
-        return c
+        return c.start()
+
+    def doVCFull(self):
+        return self.doVCUpdate()
 
 registerSlaveCommand("p4sync", P4Sync, cvs_ver)





More information about the Commits mailing list