From 2a26e7f20b3c18615459923490c8a235c1ca9a8f Mon Sep 17 00:00:00 2001
From: Mikhail S Medvedev <mmedvede@us.ibm.com>
Date: Wed, 28 Jan 2015 15:23:44 -0600
Subject: [PATCH] Split out gerritbot module

The spec:
http://specs.openstack.org/openstack-infra/infra-specs/specs/puppet-modules.html

Depends-On: Ib02402b9aeccc503d5543129a209700178e13570
Change-Id: I13a71f5f517f56386b2eb9c215ba976ecb34c9b5
---
 modules.env                                   |   1 +
 modules/gerritbot/files/gerritbot.init        | 149 ------------------
 modules/gerritbot/files/logging.config        |  44 ------
 modules/gerritbot/manifests/init.pp           | 106 -------------
 .../gerritbot/templates/gerritbot.config.erb  |  14 --
 5 files changed, 1 insertion(+), 313 deletions(-)
 delete mode 100755 modules/gerritbot/files/gerritbot.init
 delete mode 100644 modules/gerritbot/files/logging.config
 delete mode 100644 modules/gerritbot/manifests/init.pp
 delete mode 100644 modules/gerritbot/templates/gerritbot.config.erb

diff --git a/modules.env b/modules.env
index 3ac8acedd0..88fc1f08de 100644
--- a/modules.env
+++ b/modules.env
@@ -62,6 +62,7 @@ INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-elasticsea
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-etherpad_lite"]="origin/master"
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-elastic_recheck"]="origin/master"
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-gerrit"]="origin/master"
+INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-gerritbot"]="origin/master"
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-graphite"]="origin/master"
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-statusbot"]="origin/master"
 INTEGRATION_MODULES["https://git.openstack.org/openstack-infra/puppet-storyboard"]="origin/master"
diff --git a/modules/gerritbot/files/gerritbot.init b/modules/gerritbot/files/gerritbot.init
deleted file mode 100755
index 8258a01c58..0000000000
--- a/modules/gerritbot/files/gerritbot.init
+++ /dev/null
@@ -1,149 +0,0 @@
-#! /bin/sh
-### BEGIN INIT INFO
-# Provides:          gerritbot
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
-# Default-Start:     2 3 4 5
-# Default-Stop:      0 1 6
-# Short-Description: Gerrit IRC Bot
-# Description:       Announces Gerrit events to IRC
-### END INIT INFO
-
-# Author: James Blair <james.blair@rackspace.com>
-
-# 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="GerritBot"
-NAME=gerritbot
-DAEMON=/usr/local/bin/$NAME
-DAEMON_ARGS="/etc/gerritbot/gerritbot.config"
-PIDFILE=/var/run/$NAME/$NAME.pid
-SCRIPTNAME=/etc/init.d/$NAME
-USER=gerrit2
-
-# 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 sends a SIGHUP to the daemon/service
-#
-do_reload() {
-	#
-	# If the daemon can reload its configuration without
-	# restarting (for example, when it is sent a SIGHUP),
-	# then implement that here.
-	#
-	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
-	return 0
-}
-
-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_stop
-	case "$?" in
-	  0|1)
-		do_start
-		case "$?" in
-			0) log_end_msg 0 ;;
-			1) log_end_msg 1 ;; # Old process is still running
-			*) log_end_msg 1 ;; # Failed to start
-		esac
-		;;
-	  *)
-	  	# Failed to stop
-		log_end_msg 1
-		;;
-	esac
-	;;
-  *)
-	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
-	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
-	exit 3
-	;;
-esac
-
-:
diff --git a/modules/gerritbot/files/logging.config b/modules/gerritbot/files/logging.config
deleted file mode 100644
index 4e4deff756..0000000000
--- a/modules/gerritbot/files/logging.config
+++ /dev/null
@@ -1,44 +0,0 @@
-[loggers]
-keys=root,gerrit,gerritbot
-
-[handlers]
-keys=console,debug,normal
-
-[formatters]
-keys=simple
-
-[logger_root]
-level=WARNING
-handlers=console
-
-[logger_gerrit]
-level=DEBUG
-handlers=debug,normal
-qualname=gerrit
-
-[logger_gerritbot]
-level=DEBUG
-handlers=debug,normal
-qualname=gerritbot
-
-[handler_console]
-level=WARNING
-class=StreamHandler
-formatter=simple
-args=(sys.stdout,)
-
-[handler_debug]
-level=DEBUG
-class=logging.handlers.TimedRotatingFileHandler
-formatter=simple
-args=('/var/log/gerritbot/gerritbot_debug.log', 'midnight', 1, 30,)
-
-[handler_normal]
-level=INFO
-class=logging.handlers.TimedRotatingFileHandler
-formatter=simple
-args=('/var/log/gerritbot/gerritbot.log', 'midnight', 1, 30,)
-
-[formatter_simple]
-format=%(asctime)s %(levelname)s %(name)s: %(message)s
-datefmt=
diff --git a/modules/gerritbot/manifests/init.pp b/modules/gerritbot/manifests/init.pp
deleted file mode 100644
index a4fa76ac5e..0000000000
--- a/modules/gerritbot/manifests/init.pp
+++ /dev/null
@@ -1,106 +0,0 @@
-# == Class: gerritbot
-#
-class gerritbot(
-  $nick = '',
-  $password = '',
-  $server = '',
-  $user = '',
-  $vhost_name = '',
-  $ssh_rsa_key_contents = '',
-  $ssh_rsa_pubkey_contents = '',
-  $channel_file = '',
-) {
-  include pip
-
-  package { 'gerritbot':
-    ensure   => present,  # Pip upgrade is not working
-    provider => pip,
-    require  => Class['pip'],
-  }
-
-  file { '/etc/init.d/gerritbot':
-    ensure  => present,
-    group   => 'root',
-    mode    => '0555',
-    owner   => 'root',
-    require => Package['gerritbot'],
-    source  => 'puppet:///modules/gerritbot/gerritbot.init',
-  }
-
-  service { 'gerritbot':
-    ensure     => running,
-    enable     => true,
-    hasrestart => true,
-    require    => File['/etc/init.d/gerritbot'],
-    subscribe  => [
-      Package['gerritbot'],
-      File['/etc/gerritbot/gerritbot.config'],
-      File['/etc/gerritbot/channel_config.yaml'],
-    ],
-  }
-
-  file { '/etc/gerritbot':
-    ensure => directory,
-  }
-
-  file { '/var/log/gerritbot':
-    ensure => directory,
-    group  => 'gerrit2',
-    mode   => '0775',
-    owner  => 'root',
-  }
-
-  file { '/etc/gerritbot/channel_config.yaml':
-    ensure  => present,
-    group   => 'gerrit2',
-    mode    => '0440',
-    owner   => 'root',
-    replace => true,
-    require => User['gerrit2'],
-    source  => $channel_file,
-  }
-
-  file { '/etc/gerritbot/logging.config':
-    ensure  => present,
-    group   => 'gerrit2',
-    mode    => '0440',
-    owner   => 'root',
-    replace => true,
-    require => User['gerrit2'],
-    source  => 'puppet:///modules/gerritbot/logging.config',
-  }
-
-  file { '/etc/gerritbot/gerritbot.config':
-    ensure  => present,
-    content => template('gerritbot/gerritbot.config.erb'),
-    group   => 'gerrit2',
-    mode    => '0440',
-    owner   => 'root',
-    replace => true,
-    require => User['gerrit2'],
-  }
-
-  if $ssh_rsa_key_contents != '' {
-    file { '/home/gerrit2/.ssh/gerritbot_rsa':
-      owner   => 'gerrit2',
-      group   => 'gerrit2',
-      mode    => '0600',
-      content => $ssh_rsa_key_contents,
-      replace => true,
-      require => File['/home/gerrit2/.ssh']
-    }
-  }
-
-  if $ssh_rsa_pubkey_contents != '' {
-    file { '/home/gerrit2/.ssh/gerritbot_rsa.pub':
-      owner   => 'gerrit2',
-      group   => 'gerrit2',
-      mode    => '0644',
-      content => $ssh_rsa_pubkey_contents,
-      replace => true,
-      require => File['/home/gerrit2/.ssh']
-    }
-  }
-}
-
-# vim:sw=2:ts=2:expandtab:textwidth=79
diff --git a/modules/gerritbot/templates/gerritbot.config.erb b/modules/gerritbot/templates/gerritbot.config.erb
deleted file mode 100644
index e8c2fcdca7..0000000000
--- a/modules/gerritbot/templates/gerritbot.config.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-[ircbot]
-nick=<%= nick %>
-pass=<%= password %>
-server=<%= server %>
-port=6667
-channel_config=/etc/gerritbot/channel_config.yaml
-lockfile=/var/run/gerritbot/gerritbot.pid
-log_config=/etc/gerritbot/logging.config
-
-[gerrit]
-user=<%= user %>
-key=/home/gerrit2/.ssh/gerritbot_rsa
-host=<%= vhost_name %>
-port=29418