#!/bin/bash

# Test IO NIC function

. ./common

trap "_uninit; exit \$status" 0 1 2 3 15

_uninit()
{
	iptables -D INPUT -p tcp --sport 8001 -j DROP
	iptables -D INPUT -p tcp --dport 8001 -j DROP
}

_need_to_be_root

for i in `seq 0 2`; do
	_start_sheep $i "-i host=127.0.0.1,port=$((8000+$i))"
done

_wait_for_sheep 3

_cluster_format

$DOG vdi create test 100M
dd if=/dev/zero | $DOG vdi write test &

# simulate IO NIC down of sheep 1
iptables -A INPUT -p tcp --sport 8001 -j DROP
iptables -A INPUT -p tcp --dport 8001 -j DROP

# wait for dog to finish
wait
# Logger flush in 1 second internval. We need assure log is flushed.
sleep 1

if [ "`grep fallback $STORE/0/sheep.log`" ];then
	echo fallback done
fi
$DOG vdi check test

status=0
