summaryrefslogtreecommitdiffstats
path: root/tests/geo-rep/geo-rep-helper.rc
blob: de8a6817305734167be8ddf6719f24d28e80412c (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#!/bin/bash

function geo_rep_checkpoint_status()
{
    echo "Verifying the sync status using geo-rep checkpoint" >> $LOG_FILE
    local timeout=300
    local temp_status="NOTOK"
    echo  "setting the checkpoint" >> $LOG_FILE

    $CLI volume geo-rep $GMV0 $H0::$GSV0 config checkpoint now >> $LOG_FILE 2>&1

# There is a bug, where in after checkpoint set, geo-rep status still
# shows the old data for the first execution of geo-rep status. Running
#geo-rep status to clear that.
    $CLI volume geo-replication  $GMV0 $H0::$GSV0 status >> $LOG_FILE 2>&1

    while [ $timeout -gt 0 ] && [ $temp_status == "NOTOK" ];
    do
	$CLI volume geo-replication $GMV0 $H0::$GSV0 status | \
	egrep -i "not reached yet" 2>&1 >/dev/null
	test $? -ne 0 && temp_status="completed"
	echo "Waiting for the files to sync ..." >> $LOG_FILE
	sleep 20
	timeout=`expr $timeout - 20`
	echo "temp_status is $temp_status" >> $LOG_FILE
	echo "geo-rep status output:" >> $LOG_FILE
	$CLI volume geo-replication $GMV0 $H0::$GSV0 status detail >> \
	    $LOG_FILE 2>&1

    done

    echo "resetting the geo-rep checkpoint" >> $LOG_FILE
    $CLI volume geo-rep $GMV0 $H0::$GSV0 config \!checkpoint  >> $LOG_FILE 2>&1

    if test $temp_status = "completed" ; then
	echo "geo-rep checkpoint has completed" >> $LOG_FILE
	return 0
    elif test $temp_status = "NOTOK" ; then
	echo "geo-rep checkpoint has failed to complete within 300 seconds" >> \
	    $LOG_FILE
	return 1
    fi
}



function geo_rep_arequal_status()
{

    echo "Verifying the sync status using arequal" >> $LOG_FILE
    local timeout=300
    local temp_status="NOTOK"
    local comp_arequal="$(dirname $0)/compare-arequal.py"

    while [ $timeout -gt 0 ] && [ $temp_status == "NOTOK" ];
    do
	echo "Waiting for the files to sync ..." >> $LOG_FILE
	sleep 20
	timeout=`expr $timeout - 20`

	echo  "calculating and comparing arequal checksum between $GMV0 and \
$GSV0 " >> $LOG_FILE
	python $comp_arequal $H0::$GMV0 $H0::$GSV0 >> $LOG_FILE 2>&1

	local ret=$?
	# There is a bug, where sometimes metadata checksum of directories
	# and regular files don't match. This is to avoid that for now.
	if [[ $ret -eq 0 || $ret -eq 67 || $ret -eq 68 ]] ;then
	    temp_status="completed"
	fi

    done

    if test $temp_status = "completed" ; then
	echo "checksum between master and slave match " >> $LOG_FILE
	return 0
    elif test $temp_status = "NOTOK" ; then
	echo "checksum between master and slave doesn't match" >> $LOG_FILE
	return 1
    fi
}


function geo_rep_filecount_status()
{

    echo "Verifying the sync status through files count" >> $LOG_FILE
    local timeout=300
    local temp_status="NOTOK"
    local comp_arequal="$(dirname $0)/compare-arequal.py"

    while [ $timeout -gt 0 ] && [ $temp_status == "NOTOK" ];
    do
	echo "Waiting for the files to sync ..." >> $LOG_FILE
	sleep 20
	timeout=`expr $timeout - 20`

	echo  "calculating and comparing files count  between $GMV0 and \
$GSV0 " >> $LOG_FILE
	python $comp_arequal -c "find" $H0::$GMV0 $H0::$GSV0 >> $LOG_FILE 2>&1

	if [ $? -eq 0 ];then
	    temp_status="completed"
	fi

    done

    if test $temp_status = "completed" ; then
	echo "files count  between master and slave match " >> $LOG_FILE
	return 0
    elif test $temp_status = "NOTOK" ; then
	echo "files count between master and slave doesn't match" >> $LOG_FILE
	return 1
    fi
}



function check_status_arequal()
{
# checkpoint is failing to reach even though all the files got synced in the latest build.
# Hence not using checkpoint to check for sync status.
#    geo_rep_checkpoint_status
    local comp_arequal="$(dirname $0)/compare-arequal.py"
    local comp_gfid="$(dirname $0)/compare-gfid.py"

    geo_rep_filecount_status

    geo_rep_arequal_status

    echo  "calculating and comparing gfids between $GMV0 and $GSV0 " \
	>> $LOG_FILE
    python  $comp_gfid $H0::$GMV0 $H0::$GSV0 >> $LOG_FILE 2>&1

    if [ $? != 0 ]; then
	return 1
    else
	echo "gfids between master and slave match" >> $LOG_FILE
    fi

    echo  "calculating and comparing arequal checksum between $GMV0 and $GSV0 " \
	>> $LOG_FILE
    python $comp_arequal $H0::$GMV0 $H0::$GSV0 >> $LOG_FILE 2>&1

    local rett=$?

    if [[ $rett -eq 0 || $rett -eq 67 || $rett -eq 68 ]] ;then
	reta=0
    else
	reta=1
    fi

    return $reta

}




function create_data()
{
    fop=$1
    MNT_PNT=$2
    create_data="$(dirname $0)/../utils/create-files.py"

    if [ $DIR_STR == "MULTI" ];then

	python $create_data -n $nf --multi -b 10 -d 10 --random --max=2K \
	    --min=1K -t $FILE_TYPE --fop=$fop $MNT_PNT >> $LOG_FILE 2>&1

    elif [ $DIR_STR == "SINGLE" ];then

	python $create_data -n $ns --random --max=2K --min=1K -t $FILE_TYPE \
	    --fop=$fop $MNT_PNT >> $LOG_FILE 2>&1

    else

	echo "Wrong option for the create-files" >> $LOG_FILE

    fi

}


function result()
{

local ret=$1
local test=$2
if [ $ret -ne 0 ]; then
    echo -e "\n[ FAIL ] : $test has failed" >> $LOG_FILE
    exit 1
else
    echo -e "\n[ PASS ] : $test has passed" >> $LOG_FILE
fi

}


## hybrid crawl test-cases

function hybrid_mode_test()
{
    local FOP=$1
    local MNT_PNT=$2
    echo -e "\n:::::::::::::::::::::::" >> $LOG_FILE
    echo "Start of hybrid-mode-$DIR_STR-$FILE_TYPE-$FOP-test with \
$MNT_PNT client" >> $LOG_FILE
    echo -e ":::::::::::::::::::::::\n" >> $LOG_FILE

    local ret=0
    echo "stopping geo-rep session before creating data" >> $LOG_FILE

    $CLI volume geo-rep $GMV0 $H0::$GSV0 stop force >> $LOG_FILE 2>&1

    if [ $? -ne 0 ]; then
	echo "stopping geo-rep session has failed" >> $LOG_FILE
	return 1
    fi

    create_data $FOP $MNT_PNT

    $CLI volume geo-rep $GMV0 $H0::$GSV0 start >> $LOG_FILE 2>&1

    if [ $? -ne 0 ]; then
	echo "starting geo-rep session has failed" >> $LOG_FILE
	return 1
    fi

    check_status_arequal

    if [ $? -ne 0 ]; then
	ret=1
    fi

    result $ret "hybrid-mode-$DIR_STR-$FILE_TYPE-$FOP-test with $CLIENT client"

    return $ret

}

#### Changelog based test-cases

function changelog_mode_test()
{
    local FOP=$1
    local MNT_PNT=$2
    echo -e "\n:::::::::::::::::::::::" >> $LOG_FILE
    echo "Start of changelog-mode-$DIR_STR-$FILE_TYPE-$FOP-test with \
$MNT_PNT client" >> $LOG_FILE
    echo -e ":::::::::::::::::::::::\n" >> $LOG_FILE

    local ret=0

    create_data $FOP $MNT_PNT

    check_status_arequal

    if [ $? -ne 0 ]; then
	ret=1
    fi

    result $ret "basic-changelog-$DIR_STR-$FILE_TYPE-$FOP-test with $CLIENT \
client"

    return $ret
}


function changelog_mode_remove_test()
{
    MNT_PNT=$1

    echo -e "\n:::::::::::::::::::::::" >> $LOG_FILE
    echo "Start of changelog-mode-$DIR_STR-$FILE_TYPE-remove-test with \
$MNT_PNT client" >> $LOG_FILE
    echo -e ":::::::::::::::::::::::\n" >> $LOG_FILE

    local ret=0

    if [ ! -z $MNT_PNT ]; then
	rm -rvf $MNT_PNT >> $LOG_FILE
    else
	echo "Value of MNT_PNT is NULL" >> $LOG_FILE
    fi

    check_status_arequal
    if [ $? -ne 0 ]; then
	ret=1
    fi

    result $ret "chnagelog-mode-$DIR_STR-$FILE_TYPE-remove-test with \
$MNT_PNT client"

    return $ret
}