Support sshkey in merger.

The gerrit trigger took an sshkey parameter, but the merger,
which uses GitPython, did not honor it.  Add a GIT_SSH wrapper
for the merger to use to support arbitrary ssh keys for remote
git operation.

Change-Id: I43f0830905ee7103a2acbfa4b4f90959254f60b2
Reviewed-on: https://review.openstack.org/17269
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Reviewed-by: Paul Belanger <paul.belanger@polybeacon.com>
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Approved: James E. Blair <corvus@inaugust.com>
Tested-by: Jenkins
This commit is contained in:
James E. Blair 2012-11-30 16:14:21 -08:00 committed by Jenkins
parent 138d3361f6
commit ad61501575
2 changed files with 18 additions and 2 deletions

View File

@ -108,13 +108,24 @@ class Repo(object):
class Merger(object):
log = logging.getLogger("zuul.Merger")
def __init__(self, trigger, working_root, push_refs):
def __init__(self, trigger, working_root, push_refs, sshkey):
self.trigger = trigger
self.repos = {}
self.working_root = working_root
if not os.path.exists(working_root):
os.makedirs(working_root)
self.push_refs = push_refs
if sshkey:
self._makeSSHWrapper(sshkey)
def _makeSSHWrapper(self, key):
name = os.path.join(self.working_root, '.ssh_wrapper')
fd = open(name, 'w')
fd.write('#!/bin/bash\n')
fd.write('ssh -i %s $@\n' % key)
fd.close()
os.chmod(name, 0755)
os.environ['GIT_SSH'] = name
def addProject(self, project, url):
try:

View File

@ -170,7 +170,12 @@ class Scheduler(threading.Thread):
push_refs = self.config.getboolean('zuul', 'push_change_refs')
else:
push_refs = False
self.merger = merger.Merger(self.trigger, merge_root, push_refs)
if self.config.has_option('gerrit', 'sshkey'):
sshkey = self.config.get('gerrit', 'sshkey')
else:
sshkey = None
self.merger = merger.Merger(self.trigger, merge_root, push_refs,
sshkey)
for project in self.projects.values():
url = self.trigger.getGitUrl(project)
self.merger.addProject(project, url)