diff --git a/manifests/site.pp b/manifests/site.pp index cd54ae940a..07c5338c7b 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -143,6 +143,10 @@ node "gerrit.openstack.org", "review.openstack.org" { name => 'openstack/python-cinderclient', close_pull => 'true' } ], + upstream_projects => [ { + name => 'openstack-ci/gerrit', + remote => 'https://gerrit.googlesource.com/gerrit' + } ], logo => 'openstack.png', war => 'http://ci.openstack.org/tarballs/gerrit-2.3-7-g1f029ab.war', } diff --git a/modules/gerrit/files/scripts/fetch_remotes.py b/modules/gerrit/files/scripts/fetch_remotes.py new file mode 100755 index 0000000000..19df462fdf --- /dev/null +++ b/modules/gerrit/files/scripts/fetch_remotes.py @@ -0,0 +1,79 @@ +#! /usr/bin/env python +# Copyright (C) 2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +# Ensure that the specified remote exists in the repo and pull revisions +# from upstream + +# [project "UPSTREAM_PROJECT"] +# remote = https://gerrit.googlesource.com/gerrit + +import ConfigParser +import StringIO +import logging +import os +import re +import subprocess + + +def run_command(cmd, status=False, env={}): + if VERBOSE: + print datetime.datetime.now(), "Running:", cmd + cmd_list = shlex.split(str(cmd)) + newenv = os.environ + newenv.update(env) + p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, env=newenv) + (out, nothing) = p.communicate() + if status: + return (p.returncode, out.strip()) + return out.strip() + + +def run_command_status(cmd, env={}): + return run_command(cmd, True, env) + + +logging.basicConfig(level=logging.ERROR) + +REPO_ROOT = os.environ.get('REPO_ROOT', + '/home/gerrit2/git') +REMOTES_CONFIG = os.environ.get('REMOTES_CONFIG', + '/home/gerrit2/remote.config') + +PROJECT_RE = re.compile(r'^project\s+"(.*)"$') + +config = ConfigParser.ConfigParser() +config.read(REMOTES_CONFIG) + + +for section in config.sections(): + # Each section looks like [project "openstack/project"] + m = PROJECT_RE.match(section) + if not m: + continue + project = m.group(1) + project_git = "%s.git" % project + os.chdir(os.path.join(REPO_ROOT, project_git)) + + if not (config.has_option(section, "remote")): + continue + + # Make sure that the specified remote exists + remote_url = config.get(section, "remote") + # We could check if it exists first, but we're ignoring output anyway + # So just try to make it, and it'll either make a new one or do nothing + run_command("git remote add -f upstream %s" % remote_url) + # Fetch new revs from it + run_command("git remote update upstream") diff --git a/modules/gerrit/manifests/init.pp b/modules/gerrit/manifests/init.pp index a782791855..e0784c16f6 100644 --- a/modules/gerrit/manifests/init.pp +++ b/modules/gerrit/manifests/init.pp @@ -49,6 +49,7 @@ class gerrit($virtual_hostname='', $openidssourl="https://login.launchpad.net/+openid", $email='', $github_projects = [], + $upstream_projects = [], $commentlinks = [ { name => 'changeid', match => '(I[0-9a-f]{8,40})', link => '#q,$1,n,z' }, @@ -149,6 +150,13 @@ class gerrit($virtual_hostname='', environment => "PATH=/usr/bin:/bin:/usr/sbin:/sbin", } + cron { "gerritfetchremotes": + user => gerrit2, + minute => "*/30", + command => 'sleep $((RANDOM\%60+90)) && python /usr/local/gerrit/scripts/fetch_remotes.py', + require => File['/usr/local/gerrit/scripts'], + } + file { "/usr/local/gerrit/gerritbot": owner => 'root', group => 'root', @@ -225,6 +233,16 @@ class gerrit($virtual_hostname='', require => User["gerrit2"] } + file { '/home/gerrit2/remotes.config': + owner => 'root', + group => 'root', + mode => 444, + ensure => 'present', + content => template('gerrit/remotes.config.erb'), + replace => 'true', + require => User["gerrit2"] + } + file { '/home/gerrit2/review_site/static/title.png': ensure => 'present', source => "puppet:///modules/gerrit/${logo}", diff --git a/modules/gerrit/templates/remotes.config.erb b/modules/gerrit/templates/remotes.config.erb new file mode 100644 index 0000000000..2b9502f213 --- /dev/null +++ b/modules/gerrit/templates/remotes.config.erb @@ -0,0 +1,7 @@ +# This file is managed by puppet. +# https://github.com/openstack/openstack-ci-puppet + +<% upstream_projects.each do |project| -%> +[project "<%= project['name'] %>"] +remote = <%= project['remote'] %> +<% end -%>