diff --git a/cts/LSBDummy.in b/cts/LSBDummy.in new file mode 100755 index 0000000000..b6a3c20400 --- /dev/null +++ b/cts/LSBDummy.in @@ -0,0 +1,24 @@ +#!/bin/sh +# +# WARNING: This script is for CTS testing only +# + +ra=@OCF_RA_DIR@/heartbeat/IPaddr +ip="127.0.0.100" + +rc=0 +case $1 in + start) OCF_RESKEY_ip=$ip $ra start + rc=$?;; + stop) OCF_RESKEY_ip=$ip $ra stop + rc=$?;; + status) OCF_RESKEY_ip=$ip $ra status + rc=$?;; + restart)OCF_RESKEY_ip=$ip $ra start + rc=$?;; + try-restart) rc=0;; + reload) rc=0;; + force-reload) rc=0;; +esac + +exit $rc diff --git a/cts/Makefile.am b/cts/Makefile.am index 36360ce548..55cc33da07 100644 --- a/cts/Makefile.am +++ b/cts/Makefile.am @@ -1,37 +1,44 @@ # # heartbeat: Linux-HA heartbeat code # # Copyright (C) 2001 Michael Moerz # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in harddir = $(libdir)/heartbeat/cts hard_SCRIPTS = \ CM_fs.py \ CM_hb.py \ CM_LinuxHAv2.py \ CTS.py \ CTSaudits.py \ CTSlab.py \ CTSproxy.py \ CTStests.py \ extracttests.py \ OCFIPraTest.py \ CIB.py hard_DATA = README + +ocfdir = $(OCF_RA_DIR)/heartbeat/ +ocf_SCRIPTS = OCFDummy2 + +lsbdir = /etc/init.d/ +lsb_SCRIPTS = LSBDummy + diff --git a/cts/OCFDummy2.in b/cts/OCFDummy2.in new file mode 100755 index 0000000000..e25b5c8cfc --- /dev/null +++ b/cts/OCFDummy2.in @@ -0,0 +1,230 @@ +#!/bin/sh +# +# License: GNU General Public License (GPL) +# Support: linux-ha@lists.linux-ha.org +# +# +# WARNING: this script is for CTS testing only. +# +# This script support master-slave operations +# It writes the instance information to a file named $DUMMY_RESOURCE, +# in the following format: +# +# INSTANCE state running status +# instance0 slave running +# instance1 master failed +# +# +# start: append a line to the file, +# or change the running status if the resource instance exist. +# stop: remove the instance from the file +# promote/demote: change the state +# notify: do nothing +# +# +# besides, all opertions will sleep for 1 second by default +# + +. @hb_libdir@/ocf-shellfuncs + +AWK=gawk + +CRM_MASTER="/usr/sbin/crm_master" +DUMMY_RESOURCE="/tmp/OCFDummyMasterSlave:resource" +DUMMY_LOGFILE="/var/log/OCFDummyMasterSlave.log" + +start_delay=1 +stop_delay=1 +monitor_delay=1 +promote_delay=1 +demote_delay=1 +notify_delay=1 + +dummy_log () { + echo `date +%T` $1 $2 $3 >> $DUMMY_LOGFILE +} + +do_cmd() { + local cmd="$*" + ocf_log debug "$RESOURCE: Calling $cmd" + local cmd_out=$($cmd 2>&1) + ret=$? + + if [ $ret -ne 0 ]; then + ocf_log err "$RESOURCE: Called $cmd" + ocf_log err "$RESOURCE: Exit code $ret" + ocf_log err "$RESOURCE: Command output: $cmd_out" + else + ocf_log debug "$RESOURCE: Exit code $ret" + ocf_log debug "$RESOURCE: Command output: $cmd_out" + fi + + echo $cmd_out + return $ret +} + + +dummy_get_status() { + instance="instance$1" + grep $instance $DUMMY_RESOURCE 2>&1 >/dev/null + if [ ! $? -eq 0 ]; then + echo "$instance not running" + return $OCF_NOT_RUNNING + fi + grep $instance $DUMMY_RESOURCE | grep "master" 2>&1 >/dev/null + state=$? + grep $instance $DUMMY_RESOURCE | grep "running" 2>&1 >/dev/null + running=$? + + if [ $state -eq 0 ]; then # master + if [ $running -eq 0 ]; then + echo "$instance is running as master" + return $OCF_RUNNING_MASTER + else + echo "$instance is master, error" + return $OCF_FAILED_MASTER + fi + else # slave + if [ $running -eq 0 ]; then + echo "$instance is running as slave" + return $OCF_SUCCESS + else + echo "%instance is slave, error" + return $OCF_ERR_GENERIC + fi + fi +} + + +do_start_resource () { + instance="instance$1" + state=$2 + grep $instance $DUMMY_RESOURCE 2>&1 > /dev/null + if [ $? -eq 0 ]; then # found instance + regexp="s/$instance.*/$instance $state running/" + cat $DUMMY_RESOURCE | sed -e "$regexp" > $DUMMY_RESOURCE + else # instance not exist + echo -e "$instance $state running" >> $DUMMY_RESOURCE + fi + return $OCF_SUCCESS +} + +# stop, delete instance from the file +do_stop_resource () { + instance="instance$1" + cat $DUMMY_RESOURCE | grep -v $instance > $DUMMY_RESOURCE + return $OCF_SUCCESS +} + +do_change_state() { + instance="instance"$1 + state=$2 + regexp="s/$instance .* \(.*\)/$instance $state \1/" + cat $DUMMY_RESOURCE | sed -e "$regexp" > $DUMMY_RESOURCE +} + + +dummy_start() { + touch $DUMMY_RESOURCE + sleep $start_delay + dummy_log "do_start_resource $OCF_RESKEY_clone slave" + do_start_resource $OCF_RESKEY_clone "slave" + if [ $OCF_RESKEY_clone -eq 0 ]; then + do_cmd $CRM_MASTER -D + do_cmd $CRM_MASTER -v 1000 + fi + return $OCF_SUCCESS +} + +dummy_stop() { + touch $DUMMY_RESOURCE + sleep $stop_delay + dummy_log "do_stop_resource $OCF_RESKEY_clone" + do_stop_resource $OCF_RESKEY_clone + return $OCF_SUCCESS +} + +dummy_monitor() { + dummy_log "monitor instance $OCF_RESKEY_clone" + touch $DUMMY_RESOURCE + sleep $monitor_delay + dummy_get_status $OCF_RESKEY_clone +} + +dummy_promote() { + dummy_log "promote instance $OCF_RESKEY_clone" + touch $DUMMY_RESOURCE + sleep $promote_delay + do_change_state $OCF_RESKEY_clone "master" +} + +dummy_demote() { + dummy_log "demote instance $OCF_RESKEY_clone" + touch $DUMMY_RESOURCE + sleep $demote_delay + do_change_state $OCF_RESKEY_clone "slave" +} + +dummy_notify() { + dummy_log "notify instance $OCF_RESKEY_clone" + touch $DUMMY_RESOURCE + sleep $notify_delay + local n_type="$OCF_RESKEY_notify_type" + local n_op="$OCF_RESKEY_notify_operation" + set -- $n_active_resource + local n_active="$#" + set -- $notify_stop_resource + local n_stop="$#" + set -- $notify_start_resource + local n_start="$#" + + ocf_log debug "$RESOURCE notify: $n_type for $n_op - counts: active $n_active - starting $n_start - stopping $n_stop" + case $n_type in + pre) + case $n_op in + promote) # TODO: + # Resist promotion of the other side in case we + # are already primary - though the CRM should + # not even attempt that. + ;; + esac + ;; + post) + case $n_op in + start) + ;; + # TODO: Does "fence" actually happen? + stop|fence) + # This MUST be a notification for the other side + # having been stopped, because for sure we won't + # receive one for ourselves being stopped ;-) + # So to allow continuing with freeze_io, we need + # to explicitly disconnect. + ;; + monitor) + # TODO: We don't get notifications for failed + # monitors yet. + ;; + esac + ;; + esac + return $OCF_SUCCESS +} + + +if + [ $# -ne 1 ] +then + echo "$0 start|stop|status|monitor|promote|demote|notify" + exit $OCF_ERR_ARGS +fi + +case $1 in + start) dummy_start ;; + stop) dummy_stop ;; + monitor) dummy_monitor ;; + promote) dummy_promote ;; + demote) dummy_demote ;; + notify) dummy_notify ;; + *) exit $OCF_ERR_ARGS ;; +esac