1# $NetBSD: t_basic.sh,v 1.1 2017/01/16 08:18:11 ozaki-r Exp $ 2# 3# Copyright (c) 2017 Internet Initiative Japan Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28SOCK_CLIENT=unix://carp_client 29SOCK_MASTER=unix://carp_master 30SOCK_BACKUP=unix://carp_backup 31BUS=bus_carp 32IP_CLIENT=10.1.1.240 33IP_MASTER=10.1.1.1 34IP_BACKUP=10.1.1.2 35IP_CARP=10.1.1.100 36TIMEOUT=3 37 38atf_test_case carp_handover cleanup 39 40carp_handover_head() 41{ 42 43 atf_set "descr" "Tests for CARP handover" 44 atf_set "require.progs" "rump_server" 45} 46 47setup_carp() 48{ 49 local sock=$1 50 local master=$2 51 local carpif= ip= advskew= 52 53 if $master; then 54 carpif=carp0 55 ip=$IP_MASTER 56 advskew=0 57 else 58 carpif=carp1 59 ip=$IP_BACKUP 60 advskew=200 61 fi 62 63 export RUMP_SERVER=$sock 64 atf_check -s exit:0 rump.ifconfig $carpif create 65 atf_check -s exit:0 rump.ifconfig shmif0 $ip/24 up 66 atf_check -s exit:0 rump.ifconfig $carpif \ 67 vhid 175 advskew $advskew advbase 1 pass s3cret \ 68 $IP_CARP netmask 255.255.255.0 69 atf_check -s exit:0 rump.ifconfig -w 10 70} 71 72wait_handover() 73{ 74 local i=0 75 76 export RUMP_SERVER=$SOCK_CLIENT 77 78 while [ $i -ne 5 ]; do 79 $DEBUG && echo "Trying ping $IP_CARP" 80 rump.ping -n -w 1 -c 1 $IP_CARP >/dev/null 81 if [ $? = 0 ]; then 82 $DEBUG && echo "Passed ping $IP_CARP" 83 break; 84 fi 85 $DEBUG && echo "Failed ping $IP_CARP" 86 i=$((i + 1)) 87 done 88 89 if [ $i -eq 5 ]; then 90 atf_fail "Failed to failover (5 sec)" 91 fi 92} 93 94carp_handover_body() 95{ 96 97 rump_server_start $SOCK_CLIENT 98 rump_server_start $SOCK_MASTER 99 rump_server_start $SOCK_BACKUP 100 101 rump_server_add_iface $SOCK_CLIENT shmif0 $BUS 102 rump_server_add_iface $SOCK_MASTER shmif0 $BUS 103 rump_server_add_iface $SOCK_BACKUP shmif0 $BUS 104 105 setup_carp $SOCK_MASTER true 106 setup_carp $SOCK_BACKUP false 107 108 export RUMP_SERVER=$SOCK_CLIENT 109 atf_check -s exit:0 rump.ifconfig shmif0 $IP_CLIENT/24 up 110 atf_check -s exit:0 rump.ifconfig -w 10 111 112 # Check that the primary addresses are up 113 atf_check -s exit:0 -o ignore \ 114 rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER 115 atf_check -s exit:0 -o ignore \ 116 rump.ping -n -w $TIMEOUT -c 1 $IP_BACKUP 117 118 # Give carp a while to croak 119 sleep 4 120 121 # Check state 122 export RUMP_SERVER=$SOCK_MASTER 123 $DEBUG && rump.ifconfig 124 atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \ 125 rump.ifconfig carp0 126 export RUMP_SERVER=$SOCK_BACKUP 127 $DEBUG && rump.ifconfig 128 atf_check -s exit:0 -o match:'carp: BACKUP carpdev shmif0' \ 129 rump.ifconfig carp1 130 export RUMP_SERVER=$SOCK_CLIENT 131 132 # Check that the shared IP works 133 atf_check -s exit:0 -o ignore \ 134 rump.ping -n -w $TIMEOUT -c 1 $IP_CARP 135 136 # KILLING SPREE 137 env RUMP_SERVER=$SOCK_MASTER rump.halt 138 sleep 1 139 140 # Check that primary is now dead 141 atf_check -s not-exit:0 -o ignore \ 142 rump.ping -n -w $TIMEOUT -c 1 $IP_MASTER 143 144 # Do it in installments. carp will cluck meanwhile 145 wait_handover 146 147 # Check state 148 export RUMP_SERVER=$SOCK_BACKUP 149 $DEBUG && rump.ifconfig 150 atf_check -s exit:0 -o match:'carp: MASTER carpdev shmif0' \ 151 rump.ifconfig carp1 152} 153 154carp_handover_cleanup() 155{ 156 157 $DEBUG && dump 158 cleanup 159} 160 161atf_init_test_cases() 162{ 163 164 atf_add_test_case carp_handover 165} 166