summaryrefslogtreecommitdiffstats
path: root/sanity/pump_replace_brick/verify_pump.sh
blob: 446cb71034c01544733d541211d1f2c445cc3525 (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
#!/bin/bash

set -x

if [ $1="" ];then
        dir="/usr/local/sbin/glusterd"
else
        dir=$1
fi

GLUSTERFSDIR=`dirname $dir`


function graceful_cleanup ()
{

$GLUSTERFSDIR/gluster volume stop hosdu --mode=script
$GLUSTERFSDIR/gluster volume delete hosdu --mode=script
killall -9 glusterd
rm -rf /tmp/brick*
rm -f /tmp/tempfile
umount /tmp/mnt
rm -rf /tmp/mnt/

}

function cleanup ()
{

pgrep gluster | xargs kill -9
rm -rf /etc/glusterd/*
rm -rf /tmp/mnt/*
umount /tmp/mnt
rm -rf /tmp/brick*

}

function assert_success {
        if [ $1 = 0 ] ; then
                echo "test passed"
        else
                echo "test failed"
                #cleanup
                exit 1
        fi
}

function assert_are_equal {
AREQUAL='/home/arequal/arequal-checksum'
sudo rm -rf /tmp/brick{1,5}/.landfill
diff <($AREQUAL /tmp/brick1) <($AREQUAL /tmp/brick5)
assert_success $?
}

pgrep glusterd

if [ $? -ne 0 ];then
	$GLUSTERFSDIR/glusterd -LDEBUG
fi

$GLUSTERFSDIR/gluster volume create hosdu replica 2 $(hostname):/tmp/brick1/ $(hostname):/tmp/brick2/ $(hostname):/tmp/brick3/ $(hostname):/tmp/brick4/ 2>/dev/null 1>/dev/null;
$GLUSTERFSDIR/gluster volume set hosdu diagnostics.client-log-level DEBUG
$GLUSTERFSDIR/gluster volume set hosdu diagnostics.brick-log-level DEBUG
$GLUSTERFSDIR/gluster volume start hosdu 2>/dev/null 1>/dev/null;

mkdir /tmp/mnt/
mount -t glusterfs $(hostname):hosdu /tmp/mnt/
cpwd=`pwd`
cd /tmp/mnt/
for i in {1..40}
do
	for j in {1..10}
	do
		dd if=/dev/urandom of=file$j bs=128K count=10 2>/dev/null 1>/dev/null
	done
	mkdir dir$i && cd dir$i
done

cd $cpwd

umount /tmp/mnt/

ls -l /tmp/brick1
$GLUSTERFSDIR/gluster volume replace-brick hosdu $(hostname):/tmp/brick1/ $(hostname):/tmp/brick5/ start | grep "replace-brick started successfully" 2>/dev/null 1>/dev/null
if [ $? -ne 0 ];then
	echo "Failed to start the replace-brick"
	exit 1;
fi
sleep 5

temp=0;

while [ $temp -eq 0 ]
do

	$GLUSTERFSDIR/gluster volume replace-brick hosdu $(hostname):/tmp/brick1/ $(hostname):/tmp/brick5/ status >/tmp/tempfile # 2>/dev/null 1>/dev/null
	if [ $? -ne 0 ];then
		temp=2
	fi

	grep "Migration complete" /tmp/tempfile 2>/dev/null 1>/dev/null
	if [ $? -eq 0 ];then
                ls -l /tmp/brick5
                assert_are_equal
		temp=1;
	fi
done

if [ $temp -eq 1 ];then
	echo "replace-brick operation successfull. Commiting the replace-brick"
	$GLUSTERFSDIR/gluster volume replace-brick hosdu $(hostname):/tmp/brick1/ $(hostname):/tmp/brick5/ commit;
        graceful_cleanup ;
elif [ $temp -eq 2 ];then
	echo "Something went Bananas and glusterfsd probably crashed. Please look into it"
	cleanup ;
fi
rm -f /tmp/tempfile