Remove recheckwatch module
No longer needed. Remove as part of module-split sprint. Also remove reference to it from openstack_project/zuul_prod.pp. Change-Id: I6424d6d7c22b240ca3f1453d5b8770ed56e61e12
This commit is contained in:
parent
d2ce03f45e
commit
8c1eb764df
@ -92,16 +92,4 @@ class openstack_project::zuul_dev(
|
||||
ensure => present,
|
||||
source => 'puppet:///modules/openstack_project/zuul/merger-logging.conf',
|
||||
}
|
||||
|
||||
class { '::recheckwatch':
|
||||
gerrit_server => $gerrit_server,
|
||||
gerrit_user => $gerrit_user,
|
||||
recheckwatch_ssh_private_key => $zuul_ssh_private_key,
|
||||
}
|
||||
|
||||
file { '/var/lib/recheckwatch/scoreboard.html':
|
||||
ensure => present,
|
||||
source => 'puppet:///modules/openstack_project/zuul/scoreboard.html',
|
||||
require => File['/var/lib/recheckwatch'],
|
||||
}
|
||||
}
|
||||
|
@ -100,16 +100,4 @@ class openstack_project::zuul_prod(
|
||||
ensure => present,
|
||||
source => 'puppet:///modules/openstack_project/zuul/merger-logging.conf',
|
||||
}
|
||||
|
||||
class { '::recheckwatch':
|
||||
gerrit_server => $gerrit_server,
|
||||
gerrit_user => $gerrit_user,
|
||||
recheckwatch_ssh_private_key => $zuul_ssh_private_key,
|
||||
}
|
||||
|
||||
file { '/var/lib/recheckwatch/scoreboard.html':
|
||||
ensure => present,
|
||||
source => 'puppet:///modules/openstack_project/zuul/scoreboard.html',
|
||||
require => File['/var/lib/recheckwatch'],
|
||||
}
|
||||
}
|
||||
|
@ -1,237 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2012 OpenStack Foundation
|
||||
#
|
||||
# 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.
|
||||
|
||||
import ConfigParser
|
||||
import datetime
|
||||
import re
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
import pickle
|
||||
import os
|
||||
|
||||
from genshi.template import TemplateLoader
|
||||
from launchpadlib.launchpad import Launchpad
|
||||
from launchpadlib.uris import LPNET_SERVICE_ROOT
|
||||
import daemon
|
||||
|
||||
CLOSED_STATUSES = ['Fix Released', 'Invalid', 'Fix Committed', 'Won\'t Fix']
|
||||
|
||||
try:
|
||||
import daemon.pidlockfile
|
||||
pid_file_module = daemon.pidlockfile
|
||||
except:
|
||||
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
|
||||
# instead it depends on lockfile-0.9.1
|
||||
import daemon.pidfile
|
||||
pid_file_module = daemon.pidfile
|
||||
|
||||
|
||||
class Hit(object):
|
||||
def __init__(self, project, change):
|
||||
self.project = project
|
||||
self.change = change
|
||||
self.ts = datetime.datetime.utcnow()
|
||||
|
||||
class Bug(object):
|
||||
def __init__(self, number):
|
||||
self.number = number
|
||||
self.hits = []
|
||||
self.projects = []
|
||||
self.changes = []
|
||||
self.last_seen = None
|
||||
self.first_seen = None
|
||||
self.duplicate_of = None
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
launchpad = Launchpad.login_anonymously('recheckwatch',
|
||||
'production')
|
||||
lpitem = launchpad.bugs[self.number]
|
||||
self.title = lpitem.title
|
||||
self.status = map(lambda x: x.status,
|
||||
lpitem.bug_tasks)
|
||||
if lpitem.duplicate_of:
|
||||
self.duplicate_of = lpitem.duplicate_of.id
|
||||
|
||||
def is_closed(self):
|
||||
closed = True
|
||||
for status in self.status:
|
||||
if status not in CLOSED_STATUSES:
|
||||
closed = False
|
||||
return closed
|
||||
|
||||
def addHit(self, hit):
|
||||
self.hits.append(hit)
|
||||
if not self.first_seen:
|
||||
self.first_seen = hit.ts
|
||||
if hit.project not in self.projects:
|
||||
self.projects.append(hit.project)
|
||||
if hit.change not in self.changes:
|
||||
self.changes.append(hit.change)
|
||||
self.last_seen = hit.ts
|
||||
|
||||
def addHits(self, hits):
|
||||
for hit in hits:
|
||||
self.addHit(hit)
|
||||
|
||||
class Scoreboard(threading.Thread):
|
||||
def __init__(self, config):
|
||||
threading.Thread.__init__(self)
|
||||
self.scores = {}
|
||||
|
||||
server = config.get('gerrit', 'host')
|
||||
username = config.get('gerrit', 'user')
|
||||
port = config.getint('gerrit', 'port')
|
||||
keyfile = config.get('gerrit', 'key', None)
|
||||
|
||||
self.pickle_dir = config.get('recheckwatch', 'pickle_dir')
|
||||
self.pickle_file = os.path.join(self.pickle_dir, 'scoreboard.pickle')
|
||||
self.template_dir = config.get('recheckwatch', 'template_dir')
|
||||
self.output_file = config.get('recheckwatch', 'output_file')
|
||||
self.age = config.getint('recheckwatch', 'age')
|
||||
self.closed_age = config.getint('recheckwatch', 'closed_age')
|
||||
self.regex = re.compile(config.get('recheckwatch', 'regex'))
|
||||
|
||||
if os.path.exists(self.pickle_file):
|
||||
out = open(self.pickle_file, 'rb')
|
||||
self.scores = pickle.load(out)
|
||||
out.close()
|
||||
|
||||
# Import here because it needs to happen after daemonization
|
||||
import gerritlib.gerrit
|
||||
self.gerrit = gerritlib.gerrit.Gerrit(server, username, port, keyfile)
|
||||
self._update_bug_format()
|
||||
self.update()
|
||||
|
||||
def _update_bug_format(self):
|
||||
for bugno, bug in self.scores.items():
|
||||
if not hasattr(bug, 'duplicate_of'):
|
||||
bug.duplicate_of = None
|
||||
bug.update()
|
||||
|
||||
def _read(self, data):
|
||||
if data.get('type', '') != 'comment-added':
|
||||
return
|
||||
comment = data.get('comment', '')
|
||||
m = self.regex.match(comment.strip())
|
||||
if not m:
|
||||
return
|
||||
change_record = data.get('change', {})
|
||||
change = change_record.get('number')
|
||||
project = change_record.get('project')
|
||||
bugno = int(m.group('bugno'))
|
||||
hit = Hit(project, change)
|
||||
bug = self._get_bug(bugno)
|
||||
bug.addHit(hit)
|
||||
self.scores[bugno] = bug
|
||||
self.update()
|
||||
|
||||
def _get_bug(self, bugno):
|
||||
""""Get latest bug information and create bug if not in score."""
|
||||
bug = self.scores.get(bugno)
|
||||
if not bug:
|
||||
bug = Bug(bugno)
|
||||
else:
|
||||
bug.update()
|
||||
return bug
|
||||
|
||||
def update(self):
|
||||
# Check for duplicate bugs
|
||||
dupes = []
|
||||
for bugno, bug in self.scores.items():
|
||||
if bug.duplicate_of:
|
||||
dupes.append(bugno)
|
||||
for bugno in dupes:
|
||||
dupno = self.scores[bugno].duplicate_of
|
||||
bug = self._get_bug(dupno)
|
||||
bug.addHits(self.scores[bugno].hits)
|
||||
self.scores[dupno] = bug
|
||||
del self.scores[bugno]
|
||||
|
||||
# Remove bugs that haven't been seen in ages
|
||||
# Or closed bugs older then self.closed_age
|
||||
to_remove = []
|
||||
now = datetime.datetime.utcnow()
|
||||
for bugno, bug in self.scores.items():
|
||||
if (bug.last_seen < now-datetime.timedelta(days=self.age) or
|
||||
(bug.is_closed() and
|
||||
bug.last_seen < now-datetime.timedelta(days=self.closed_age))):
|
||||
to_remove.append(bugno)
|
||||
for bugno in to_remove:
|
||||
del self.scores[bugno]
|
||||
|
||||
def impact(bug):
|
||||
"""Golf rules for bugs, smaller the more urgent."""
|
||||
age = (now - bug.last_seen).total_seconds()
|
||||
|
||||
if bug.is_closed():
|
||||
age = age + (5.0 * 86400.0)
|
||||
|
||||
return age
|
||||
|
||||
# Get the bugs reverse sorted by impact
|
||||
bugs = self.scores.values()
|
||||
# freshen to get lp bug status
|
||||
for bug in bugs:
|
||||
bug.update()
|
||||
bugs.sort(lambda a,b: cmp(impact(a), impact(b)))
|
||||
|
||||
loader = TemplateLoader([self.template_dir], auto_reload=True)
|
||||
tmpl = loader.load('scoreboard.html')
|
||||
out = open(self.output_file, 'w')
|
||||
out.write(tmpl.generate(bugs = bugs).render('html', doctype='html'))
|
||||
|
||||
out = open(self.pickle_file, 'wb')
|
||||
pickle.dump(self.scores, out, -1)
|
||||
out.close()
|
||||
|
||||
def run(self):
|
||||
self.gerrit.startWatching()
|
||||
while True:
|
||||
event = self.gerrit.getEvent()
|
||||
try:
|
||||
self._read(event)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
def _main(daemonize=True):
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(sys.argv[1])
|
||||
|
||||
s = Scoreboard(config)
|
||||
if daemonize:
|
||||
s.start()
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print "Usage: %s CONFIGFILE" % sys.argv[0]
|
||||
sys.exit(1)
|
||||
|
||||
if '-n' in sys.argv:
|
||||
_main(daemonize=False)
|
||||
elif '-d' in sys.argv:
|
||||
_main()
|
||||
else:
|
||||
pid = pid_file_module.TimeoutPIDLockFile(
|
||||
"/var/run/recheckwatch/recheckwatch.pid", 10)
|
||||
with daemon.DaemonContext(pidfile=pid):
|
||||
_main()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,146 +0,0 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: recheckwatch
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Recheckwatch
|
||||
# Description: Trunk gating system
|
||||
### END INIT INFO
|
||||
|
||||
# Do NOT "set -e"
|
||||
|
||||
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="Recheckwatch"
|
||||
NAME=recheckwatch
|
||||
DAEMON=/usr/local/bin/recheckwatch
|
||||
DAEMON_ARGS=/etc/recheckwatch/recheckwatch.conf
|
||||
PIDFILE=/var/run/$NAME/$NAME.pid
|
||||
SCRIPTNAME=/etc/init.d/$NAME
|
||||
USER=recheckwatch
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
||||
|
||||
# Load the VERBOSE setting and other rcS variables
|
||||
. /lib/init/vars.sh
|
||||
|
||||
# Define LSB log_* functions.
|
||||
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
||||
. /lib/lsb/init-functions
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
#
|
||||
do_start()
|
||||
{
|
||||
# Return
|
||||
# 0 if daemon has been started
|
||||
# 1 if daemon was already running
|
||||
# 2 if daemon could not be started
|
||||
|
||||
mkdir -p /var/run/$NAME
|
||||
chown $USER /var/run/$NAME
|
||||
start-stop-daemon --start --quiet --pidfile $PIDFILE -c $USER --exec $DAEMON --test > /dev/null \
|
||||
|| return 1
|
||||
start-stop-daemon --start --quiet --pidfile $PIDFILE -c $USER --exec $DAEMON -- \
|
||||
$DAEMON_ARGS \
|
||||
|| return 2
|
||||
# Add code here, if necessary, that waits for the process to be ready
|
||||
# to handle requests from services started subsequently which depend
|
||||
# on this one. As a last resort, sleep for some time.
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
do_stop()
|
||||
{
|
||||
# Return
|
||||
# 0 if daemon has been stopped
|
||||
# 1 if daemon was already stopped
|
||||
# 2 if daemon could not be stopped
|
||||
# other if a failure occurred
|
||||
start-stop-daemon --stop --signal 9 --pidfile $PIDFILE
|
||||
RETVAL="$?"
|
||||
[ "$RETVAL" = 2 ] && return 2
|
||||
rm -f /var/run/$NAME/*
|
||||
return "$RETVAL"
|
||||
}
|
||||
|
||||
#
|
||||
# Function that stops the daemon/service
|
||||
#
|
||||
do_graceful_stop()
|
||||
{
|
||||
PID=`cat $PIDFILE`
|
||||
kill -USR1 $PID
|
||||
|
||||
# wait until really stopped
|
||||
if [ -n "${PID:-}" ]; then
|
||||
i=0
|
||||
while kill -0 "${PID:-}" 2> /dev/null; do
|
||||
if [ $i -eq '0' ]; then
|
||||
echo -n " ... waiting "
|
||||
else
|
||||
echo -n "."
|
||||
fi
|
||||
i=$(($i+1))
|
||||
sleep 1
|
||||
done
|
||||
fi
|
||||
|
||||
rm -f /var/run/$NAME/*
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
||||
do_start
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
stop)
|
||||
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
||||
do_stop
|
||||
case "$?" in
|
||||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
||||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
||||
esac
|
||||
;;
|
||||
status)
|
||||
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
||||
;;
|
||||
#reload|force-reload)
|
||||
#
|
||||
# If do_reload() is not implemented then leave this commented out
|
||||
# and leave 'force-reload' as an alias for 'restart'.
|
||||
#
|
||||
#log_daemon_msg "Reloading $DESC" "$NAME"
|
||||
#do_reload
|
||||
#log_end_msg $?
|
||||
#;;
|
||||
restart|force-reload)
|
||||
#
|
||||
# If the "reload" option is implemented then remove the
|
||||
# 'force-reload' alias
|
||||
#
|
||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
||||
do_graceful_stop
|
||||
do_start
|
||||
;;
|
||||
*)
|
||||
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
|
||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
|
||||
:
|
@ -1,120 +0,0 @@
|
||||
# == Class: recheckwatch
|
||||
#
|
||||
class recheckwatch (
|
||||
$gerrit_server = '',
|
||||
$gerrit_user = '',
|
||||
$recheckwatch_ssh_private_key = '',
|
||||
) {
|
||||
|
||||
if ! defined(Package['python-daemon']) {
|
||||
package { 'python-daemon':
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
if ! defined(Package['python-genshi']) {
|
||||
package { 'python-genshi':
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
if ! defined(Package['python-launchpadlib']) {
|
||||
package { 'python-launchpadlib':
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
if ! defined(Package['gerritlib']) {
|
||||
package { 'gerritlib':
|
||||
ensure => latest,
|
||||
provider => pip,
|
||||
require => Class['pip'],
|
||||
}
|
||||
}
|
||||
|
||||
user { 'recheckwatch':
|
||||
ensure => present,
|
||||
home => '/home/recheckwatch',
|
||||
shell => '/bin/bash',
|
||||
gid => 'recheckwatch',
|
||||
managehome => true,
|
||||
require => Group['recheckwatch'],
|
||||
}
|
||||
|
||||
group { 'recheckwatch':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
file { '/etc/recheckwatch':
|
||||
ensure => directory,
|
||||
}
|
||||
|
||||
file { '/etc/recheckwatch/recheckwatch.conf':
|
||||
ensure => present,
|
||||
owner => 'recheckwatch',
|
||||
mode => '0400',
|
||||
content => template('recheckwatch/recheckwatch.conf.erb'),
|
||||
require => [
|
||||
File['/etc/recheckwatch'],
|
||||
User['recheckwatch'],
|
||||
],
|
||||
notify => Service['recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/var/run/recheckwatch':
|
||||
ensure => directory,
|
||||
owner => 'recheckwatch',
|
||||
require => User['recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/var/www/recheckwatch':
|
||||
ensure => directory,
|
||||
owner => 'recheckwatch',
|
||||
mode => '0755',
|
||||
require => User['recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/var/lib/recheckwatch':
|
||||
ensure => directory,
|
||||
owner => 'recheckwatch',
|
||||
require => User['recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/var/lib/recheckwatch/ssh':
|
||||
ensure => directory,
|
||||
owner => 'recheckwatch',
|
||||
group => 'recheckwatch',
|
||||
mode => '0500',
|
||||
require => File['/var/lib/recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/var/lib/recheckwatch/ssh/id_rsa':
|
||||
owner => 'recheckwatch',
|
||||
group => 'recheckwatch',
|
||||
mode => '0400',
|
||||
require => File['/var/lib/recheckwatch/ssh'],
|
||||
content => $recheckwatch_ssh_private_key,
|
||||
}
|
||||
|
||||
file { '/etc/init.d/recheckwatch':
|
||||
ensure => present,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0555',
|
||||
source => 'puppet:///modules/recheckwatch/recheckwatch.init',
|
||||
}
|
||||
|
||||
service { 'recheckwatch':
|
||||
name => 'recheckwatch',
|
||||
enable => true,
|
||||
hasrestart => true,
|
||||
require => File['/etc/init.d/recheckwatch'],
|
||||
}
|
||||
|
||||
file { '/usr/local/bin/recheckwatch':
|
||||
ensure => present,
|
||||
mode => '0555',
|
||||
source => 'puppet:///modules/recheckwatch/recheckwatch',
|
||||
notify => Service['recheckwatch'],
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
[recheckwatch]
|
||||
pickle_dir=/var/lib/recheckwatch
|
||||
template_dir=/var/lib/recheckwatch
|
||||
output_file=/var/www/recheckwatch/rechecks.html
|
||||
age=30 ; days
|
||||
closed_age=5 ; days
|
||||
regex=(?i)^(?P<verb>recheck|reverify) (?:bug|lp)[\s#:]*(?P<bugno>\d+)$
|
||||
|
||||
[gerrit]
|
||||
host=<%= gerrit_server %>
|
||||
user=<%= gerrit_user %>
|
||||
key=/var/lib/recheckwatch/ssh/id_rsa
|
||||
port=29418
|
Loading…
Reference in New Issue
Block a user