Skip to content

Commit

Permalink
Merge branch 'bug2465-sqash' of git://github.com/srinupiits/buildbot
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Jul 17, 2013
2 parents 021ff42 + feb582a commit 97eff1c
Show file tree
Hide file tree
Showing 12 changed files with 624 additions and 81 deletions.
1 change: 1 addition & 0 deletions master/buildbot/steps/source/base.py
Expand Up @@ -109,6 +109,7 @@ def __init__(self, workdir=None, mode='update', alwaysUseLatest=False,
self.logEnviron = logEnviron
self.env = env
self.timeout = timeout
self.retry = retry

descriptions_for_mode = {
"clobber": "checkout",
Expand Down
51 changes: 36 additions & 15 deletions master/buildbot/steps/source/bzr.py
Expand Up @@ -16,7 +16,7 @@
import os

from twisted.python import log
from twisted.internet import defer
from twisted.internet import defer, reactor

from buildbot.process import buildstep
from buildbot.steps.source.base import Source
Expand Down Expand Up @@ -89,21 +89,16 @@ def checkPatched(patched):
d.addErrback(self.failed)
return d

@defer.inlineCallbacks
def incremental(self):
d = self._sourcedirIsUpdatable()
def _cmd(updatable):
if updatable:
command = ['update']
else:
command = ['checkout', self.repourl, '.']

updatable = yield self._sourcedirIsUpdatable()
if updatable:
command = ['update']
if self.revision:
command.extend(['-r', self.revision])
return command

d.addCallback(_cmd)
d.addCallback(self._dovccmd)
return d
yield self._dovccmd(command)
else:
yield self._doFull()

@defer.inlineCallbacks
def full(self):
Expand All @@ -126,7 +121,7 @@ def full(self):
else:
raise ValueError("Unknown method, check your configuration")

def clobber(self):
def _clobber(self):
cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
'logEnviron': self.logEnviron,})
cmd.useLog(self.stdio_log, False)
Expand All @@ -136,6 +131,10 @@ def checkRemoval(res):
raise RuntimeError("Failed to delete directory")
return res
d.addCallback(lambda _: checkRemoval(cmd.rc))
return d

def clobber(self):
d = self._clobber()
d.addCallback(lambda _: self._doFull())
return d

Expand Down Expand Up @@ -176,7 +175,29 @@ def _doFull(self):
command = ['checkout', self.repourl, '.']
if self.revision:
command.extend(['-r', self.revision])
d = self._dovccmd(command)

if self.retry:
abandonOnFailure = (self.retry[1] <= 0)
else:
abandonOnFailure = True
d = self._dovccmd(command, abandonOnFailure=abandonOnFailure)
def _retry(res):
if self.stopped or res == 0:
return res
delay, repeats = self.retry
if repeats > 0:
log.msg("Checkout failed, trying %d more times after %d seconds"
% (repeats, delay))
self.retry = (delay, repeats-1)
df = defer.Deferred()
df.addCallback(lambda _: self._clobber())
df.addCallback(lambda _: self._doFull())
reactor.callLater(delay, df.callback, None)
return df
return res

if self.retry:
d.addCallback(_retry)
return d

def finish(self, res):
Expand Down
36 changes: 31 additions & 5 deletions master/buildbot/steps/source/cvs.py
Expand Up @@ -18,7 +18,7 @@
import re

from twisted.python import log
from twisted.internet import defer
from twisted.internet import defer, reactor

from buildbot.process import buildstep
from buildbot.steps.shell import StringFileWriter
Expand Down Expand Up @@ -111,7 +111,7 @@ def full(self):
raise ValueError("Unknown method, check your configuration")
defer.returnValue(rv)

def clobber(self):
def _clobber(self):
cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
'logEnviron': self.logEnviron})
cmd.useLog(self.stdio_log, False)
Expand All @@ -121,6 +121,10 @@ def checkRemoval(res):
raise RuntimeError("Failed to delete directory")
return res
d.addCallback(lambda _: checkRemoval(cmd.rc))
return d

def clobber(self):
d = self._clobber()
d.addCallback(lambda _: self.doCheckout(self.workdir))
return d

Expand Down Expand Up @@ -181,9 +185,31 @@ def doCheckout(self, dir):
if self.revision:
command += ['-D', self.revision]
command += [ self.cvsmodule ]
d = self._dovccmd(command, '')
if self.retry:
abandonOnFailure = (self.retry[1] <= 0)
else:
abandonOnFailure = True
d = self._dovccmd(command, '', abandonOnFailure=abandonOnFailure)
def _retry(res):
if self.stopped or res == 0:
return res
delay, repeats = self.retry
if repeats > 0:
log.msg("Checkout failed, trying %d more times after %d seconds"
% (repeats, delay))
self.retry = (delay, repeats-1)
df = defer.Deferred()
df.addCallback(lambda _: self._clobber())
df.addCallback(lambda _: self.doCheckout(self.workdir))
reactor.callLater(delay, df.callback, None)
return df
return res

if self.retry:
d.addCallback(_retry)
return d


def doUpdate(self):
command = ['-z3', 'update', '-dP']
branch = self.branch
Expand Down Expand Up @@ -219,7 +245,7 @@ def setLogin(res):

return d

def _dovccmd(self, command, workdir=None):
def _dovccmd(self, command, workdir=None, abandonOnFailure=True):
if workdir is None:
workdir = self.workdir
if not command:
Expand All @@ -232,7 +258,7 @@ def _dovccmd(self, command, workdir=None):
cmd.useLog(self.stdio_log, False)
d = self.runCommand(cmd)
def evaluateCommand(cmd):
if cmd.rc != 0:
if cmd.rc != 0 and abandonOnFailure:
log.msg("Source step failed while running command %s" % cmd)
raise buildstep.BuildStepFailed()
return cmd.rc
Expand Down
49 changes: 37 additions & 12 deletions master/buildbot/steps/source/git.py
Expand Up @@ -14,7 +14,7 @@
# Copyright Buildbot Team Members

from twisted.python import log
from twisted.internet import defer
from twisted.internet import defer, reactor

from buildbot import config as bbconfig
from buildbot.process import buildstep
Expand Down Expand Up @@ -138,6 +138,7 @@ def startVC(self, branch, revision, patch):
self.method = self._getMethod()
self.stdio_log = self.addLogForRemoteCommands("stdio")


d = self.checkGit()
def checkInstall(gitInstalled):
if not gitInstalled:
Expand Down Expand Up @@ -379,15 +380,14 @@ def _fetchOrFallback(self, _):
elif self.retryFetch:
yield self._fetch(None)
elif self.clobberOnFailure:
yield self._doClobber()
yield self._fullClone()
yield self.clobber()
else:
raise buildstep.BuildStepFailed()

def _fullClone(self, shallowClone=False):
"""Perform full clone and checkout to the revision if specified
In the case of shallow clones if any of the step fail abort whole build step.
"""

def _clone(self, shallowClone):
"""Retry if clone failed"""

args = []
if self.branch != 'HEAD':
args += ['--branch', self.branch]
Expand All @@ -399,9 +399,36 @@ def _fullClone(self, shallowClone=False):

if self.prog:
command.append('--progress')

if self.retry:
abandonOnFailure = (self.retry[1] <= 0)
else:
abandonOnFailure = True
# If it's a shallow clone abort build step
d = self._dovccmd(command, shallowClone)
d = self._dovccmd(command, abandonOnFailure=(abandonOnFailure and shallowClone))
def _retry(res):
if self.stopped or res == 0: # or shallow clone??
return res
delay, repeats = self.retry
if repeats > 0:
log.msg("Checkout failed, trying %d more times after %d seconds"
% (repeats, delay))
self.retry = (delay, repeats-1)
df = defer.Deferred()
df.addCallback(lambda _: self._doClobber())
df.addCallback(lambda _: self._clone(shallowClone))
reactor.callLater(delay, df.callback, None)
return df
return res

if self.retry:
d.addCallback(_retry)
return d

def _fullClone(self, shallowClone=False):
"""Perform full clone and checkout to the revision if specified
In the case of shallow clones if any of the step fail abort whole build step.
"""
d = self._clone(shallowClone)
# If revision specified checkout that revision
if self.revision:
d.addCallback(lambda _: self._dovccmd(['reset', '--hard',
Expand All @@ -424,9 +451,7 @@ def _fullCloneOrFallback(self):
def clobber(res):
if res != 0:
if self.clobberOnFailure:
d = self._doClobber()
d.addCallback(lambda _: self._fullClone())
return d
return self.clobber()
else:
raise buildstep.BuildStepFailed()
else:
Expand Down
59 changes: 46 additions & 13 deletions master/buildbot/steps/source/mercurial.py
Expand Up @@ -16,7 +16,7 @@
## Source step code for mercurial

from twisted.python import log
from twisted.internet import defer
from twisted.internet import defer, reactor

from buildbot.process import buildstep
from buildbot.steps.source.base import Source
Expand Down Expand Up @@ -131,12 +131,13 @@ def checkPatched(patched):
@defer.inlineCallbacks
def full(self):
if self.method == 'clobber':
yield self.clobber(None)
yield self.clobber()
return

updatable = yield self._sourcedirIsUpdatable()
if not updatable:
yield self._dovccmd(['clone', self.repourl, '.'])
yield self._clone()
yield self._update(None)
elif self.method == 'clean':
yield self.clean(None)
elif self.method == 'fresh':
Expand All @@ -149,15 +150,16 @@ def incremental(self):
raise ValueError(self.method)

d = self._sourcedirIsUpdatable()
@defer.inlineCallbacks
def _cmd(updatable):
if updatable:
command = ['pull', self.repourl]
yield self._dovccmd(['pull', self.repourl])
return
else:
command = ['clone', self.repourl, '.', '--noupdate']
return command
yield self._clone()
return

d.addCallback(_cmd)
d.addCallback(self._dovccmd)
d.addCallback(self._checkBranchChange)
return d

Expand All @@ -167,13 +169,17 @@ def clean(self, _):
d.addCallback(self._pullUpdate)
return d

def clobber(self, _):

def _clobber(self):
cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
'logEnviron':self.logEnviron})
cmd.useLog(self.stdio_log, False)
d = self.runCommand(cmd)
d.addCallback(lambda _: self._dovccmd(['clone', '--noupdate'
, self.repourl, "."]))
return d

def clobber(self):
d = self._clobber()
d.addCallback(lambda _: self._clone())
d.addCallback(self._update)
return d

Expand Down Expand Up @@ -212,7 +218,7 @@ def _checkBranchChange(self, _):
if current_branch != self.update_branch and self.clobberOnBranchChange:
msg += ' Clobbering.'
log.msg(msg)
yield self.clobber(None)
yield self.clobber()
return
msg += ' Updating.'
log.msg(msg)
Expand All @@ -226,7 +232,8 @@ def _pullUpdate(self, res):
d.addCallback(self._checkBranchChange)
return d

def _dovccmd(self, command, collectStdout=False, initialStdin=None, decodeRC={0:SUCCESS}):
def _dovccmd(self, command, collectStdout=False, initialStdin=None, decodeRC={0:SUCCESS},
abandonOnFailure=True):
if not command:
raise ValueError("No command specified")
cmd = buildstep.RemoteShellCommand(self.workdir, ['hg', '--verbose'] + command,
Expand All @@ -240,7 +247,7 @@ def _dovccmd(self, command, collectStdout=False, initialStdin=None, decodeRC={0:
log.msg("Starting mercurial command : hg %s" % (" ".join(command), ))
d = self.runCommand(cmd)
def evaluateCommand(cmd):
if cmd.didFail():
if abandonOnFailure and cmd.didFail():
log.msg("Source step failed while running command %s" % cmd)
raise buildstep.BuildStepFailed()
if collectStdout:
Expand Down Expand Up @@ -330,6 +337,32 @@ def _update(self, _):
d = self._dovccmd(command)
return d

def _clone(self):
if self.retry:
abandonOnFailure = (self.retry[1] <= 0)
else:
abandonOnFailure = True
d = self._dovccmd(['clone', '--noupdate', self.repourl, '.'],
abandonOnFailure=abandonOnFailure)
def _retry(res):
if self.stopped or res == 0:
return res
delay, repeats = self.retry
if repeats > 0:
log.msg("Checkout failed, trying %d more times after %d seconds"
% (repeats, delay))
self.retry = (delay, repeats-1)
df = defer.Deferred()
df.addCallback(lambda _: self._clobber())
df.addCallback(lambda _: self._clone())
reactor.callLater(delay, df.callback, None)
return df
return res

if self.retry:
d.addCallback(_retry)
return d

def checkHg(self):
d = self._dovccmd(['--version'])
def check(res):
Expand Down

0 comments on commit 97eff1c

Please sign in to comment.