Skip to content

Commit

Permalink
Fix to support multiple gerrit codebases (issue #3460)
Browse files Browse the repository at this point in the history
- Adds a check to the gerrit source step that this codebase is the one that
  has been changed
- Allows gerrit reporter to use the gerrit event.patchset.revision as its
  revision.  This allows for the possibility that the gerrit startVC has not
  yet been executed when a failure occurs, and so got_revision will not be
  set
  • Loading branch information
willlovett-arm committed Sep 22, 2017
1 parent cccd4d6 commit f2b69f1
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
1 change: 1 addition & 0 deletions master/buildbot/newsfragments/multiple-gerrit-repos.bugfix
@@ -0,0 +1 @@
Fix the Gerrit source step in the presence of multiple gerrit repos (:issue:`3460`).
5 changes: 3 additions & 2 deletions master/buildbot/reporters/gerrit.py
Expand Up @@ -389,8 +389,9 @@ def getProperty(build, name):
if getProperty(build, "event.change.id") is not None:
project = getProperty(build, "event.change.project")
codebase = getProperty(build, "codebase")
revision = getProperty(
build, "got_revision") or getProperty(build, "revision")
revision = (getProperty(build, "event.patchSet.revision") or
getProperty(build, "got_revision") or
getProperty(build, "revision"))

if isinstance(revision, dict):
# in case of the revision is a codebase revision, we just take
Expand Down
10 changes: 9 additions & 1 deletion master/buildbot/steps/source/gerrit.py
Expand Up @@ -26,7 +26,15 @@ def __init__(self, **kwargs):

def startVC(self, branch, revision, patch):
gerrit_branch = None
if self.build.hasProperty("event.patchSet.ref"):

changed_project = self.build.getProperty('event.change.project')
if (not self.sourcestamp or (self.sourcestamp.project !=
changed_project)):
# If we don't have a sourcestamp, or the project is wrong, this
# isn't the repo that's changed. Drop through and check out the
# head of the given branch
pass
elif self.build.hasProperty("event.patchSet.ref"):
gerrit_branch = self.build.getProperty("event.patchSet.ref")
self.updateSourceProperty("gerrit_branch", gerrit_branch)
else:
Expand Down
91 changes: 91 additions & 0 deletions master/buildbot/test/unit/test_steps_source_gerrit.py
Expand Up @@ -38,6 +38,8 @@ def test_mode_full_clean(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.build.setProperty("event.change.project", "buildbot")
self.sourcestamp.project = 'buildbot'
self.build.setProperty("event.patchSet.ref", "gerrit_branch")

self.expectCommands(
Expand Down Expand Up @@ -82,6 +84,8 @@ def test_mode_full_clean_force_build(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean'))
self.build.setProperty("event.change.project", "buildbot")
self.sourcestamp.project = 'buildbot'
self.build.setProperty("gerrit_change", "1234/567")

self.expectCommands(
Expand Down Expand Up @@ -121,3 +125,90 @@ def test_mode_full_clean_force_build(self):
self.expectProperty(
'got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Gerrit')
return self.runStep()

def test_mode_full_clean_force_same_project(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean', codebase='buildbot'))
self.build.setProperty("event.change.project", "buildbot")
self.sourcestamp.project = 'buildbot'
self.build.setProperty("gerrit_change", "1234/567")

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ ExpectShell.log('stdio',
stdout='git version 1.7.5')
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('listdir', {'dir': 'wkdir', 'logEnviron': True,
'timeout': 1200})
+ Expect.update('files', ['.git'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-f', '-d'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'refs/changes/34/1234/567'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'checkout', '-B', 'refs/changes/34/1234/567'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS)
self.expectProperty(
'got_revision', {'buildbot': 'f6ad368298bd941e934a41f3babc827b2aa95a1d'}, 'Gerrit')
return self.runStep()

def test_mode_full_clean_different_project(self):
self.setupStep(
gerrit.Gerrit(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean', codebase='buildbot'))
self.build.setProperty("event.change.project", "buildbot")
self.sourcestamp.project = 'not_buildbot'
self.build.setProperty("gerrit_change", "1234/567")

self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ ExpectShell.log('stdio',
stdout='git version 1.7.5')
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('listdir', {'dir': 'wkdir', 'logEnviron': True,
'timeout': 1200})
+ Expect.update('files', ['.git'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-f', '-d'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'HEAD'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS)
return self.runStep()

0 comments on commit f2b69f1

Please sign in to comment.