Skip to content

Commit

Permalink
Issue 2464: Makes GitPoller write git based error to log file.
Browse files Browse the repository at this point in the history
    * Added GitError: Called when git returns with status
      code 128.
    * The error message is logged to twistd.log
    * Added test.
  • Loading branch information
Prasoon Shukla committed Mar 25, 2015
1 parent 0fdb4c7 commit 1ff7311
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
22 changes: 19 additions & 3 deletions master/buildbot/changes/gitpoller.py
Expand Up @@ -28,6 +28,10 @@
from buildbot.util.state import StateMixin


class GitError(Exception):
"""Raised when git exits with code 128."""


class GitPoller(base.PollingChangeSource, StateMixin):

"""This source will poll a remote git repo for changes and submit
Expand Down Expand Up @@ -145,7 +149,11 @@ def _trackerBranch(self, branch):

@defer.inlineCallbacks
def poll(self):
yield self._dovccmd('init', ['--bare', self.workdir])
try:
yield self._dovccmd('init', ['--bare', self.workdir])
except GitError, e:
log.msg(e.args[0])
return

branches = self.branches
if branches is True or callable(branches):
Expand All @@ -159,8 +167,13 @@ def poll(self):
'+%s:%s' % (self._removeHeads(branch), self._trackerBranch(branch))
for branch in branches
]
yield self._dovccmd('fetch',
[self.repourl] + refspecs, path=self.workdir)

try:
yield self._dovccmd('fetch', [self.repourl] + refspecs,
path=self.workdir)
except GitError, e:
log.msg(e.args[0])
return

revs = {}
log.msg('gitpoller: processing changes from "%s"' % (self.repourl,))
Expand Down Expand Up @@ -311,6 +324,9 @@ def _convert_nonzero_to_failure(res,
"utility to handle the result of getProcessOutputAndValue"
(stdout, stderr, code) = res
if code != 0:
if code == 128:
raise GitError('command %s %s in %s on repourl %s failed with exit code %d: %s'
% (command, args, path, self.repourl, code, stderr))
raise EnvironmentError('command %s %s in %s on repourl %s failed with exit code %d: %s'
% (command, args, path, self.repourl, code, stderr))
return stdout.strip()
Expand Down
27 changes: 27 additions & 0 deletions master/buildbot/test/unit/test_changes_gitpoller.py
Expand Up @@ -22,6 +22,7 @@
from buildbot.test.util import changesource
from buildbot.test.util import config
from buildbot.test.util import gpo
from buildbot.test.util import logging
from twisted.internet import defer
from twisted.trial import unittest

Expand Down Expand Up @@ -153,6 +154,7 @@ def test_get_commit_timestamp(self):

class TestGitPoller(gpo.GetProcessOutputMixin,
changesource.ChangeSourceMixin,
logging.LoggingMixin,
unittest.TestCase):

REPOURL = 'git@example.com:foo/baz.git'
Expand Down Expand Up @@ -285,6 +287,31 @@ def cb(_):
'master': '4423cdbcbb89c14e50dd5f4152415afd686c5241'
})

def test_poll_GitError(self):
# Raised when git exits with status code 128. See issue 2468
self.expectCommands(
gpo.Expect('git', 'init', '--bare', 'gitpoller-work')
.exit(128),
)

d = self.assertFailure(self.poller._dovccmd('init', ['--bare',
'gitpoller-work']), gitpoller.GitError)

d.addCallback(lambda _: self.assertAllCommandsRan())
return d

def test_poll_GitError_log(self):
self.setUpLogging()
self.expectCommands(
gpo.Expect('git', 'init', '--bare', 'gitpoller-work')
.exit(128),
)

d = self.poller.poll()
d.addCallback(lambda _: self.assertAllCommandsRan())
self.assertLogged("command.*on repourl.*failed.*exit code 128.*")
return d

def test_poll_nothingNew(self):
# Test that environment variables get propagated to subprocesses
# (See #2116)
Expand Down

0 comments on commit 1ff7311

Please sign in to comment.