summaryrefslogtreecommitdiffstats
path: root/cts/lab/cluster_test.in
blob: 1741b472c04087ed7cc9223c7064d4f892dccf76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!@BASH_PATH@
#
# Copyright 2008-2020 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
# This source code is licensed under the GNU General Public License version 2
# or later (GPLv2+) WITHOUT ANY WARRANTY.
#
if [ -e ~/.cts ]; then
    . ~/.cts
fi
anyAsked=0

[ $# -lt 1 ] || CTS_numtests=$1

die() { echo "$@"; exit 1; }

if [ -z "$CTS_asked_once" ]; then
    anyAsked=1
    echo "This script should only be executed on the test exerciser."
    echo "The test exerciser will remotely execute the actions required by the"
    echo "tests and should not be part of the cluster itself."
    
    read -p "Is this host intended to be the test exerciser? (yN) " doUnderstand
    [ "$doUnderstand" = "y" ] \
        || die "This script must be executed on the test exerciser"
fi

if [ -z "$CTS_node_list" ]; then
    anyAsked=1
    read -p "Please list your cluster nodes (eg. node1 node2 node3): " CTS_node_list
else
    echo "Beginning test of cluster: $CTS_node_list"
fi

if [ -z "$CTS_stack" ]; then
    anyAsked=1
    read -p "Which cluster stack are you using? ([corosync]): " CTS_stack
    [ -n "$CTS_stack" ] || CTS_stack=corosync
else
    echo "Using the $CTS_stack cluster stack"
fi

[ "${CTS_node_list}" = "${CTS_node_list/$HOSTNAME/}" ] \
    || die "This script must be executed on the test exerciser, and the test exerciser cannot be part of the cluster"

printf "+ Bootstrapping ssh... "
if [ -z "$SSH_AUTH_SOCK" ]; then
    printf "\n + Initializing SSH "
    eval "$(ssh-agent)"
    echo " + Adding identities..."
    ssh-add
    rc=$?
    if [ $rc -ne 0 ]; then
	echo " -- No identities added"
	printf "\nThe ability to open key-based 'ssh' connections (as the user 'root') is required to use CTS.\n"

	read -p " - Do you want this program to help you create one? (yN) " auto_fix
	if [ "$auto_fix" = "y" ]; then
	    ssh-keygen -t dsa
	    ssh-add
	else
	    die "Please run 'ssh-keygen -t dsa' to create a new key"
	fi
    fi
else
    echo "OK"
fi

test_ok=1
printf "+ Testing ssh configuration... "
for n in $CTS_node_list; do
    ssh -l root -o PasswordAuthentication=no -o ConnectTimeout=5 "$n" /bin/true
    rc=$?
    if [ $rc -ne 0 ]; then
	echo " - connection to $n failed"
	test_ok=0
    fi
done

if [ $test_ok -eq 0 ]; then
    printf "\nThe ability to open key-based 'ssh' connections (as the user 'root') is required to use CTS.\n"

    read -p " - Do you want this program to help you with such a setup? (yN) " auto_fix
    if [ "$auto_fix" = "y" ]; then
        # XXX are we picking the most suitable identity?
        privKey=$(ssh-add -L | head -n1 | cut -d" " -f3)
        sshCopyIdOpts="-o User=root"
        [ -z "$privKey" ] || sshCopyIdOpts+=" -i \"${privKey}.pub\""
        for n in $CTS_node_list; do
            eval "ssh-copy-id $sshCopyIdOpts \"${n}\"" \
                || die "Attempt to 'ssh-copy-id $sshCopyIdOpts \"$n\"' failed"
        done
    else
        die "Please install one of your SSH public keys to root's account on all cluster nodes"
    fi
fi
echo "OK"

if [ -z "$CTS_logfile" ]; then
    anyAsked=1
    read -p " + Where does/should syslog store logs from remote hosts? (/var/log/messages) " CTS_logfile
    [ -n "$CTS_logfile" ] || CTS_logfile=/var/log/messages
fi

[ -e "$CTS_logfile" ] || die "$CTS_logfile doesn't exist"

if [ -z "$CTS_logfacility" ]; then
    anyAsked=1
    read -p " + Which log facility does the cluster use? (daemon) " CTS_logfacility
    [ -n "$CTS_logfacility" ] || CTS_logfacility=daemon
fi

if [ -z "$CTS_boot" ]; then
    read -p "+ Is the cluster software started automatically when a node boots? [yN] " CTS_boot
    if [ -z "$CTS_boot" ]; then
	CTS_boot=0
    else
	case $CTS_boot in
	    1|y|Y) CTS_boot=1;;
	    *) CTS_boot=0;;
	esac
    fi
fi

if [ -z "$CTS_numtests" ]; then
    read -p "+ How many test iterations should be performed? (500) " CTS_numtests
    [ -n "$CTS_numtests" ] || CTS_numtests=500
fi

if [ -z "$CTS_asked_once" ]; then
    anyAsked=1
    read -p "+ What type of STONITH agent do you use? (none) " CTS_stonith
    [ -z "$CTS_stonith" ] \
        || read -p "+ List any STONITH agent parameters (eq. device_host=switch.power.com): " CTS_stonith_args
    [ -n "$CTS_adv" ] \
        || read -p "+ (Advanced) Any extra CTS parameters? (none) " CTS_adv
fi

[ $anyAsked -eq 0 ] \
    || read -p "+ Save values to ~/.cts for next time? (yN) " doSave

if [ "$doSave" = "y" ]; then
    cat > ~/.cts <<-EOF
	# CTS Test data
	CTS_stack="$CTS_stack"
	CTS_node_list="$CTS_node_list"
	CTS_logfile="$CTS_logfile"
	CTS_logport="$CTS_logport"
	CTS_logfacility="$CTS_logfacility"
	CTS_asked_once=1
	CTS_adv="$CTS_adv"
	CTS_stonith="$CTS_stonith"
	CTS_stonith_args="$CTS_stonith_args"
	CTS_boot="$CTS_boot"
EOF
fi

cts_extra=""
if [ -n "$CTS_stonith" ]; then
    cts_extra="$cts_extra --stonith-type $CTS_stonith"
    [ -z "$CTS_stonith_args" ] \
        || cts_extra="$cts_extra --stonith-params \"$CTS_stonith_args\""
else
    cts_extra="$cts_extra --stonith 0"
    echo " - Testing a cluster without STONITH is like a blunt pencil... pointless"
fi

printf "\nAll set to go for %d iterations!\n" "$CTS_numtests"
[ $anyAsked -ne 0 ] \
    || echo "+ To use a different configuration, remove ~/.cts and re-run cts (or edit it manually)."

echo Now paste the following command into this shell:
echo "@PYTHON@ `dirname "$0"`/CTSlab.py -L \"$CTS_logfile\" --syslog-facility \"$CTS_logfacility\" --no-unsafe-tests --stack \"$CTS_stack\" $CTS_adv --at-boot \"$CTS_boot\" $cts_extra \"$CTS_numtests\" --nodes \"$CTS_node_list\""