Add parameters for scripts that talk to Gerrit

Not all gerrit installations are configured the same.  This adds parameters
to the gerrit sync script and expire script so that it can work from the
command line and cron on all servers.

Fixes bug #994201

Change-Id: Iac37e18aaf7a10fb5594be233e33b000eabed336
This commit is contained in:
Andrew Hutchings 2012-05-17 14:53:01 +01:00
parent 2f4f849dcb
commit ab8c2a7ba7
5 changed files with 33 additions and 11 deletions

View File

@ -149,6 +149,9 @@ node "gerrit.openstack.org", "review.openstack.org" {
} ], } ],
logo => 'openstack.png', logo => 'openstack.png',
war => 'http://ci.openstack.org/tarballs/gerrit-2.3-7-g1f029ab.war', war => 'http://ci.openstack.org/tarballs/gerrit-2.3-7-g1f029ab.war',
script_user => 'launchpadsync',
script_key_file => '/home/gerrit2/.ssh/launchpadsync_rsa',
script_site => 'openstack'
} }
} }
@ -171,6 +174,9 @@ node "gerrit-dev.openstack.org", "review-dev.openstack.org" {
} ], } ],
logo => 'openstack.png', logo => 'openstack.png',
war => 'http://ci.openstack.org/tarballs/gerrit-2.3-7-g1f029ab.war', war => 'http://ci.openstack.org/tarballs/gerrit-2.3-7-g1f029ab.war',
script_user => 'update',
script_key_file => '/home/gerrit2/.ssh/id_rsa',
script_site => 'openstack'
} }
} }

View File

@ -55,6 +55,9 @@ node "review.stackforge.org" {
} ], } ],
logo => 'stackforge.png', logo => 'stackforge.png',
war => 'http://ci.openstack.org/tarballs/gerrit-2.3-5-gaec571e.war', war => 'http://ci.openstack.org/tarballs/gerrit-2.3-5-gaec571e.war',
script_user => 'update',
script_key_file => '/home/gerrit2/.ssh/id_rsa',
script_site => 'stackforge'
} }
} }

View File

@ -22,10 +22,15 @@ import os
import paramiko import paramiko
import json import json
import logging import logging
import argparse
GERRIT_USER = os.environ.get('GERRIT_USER', 'launchpadsync') parser = argparse.ArgumentParser()
GERRIT_SSH_KEY = os.environ.get('GERRIT_SSH_KEY', parser.add_argument('user', help='The gerrit admin user')
'/home/gerrit2/.ssh/launchpadsync_rsa') parser.add_argument('ssh_key', help='The gerrit admin SSH key file')
options = parser.parse_args()
GERRIT_USER = options.user
GERRIT_SSH_KEY = options.ssh_key
logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s', filename='/var/log/gerrit/expire_reviews.log') logging.basicConfig(format='%(asctime)-6s: %(name)s - %(levelname)s - %(message)s', filename='/var/log/gerrit/expire_reviews.log')
logger= logging.getLogger('expire_reviews') logger= logging.getLogger('expire_reviews')

View File

@ -25,7 +25,7 @@ from datetime import datetime
import StringIO import StringIO
import ConfigParser import ConfigParser
import argparse
import MySQLdb import MySQLdb
from launchpadlib.launchpad import Launchpad from launchpadlib.launchpad import Launchpad
@ -36,13 +36,18 @@ from openid.cryptutil import randomString
DEBUG = False DEBUG = False
GERRIT_USER = os.environ.get('GERRIT_USER', 'launchpadsync') parser = argparse.ArgumentParser()
parser.add_argument('user', help='The gerrit admin user')
parser.add_argument('ssh_key', help='The gerrit admin SSH key file')
parser.add_argument('site', help='The site in use (typically openstack or stackforge)')
options = parser.parse_args()
GERRIT_USER = options.user
GERRIT_CONFIG = os.environ.get('GERRIT_CONFIG', GERRIT_CONFIG = os.environ.get('GERRIT_CONFIG',
'/home/gerrit2/review_site/etc/gerrit.config') '/home/gerrit2/review_site/etc/gerrit.config')
GERRIT_SECURE_CONFIG = os.environ.get('GERRIT_SECURE_CONFIG', GERRIT_SECURE_CONFIG = os.environ.get('GERRIT_SECURE_CONFIG',
'/home/gerrit2/review_site/etc/secure.config') '/home/gerrit2/review_site/etc/secure.config')
GERRIT_SSH_KEY = os.environ.get('GERRIT_SSH_KEY', GERRIT_SSH_KEY = options.ssh_key
'/home/gerrit2/.ssh/launchpadsync_rsa')
GERRIT_CACHE_DIR = os.path.expanduser(os.environ.get('GERRIT_CACHE_DIR', GERRIT_CACHE_DIR = os.path.expanduser(os.environ.get('GERRIT_CACHE_DIR',
'~/.launchpadlib/cache')) '~/.launchpadlib/cache'))
GERRIT_CREDENTIALS = os.path.expanduser(os.environ.get('GERRIT_CREDENTIALS', GERRIT_CREDENTIALS = os.path.expanduser(os.environ.get('GERRIT_CREDENTIALS',
@ -368,7 +373,7 @@ for (username, user_details) in users.items():
if os_project_name is not None: if os_project_name is not None:
if os_project_name.endswith("-core"): if os_project_name.endswith("-core"):
os_project_name = os_project_name[:-5] os_project_name = os_project_name[:-5]
os_project_name = "openstack/%s" % os_project_name os_project_name = "{site}/{project}".format(site=options.site, project=os_project_name)
if os_project_name in projects: if os_project_name in projects:
if not cur.execute("""select account_id if not cur.execute("""select account_id
from account_project_watches from account_project_watches

View File

@ -63,7 +63,10 @@ class gerrit($virtual_hostname='',
link => 'https://blueprints.launchpad.net/openstack/?searchtext=$2' }, link => 'https://blueprints.launchpad.net/openstack/?searchtext=$2' },
], ],
$logo, $logo,
$war $war,
$script_user,
$script_key_file,
$script_site
) { ) {
# Set this to true to disable cron jobs and replication, which can # Set this to true to disable cron jobs and replication, which can
@ -114,7 +117,7 @@ class gerrit($virtual_hostname='',
cron { "gerritsyncusers": cron { "gerritsyncusers":
user => gerrit2, user => gerrit2,
minute => "*/15", minute => "*/15",
command => 'sleep $((RANDOM\%60+60)) && python /usr/local/gerrit/scripts/update_gerrit_users.py', command => "sleep $((RANDOM\%60+60)) && python /usr/local/gerrit/scripts/update_gerrit_users.py ${script_user} ${script_key_file} ${script_site}",
require => File['/usr/local/gerrit/scripts'], require => File['/usr/local/gerrit/scripts'],
} }
@ -129,7 +132,7 @@ class gerrit($virtual_hostname='',
user => gerrit2, user => gerrit2,
hour => 6, hour => 6,
minute => 3, minute => 3,
command => 'python /usr/local/gerrit/scripts/expire_old_reviews.py', command => "python /usr/local/gerrit/scripts/expire_old_reviews.py ${script_user} ${script_key_file}",
require => File['/usr/local/gerrit/scripts'], require => File['/usr/local/gerrit/scripts'],
} }