-
Notifications
You must be signed in to change notification settings - Fork 72
/
test_istgt.sh
executable file
·2135 lines (1831 loc) · 59.9 KB
/
test_istgt.sh
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
## Copyright © 2018 The OpenEBS Authors
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
DIR=$PWD
SETUP_ISTGT=$DIR/src/setup_istgt.sh
REPLICATION_TEST=$DIR/src/replication_test
TEST_SNAPSHOT=$DIR/test_snapshot.sh
MEMPOOL_TEST=$DIR/src/mempool_test
ISTGT_INTEGRATION=$DIR/src/istgt_integration
ISCSIADM=iscsiadm
ISTGTCONTROL=istgtcontrol
SETUP_PID=-1
device_name=""
LOGFILE="/tmp/istgt.log"
INTEGRATION_TEST_LOGFILE="/tmp/integration_test.log"
CONTROLLER_IP="127.0.0.1"
CONTROLLER_PORT="6060"
REPLICATION_FACTOR=3
CONSISTTENCY_FACTOR=2
IOPING="ioping"
CURDIR=$PWD
which $IOPING >> /dev/null
if [ $? -ne 0 ]; then
echo "$IOPING is not installed.. exiting.."
exit 1
fi
on_exit() {
cd $CURDIR
COREFILE=`find $CURDIR |grep core`
if [ ! -z $COREFILE ]; then
tail -1000 $LOGFILE
tail -500 $INTEGRATION_TEST_LOGFILE
gdb -ex "quit" -c $COREFILE
file=`strings $COREFILE |grep ^'_=' |grep "\/" |tail -1 |awk -F '=' '{print $2}'`
echo "Corefile generated by $file"
gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" $file $COREFILE
fi
tail -1000 $LOGFILE
tail -500 $INTEGRATION_TEST_LOGFILE
}
ulimit -c unlimited
trap 'on_exit' EXIT
source $SETUP_ISTGT
login_to_volume() {
$ISCSIADM -m discovery -t st -p $1
$ISCSIADM -m node -l
}
logout_of_volume() {
$ISCSIADM -m node -u
$ISCSIADM -m node -o delete
}
get_scsi_disk() {
local device_name=$($ISCSIADM -m session -P 3 |grep -i "Attached scsi disk" | awk '{print $4}')
i=0
while [ -z $device_name ]; do
sleep 5
device_name=$($ISCSIADM -m session -P 3 |grep -i "Attached scsi disk" | awk '{print $4}')
i=`expr $i + 1`
if [ $i -eq 10 ]; then
echo "scsi disk not found";
tail -20 $LOGFILE
exit;
else
continue;
fi
done
echo $device_name
}
start_istgt() {
cd $DIR/src
run_istgt $* >> $LOGFILE 2>&1 &
SETUP_PID=$!
echo $SETUP_PID
## wait for couple of seconds to start the istgt target
sleep 5
cd ..
}
start_replica() {
$REPLICATION_TEST $* >> $LOGFILE 2>&1
}
## wait_for_istgt_process verifies whether istgt is running or not
## $1 - retry count
wait_for_istgt_process() {
local retry_count=$1
##Wait for istgt to up
while [ $retry_count -gt 0 ]; do
value=$(netstat -nap | grep $CONTROLLER_PORT | grep -w LISTEN | wc -l)
if [ $value == "1" ]; then
break
fi
sleep 1
retry_count=$((retry_count - 1))
if [ $retry_count == 1 ]; then
exit 1
fi
done
}
stop_istgt() {
if [ $SETUP_PID -ne -1 ]; then
pkill -9 -P $(list_descendants $SETUP_PID)
kill -9 $(list_descendants $SETUP_PID)
pkill -9 -P $SETUP_PID
kill -9 $SETUP_PID
fi
}
run_mempool_test()
{
$MEMPOOL_TEST
[[ $? -ne 0 ]] && echo "mempool test failed" && tail -20 $LOGFILE && exit 1
return 0
}
run_istgt_integration()
{
local pid_istgt=$(sudo lsof -t -i:6060)
echo "istgt PID is $pid_istgt"
kill -9 $pid_istgt
pkill -9 -x istgt/src/replication_test
ps -aux | grep 'istgt'
truncate -s 5G /tmp/test_vol1 /tmp/test_vol2 /tmp/test_vol3
export externalIP=127.0.0.1
echo $externalIP
$ISTGT_INTEGRATION >> $INTEGRATION_TEST_LOGFILE 2>&1
[[ $? -ne 0 ]] && echo "istgt integration test failed" && tail -30 $INTEGRATION_TEST_LOGFILE && exit 1
rm -f /tmp/test_vol*
rm $INTEGRATION_TEST_LOGFILE
return 0
}
run_and_verify_iostats() {
login_to_volume "$CONTROLLER_IP:3260"
local device_name=$(get_scsi_disk)
if [ "$device_name"!="" ]; then
sudo mkfs.ext4 -F /dev/$device_name
[[ $? -ne 0 ]] && echo "mkfs failed for $device_name" && exit 1
sudo mount /dev/$device_name /mnt/store
[[ $? -ne 0 ]] && echo "mount for $device_name" && exit 1
sudo dd if=/dev/urandom of=/mnt/store/file1 bs=4k count=10000 oflag=direct
$ISTGTCONTROL iostats
var1="$($ISTGTCONTROL iostats | grep -oP "(?<=TotalWriteBytes\": \")[^ ]+" | cut -d '"' -f 1)"
if [ $var1 -eq 0 ]; then
echo "iostats command failed" && exit 1
fi
sudo dd if=/dev/urandom of=/mnt/store/file1 bs=4k count=10000 oflag=direct
$ISTGTCONTROL iostats
var2="$($ISTGTCONTROL iostats | grep -oP "(?<=TotalWriteBytes\": \")[^ ]+" | cut -d '"' -f 1)"
if [ $var2 -eq 0 ]; then
echo "iostats command failed" && exit 1
fi
if [ "$var2" == "$var1" ]; then
echo "iostats command failed, both the values are same" && exit 1
else
echo "iostats test passed"
fi
sudo umount /mnt/store
logout_of_volume
readReqTime="$($ISTGTCONTROL -q iostats | jq '.Replicas[0].ReadReqTime' | cut -d '"' -f 2)"
readRespTime="$($ISTGTCONTROL -q iostats | jq '.Replicas[0].ReadRespTime' | cut -d '"' -f 2)"
writeReqTime="$($ISTGTCONTROL -q iostats | jq '.Replicas[0].WriteReqTime' | cut -d '"' -f 2)"
writeRespTime="$($ISTGTCONTROL -q iostats | jq '.Replicas[0].WriteRespTime' | cut -d '"' -f 2)"
if [ $readReqTime -gt $readRespTime ] || [ $writeReqTime -gt $writeRespTime ]; then
echo "Issue in replica latency stats" && tail -20 $LOGFILE && exit 1
fi
sleep 5
else
echo "Unable to detect iSCSI device, login failed"; exit 1
fi
}
write_and_verify_data(){
login_to_volume "$CONTROLLER_IP:3260"
sleep 5
local device_name=$(get_scsi_disk)
if [ "$device_name"!="" ]; then
mkfs.ext4 -F /dev/$device_name
[[ $? -ne 0 ]] && echo "mkfs failed for $device_name" && tail -20 $LOGFILE && exit 1
mount /dev/$device_name /mnt/store
[[ $? -ne 0 ]] && echo "mount for $device_name" && tail -20 $LOGFILE && exit 1
dd if=/dev/urandom of=file1 bs=4k count=10000
hash1=$(md5sum file1 | awk '{print $1}')
cp file1 /mnt/store
hash2=$(md5sum /mnt/store/file1 | awk '{print $1}')
if [ $hash1 == $hash2 ]; then echo "DI Test: PASSED"
else
rm file1
echo "DI Test: FAILED";
tail -20 $LOGFILE
exit 1
fi
rm file1
umount /mnt/store
logout_of_volume
sleep 5
else
echo "Unable to detect iSCSI device, login failed";
tail -20 $LOGFILE
exit 1
fi
}
write_data()
{
local offset=$1
local len=$2
local base=$3
local output1=$4
local output2=$5
seek=$(( $offset / $base ))
count=$(( $len / $base ))
dd if=/dev/urandom | tr -dc 'a-zA-Z0-9'| head -c $len | \
tee >(dd of=$output1 conv=notrunc bs=$base count=$count seek=$seek oflag=direct) | \
(dd of=$output2 conv=notrunc bs=$base count=$count seek=$seek oflag=direct)
}
setup_test_env() {
rm -f /tmp/test_vol*
mkdir -p /mnt/store
## We are doing multiple resizes
truncate -s 10G /tmp/test_vol1 /tmp/test_vol2 /tmp/test_vol3 $1
logout_of_volume
sudo killall -9 istgt
sudo killall -9 replication_test
touch $INTEGRATION_TEST_LOGFILE
start_istgt
}
cleanup_test_env() {
stop_istgt
rm -rf /mnt/store
}
wait_for_pids()
{
for p in "$@"; do
wait $p
status=$?
if [ $status -ne 0 ] && [ $status -ne 127 ]; then
tail -20 $LOGFILE
exit 1
fi
done
}
list_descendants ()
{
local children=$(ps -o pid= --ppid "$1")
for pid in $children
do
list_descendants "$pid"
done
echo "$children"
}
run_data_integrity_test() {
local replica1_port="6161"
local replica2_port="6162"
local replica3_port="6163"
local replica1_id="6161"
local replica2_id="6162"
local replica3_id="6163"
local replica1_ip="127.0.0.1"
local replica2_ip="127.0.0.1"
local replica3_ip="127.0.0.1"
setup_test_env
$TEST_SNAPSHOT 0
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V "/tmp/test_vol1" -u "$replica1_id" -q &
replica1_pid=$!
$TEST_SNAPSHOT 0
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica2_ip" -P "$replica2_port" -V "/tmp/test_vol2" -u "$replica2_id" -q &
replica2_pid=$!
$TEST_SNAPSHOT 0
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$replica3_port" -V "/tmp/test_vol3" -u "$replica3_id" -q &
replica3_pid=$!
sleep 15
$TEST_SNAPSHOT 1 &
test_snapshot_pid=$!
write_and_verify_data
wait_for_pids $test_snapshot_pid
#$TEST_SNAPSHOT 1
pkill -9 -P $replica1_pid
kill -SIGKILL $replica1_pid
sleep 5
write_and_verify_data
#sleep is required for more than 60 seconds, as status messages are sent every 60 seconds
sleep 65
ps -auxwww
ps -o pid,ppid,command
#$TEST_SNAPSHOT 0
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V "/tmp/test_vol1" -u "$replica1_id" -q &
replica1_pid=$!
sleep 5
write_and_verify_data
#$TEST_SNAPSHOT 1
sleep 65
ps -auxwww
ps -o pid,ppid,command
#$TEST_SNAPSHOT 1
pkill -9 -P $replica1_pid
kill -SIGKILL $replica1_pid
# test replica IO timeout
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V "/tmp/test_vol1" -u "$replica1_id" -q -n 500&
replica1_pid1=$!
sleep 5
write_and_verify_data
sleep 5
write_and_verify_data
sleep 5
run_and_verify_iostats
wait $replica1_pid1
if [ $? == 0 ]; then
echo "Replica timeout failed"
exit 1
else
echo "Replica timeout passed"
fi
$ISTGTCONTROL -q iostats
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V "/tmp/test_vol1" -u "$replica1_id" -q &
replica1_pid=$!
sleep 5
ps aux |grep replication_test
pkill -9 -P $replica1_pid
pkill -9 -P $replica1_pid1
pkill -9 -P $replica2_pid
pkill -9 -P $replica3_pid
kill -SIGKILL $replica1_pid
kill -SIGKILL $replica1_pid1
kill -SIGKILL $replica2_pid
kill -SIGKILL $replica3_pid
cleanup_test_env
ps -auxwww
ps -o pid,ppid,command
}
run_read_consistency_test ()
{
local replica1_port="6161"
local replica2_port="6162"
local replica3_port="6163"
local replica1_id="6161"
local replica2_id="6162"
local replica3_id="6163"
local replica1_ip="127.0.0.1"
local replica2_ip="127.0.0.1"
local replica3_ip="127.0.0.1"
local replica1_vdev="/tmp/test_vol1"
local replica2_vdev="/tmp/test_vol2"
local replica3_vdev="/tmp/test_vol3"
local file_name="/root/data_file"
local device_file="/root/device_file"
local w_pid
local device_name=""
# Test to check if replication module is not initialized then
# istgtcontrol should return an error
export ReplicationDelay=40
setup_test_env
sleep 2
ps -aux | grep 'istgt'
istgtcontrol status >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ISTGTCONTROL returned error as replication module not initialized"
else
echo "ISTGTCONTROL returned success .. something went wrong"
stop_istgt
return
fi
unset ReplicationDelay
sleep 60
rm -rf $file_name $device_file
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q &
replica1_pid=$!
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica2_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" -q &
replica2_pid=$!
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" -q &
replica3_pid=$!
sleep 5
login_to_volume "$CONTROLLER_IP:3260"
sleep 5
device_name=$(get_scsi_disk)
if [ "$device_name" == "" ]; then
echo "error happened while running read consistency test"
pkill -9 -P $replica1_pid
pkill -9 -P $replica2_pid
pkill -9 -P $replica3_pid
return
fi
write_data 0 41943040 4096 "/dev/$device_name" $file_name
sync
$ISCSIADM -m session -P 3
write_data 0 10485760 4096 "/dev/$device_name" $file_name &
w_pid=$!
sleep 1
pkill -9 -P $replica1_pid
wait $w_pid
sync
$ISCSIADM -m session -P 3
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q -d &
replica1_pid=$!
sleep 5
write_data 13631488 10485760 4096 "/dev/$device_name" $file_name &
w_pid=$!
sleep 1
pkill -9 -P $replica2_pid
wait $w_pid
sync
$ISCSIADM -m session -P 3
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica2_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" -q -d &
replica2_pid=$!
sleep 5
write_data 31457280 10485760 4096 "/dev/$device_name" $file_name &
w_pid=$!
sleep 1
pkill -9 -P $replica3_pid
wait $w_pid
sync
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" -q -d &
replica3_pid=$!
sleep 5
dd if=/dev/$device_name of=$device_file bs=4096 iflag=direct oflag=direct count=10240
diff $device_file $file_name >> /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "read consistency test failed"
tail -50 $LOGFILE
exit 1
else
echo "read consistency test passed"
fi
logout_of_volume
pkill -9 -P $replica1_pid
pkill -9 -P $replica2_pid
pkill -9 -P $replica3_pid
rm -rf ${replica1_vdev}* ${replica2_vdev}* ${replica3_vdev}*
rm -rf $file_name $device_file
stop_istgt
}
run_lu_rf_test ()
{
local replica1_port="6161"
local replica2_port="6162"
local replica3_port="6163"
local replica1_id="6161"
local replica2_id="6162"
local replica3_id="6163"
local replica4_id="6164"
local replica1_ip="127.0.0.1"
local replica2_ip="127.0.0.1"
local replica3_ip="127.0.0.1"
local replica1_vdev="/tmp/test_vol1"
local replica2_vdev="/tmp/test_vol2"
local replica3_vdev="/tmp/test_vol3"
local replica4_ip="127.0.0.1"
local replica4_port="6164"
local replica4_vdev="/tmp/test_vol4"
>$LOGFILE
sed -i -n '/LogicalUnit section/,$!p' src/istgt.conf
setup_test_env $replica4_vdev
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica1_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q -r &
replica1_pid=$!
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica2_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" -q -r &
replica2_pid=$!
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" -q -r &
replica3_pid=$!
sleep 5
git checkout src/istgt.conf
echo "# LogicalUnit section
[LogicalUnit2]
TargetName vol1
TargetAlias nicknamefor-vol1
Mapping PortalGroup1 InitiatorGroup1
AuthMethod None
AuthGroup None
UseDigest Auto
ReadOnly No
ReplicationFactor 3
ConsistencyFactor 2
DesiredReplicationFactor 3
UnitType Disk
UnitOnline Yes
BlockLength 512
QueueDepth 32
Luworkers 6
UnitInquiry "CloudByte" "iscsi" "0" "4059aab98f093c5d95207f7af09d1413"
PhysRecordLength 4096
LUN0 Storage 5G 32k
LUN0 Option Unmap Disable
LUN0 Option WZero Disable
LUN0 Option ATS Disable
LUN0 Option XCOPY Disable" >> /usr/local/etc/istgt/istgt.conf
$ISTGTCONTROL refresh
sleep 5
grep "is ready for IOs now" $LOGFILE > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "lun refresh passed"
else
echo "lun refresh failed"
cat $LOGFILE
exit 1
fi
sleep 5
pkill -9 -P $replica3_pid
## Below will be allowed to connect as unkown replica but it will never become healthy
## since we are storing RF number replica details in memory
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$(($replica3_port + 10))" -V $replica3_vdev -u "$(($replica3_id + 10))" -q &
replica3_pid=$!
sleep 5
## Checking whether process exist or not
if ps -p $replica3_pid > /dev/null 2>&1
then
echo "Replica identification test failed"
cat $LOGFILE
exit 1
else
echo "Replica identification test passed"
fi
## Check whether old replica i.e(6163) allowed to connect or not
## since 6173 is new replica it will be addded as part of unknown
## quorum list since 6163 is in known list we should allow it to connect
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica3_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" -q &
old_replica3_pid=$!
sleep 3
## checking whether process exist or not
if ps -p $old_replica3_pid > /dev/null 2>&1
then
echo "Trusty Replica identification test passed"
else
echo "Trusty Replica identification test failed"
cat $LOGFILE
exit 1
fi
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica4_ip" -P "$replica4_port" -V $replica4_vdev -u "$replica4_id" &
replica4_pid=$!
sleep 5
if ps -p $replica4_pid > /dev/null 2>&1
then
echo "Unknown replica connection test failed(3 quorum + 1 non-quorum)"
cat $LOGFILE
exit 1
else
echo "Unknown replica connection test passed(3 quorum + 1 non-quorum)"
fi
pkill -9 -P $replica1_pid
pkill -9 -P $replica2_pid
pkill -9 -P $replica3_pid
rm -rf ${replica1_vdev}* ${replica2_vdev}* ${replica3_vdev}*
stop_istgt
}
## wait_for_healthy_replicas will wait for max of 5 minutes for replicas to become healthy
## and verifies the count of the helathy replicas with desired count.
wait_for_healthy_replicas()
{
no_of_replicas=$1
local i=0
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].Mode' | grep -w Healthy"
cnt=$(eval $cmd | wc -l)
## Wait untill all the replicas are converted to healthy.
## It takes atleast 30 seconds for each replica to become healthy
## checking for desired healthy replica count for 5 minutes with an interval of 3 seconds.
if [ $cnt -ne $no_of_replicas ]
then
for (( i = 0; i < 100; i++ )) do
sleep 3
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].Mode' | grep -w Healthy"
cnt=$(eval $cmd | wc -l)
if [ $cnt -eq $no_of_replicas ]
then
break
fi
done
fi
if [ $cnt -ne $no_of_replicas ]; then
echo "Health check is failed expected healthy replica count $no_of_replicas but got $cnt"
exit 1
fi
echo "Health state check is passed"
check_degraded_quorum 0 0
}
## check_degraded_quorum used to check the degraded replica count and quorum value count.
check_degraded_quorum()
{
local expected_degraded_count=$1
local expected_non_quorum_count=$2
local cnt=0
## Check the no.of degraded replicas
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].Mode'"
cnt=$(eval $cmd | grep -w Degraded | wc -l)
if [ $cnt -ne $expected_degraded_count ]
then
echo "Degraded replica count is not matched: expected degraded replica count $expected_rep_count and got $cnt"
exit 1
fi
## Check for quorum replicas. It takes approximately another 10 seconds to set quorum to 1 after rebuilding
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].quorum'"
cnt=$(eval $cmd | grep -w 0 | wc -l)
if [ $cnt -ne $expected_non_quorum_count ]
then
echo "Quorum test failed: expected quorum count is $expected_quorum_count and got $cnt"
exit 1
fi
echo "Test passed for checking the count of Degraded and Quorum count"
}
## is_replica_connected accepts zvol_guid as argument
## returns 0 in case of replica is connected to it else
## it return -1
is_replica_connected ()
{
local replica_id=$1
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].replicaId'"
cnt=$(eval $cmd | grep -w $replica_id | wc -l)
if [ $cnt == "1" ]; then
echo "0"
else
echo "-1"
fi
}
## get_connected_replica_count returns no.of replicas connected to
## the target by using istgtcontrol replica commmand
get_connected_replica_count ()
{
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].\"replicaStatus\"[].replicaId'"
cnt=$(eval "$cmd" | wc -l)
echo "$cnt"
}
run_login_multiple_times_test ()
{
local replica1_port="6161"
local replica1_id="6161"
local replica_ip="127.0.0.1"
local replica1_vdev="/tmp/test_vol1"
DESIRED_REPLICATION_FACTOR=1
REPLICATION_FACTOR=1
CONSISTENCY_FACTOR=1
KNOWN_REPLICA1_DETAILS=""
setup_test_env
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q &
replica2_pid=$!
sleep 3
login_to_volume "$CONTROLLER_IP:3260"
sleep 10
device_name=$(get_scsi_disk)
if [ -z "$device_name" ]; then
echo "After logging in Device name shouldn't be empty"
exit 1
fi
## Logging second time shouldn't cause any harmfull error
$ISCSIADM -m discovery -t st -p "$CONTROLLER_IP:3260"
$ISCSIADM -m node -l
rc=$?
if [ $rc -ne 15 ]; then
echo "Trying to logging in second time exit code should be 15 but got $rc"
exit 1
fi
pkill -9 -P $replica1_pid
rm -rf ${replica1_vdev::-1}*
stop_istgt
}
run_scaleup_scaledown_test ()
{
local replica1_port="6161"
local replica2_port="6162"
local replica3_port="6163"
local new_replica_port="7164"
local replica1_id="6161"
local replica2_id="6162"
local replica3_id="6163"
local replica_ip="127.0.0.1"
local replica1_vdev="/tmp/test_vol1"
local replica2_vdev="/tmp/test_vol2"
local replica3_vdev="/tmp/test_vol3"
DESIRED_REPLICATION_FACTOR=3
REPLICATION_FACTOR=1
CONSISTENCY_FACTOR=1
KNOWN_REPLICA1_DETAILS="Replica 6161 6161"
setup_test_env
## Replica2, Replica3 will be part of unknown replicas
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" &
replica2_pid=$!
sleep 3
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" &
replica3_pid=$!
sleep 3
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].status'"
rt=$(eval $cmd)
if [ ${rt} != "\"Offline\"" ]; then
$ISTGTCONTROL -q REPLICA vol1
echo "volume status is supposed to be Offline since there are no known replicas connected, but, $rt"
exit 1
fi
## Below replica is connecting as known replica
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q &
replica1_pid=$!
sleep 20 #Replica will take some time to make successful connection to target
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].status'"
rt=$(eval $cmd)
if [ ${rt} != "\"Healthy\"" ]; then
$ISTGTCONTROL -q REPLICA vol1
echo "volume status is supposed to be Healthy since it is single replica case, but, $rt"
exit 1
fi
## Wait for replcaed replica to become healthy
wait_for_healthy_replicas 3
## disconnect one replica and trigger scaledown
pkill -9 -P $replica1_pid
## remove replica1
istgtcontrol drf vol1 2 $replica2_id $replica3_id
rc=$?
if [ $rc != 0 ]; then
echo "Replica Scaledown should be succeed"
exit 1
fi
## wait for few seconds to disconnect the replica
sleep 3
## Performed scale down process(i.e decreased the drf from 3 to 2)
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q &
replica1_pid=$!
sleep 2
## If replica1 tries to connect target will reject and this entry
## should not available in istgtcontrol replica command
replica_status=$(is_replica_connected "$replica1_port")
if [ "$replica_status" == 0 ]; then
echo "Replica($replica1_port) should be disconnected from the target as part of scaledown"
exit -1
fi
## After scaledown current replica count should be 2
current_replica_count=$(get_connected_replica_count)
if [ "$current_replica_count" != "2"]; then
echo "connected replica count should be 2 but got $(current_replica_count)"
exit -1
fi
## Remove replica2
istgtcontrol drf vol1 1 $replica3_id
rc=$?
if [ $rc != 0 ]; then
echo "Replica Scaledown should be succeed"
exit 1
fi
## Wait for few seconds after disconnecting the replica
sleep 3
## pass zvol_guid as argument it should not exist in list
replica_status=$(is_replica_connected "$replica2_port")
if [ "$replica_status" == 0 ]; then
echo "Replica($replica2_port) should be disconnected from the target as part of scaledown"
exit -1
fi
cmd="$ISTGTCONTROL -q REPLICA vol1 | jq '.\"volumeStatus\"[0].status'"
rt=$(eval $cmd)
if [ ${rt} != "\"Healthy\"" ]; then
$ISTGTCONTROL -q REPLICA vol1
echo "volume status is supposed to be Healthy since it is single replica case after scale down, but, $rt"
exit 1
fi
## Remove known replica from conf file
sed -i "$ d" /usr/local/istgt/istgt.conf
pkill -9 -P $replica1_pid
pkill -9 -P $replica2_pid
pkill -9 -P $replica3_pid
rm -rf ${replica1_vdev::-1}*
stop_istgt
}
run_replica_connection_test ()
{
local replica1_port="6161"
local replica2_port="6162"
local replica3_port="6163"
local new_replica_port="7164"
local replica1_id="6161"
local replica2_id="6162"
local replica3_id="6163"
local replica_ip="127.0.0.1"
local replica1_vdev="/tmp/test_vol1"
local replica2_vdev="/tmp/test_vol2"
local replica3_vdev="/tmp/test_vol3"
local replica4_vdev="/tmp/test_vol4"
DESIRED_REPLICATION_FACTOR=1
REPLICATION_FACTOR=1
CONSISTENCY_FACTOR=1
setup_test_env $replica4_vdev
wait_for_istgt_process 3
# We didn't passed the replicaId so target should disconnect this replica
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica1_port" -V $replica1_vdev -q &
replica1_pid=$!
sleep 2
## checking whether process exist or not
if ps -p $replica1_pid > /dev/null 2>&1
then
echo "Target should disconnect the replica which doesn't have ReplicaID"
cat $LOGFILE
exit 1
else
echo "ReplicaID test passed(replica got disconnected by the target)"
fi
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica1_port" -V $replica1_vdev -u "$replica1_id" -q &
replica1_pid=$!
sleep 2 #Replica will take some time to make successful connection to target
## wait till replica become healthy(it will be healthy with in 10sec)
wait_for_healthy_replicas 1
## Following replica should be disconnected
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" &
replica2_pid=$!
sleep 3
## checking whether process exist or not(it shouldn't since DRF is 1)
if ps -p $replica2_pid > /dev/null 2>&1
then
echo "Target should disconnect the replica since DRF is $DESIRED_REPLICATION_FACTOR"
cat $LOGFILE
exit 1
else
echo "More than DRF Replica test passed(replica got disconnected by the target)"
fi
## Scaleup replica from 1 to 3
istgtcontrol drf vol1 3
rc=$?
if [ $rc != 0 ]; then
echo "Failed to update desired replication factor"
exit 1
fi
## Replica2, Replica3 will be part of unknown replicas
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica2_port" -V $replica2_vdev -u "$replica2_id" &
replica2_pid=$!
sleep 2
## Replica3 will be connected with ZVOL_GUID 6163 and REPLICA_ID will be 6163
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$replica3_port" -V $replica3_vdev -u "$replica3_id" &
replica3_pid=$!
sleep 2
## Scaling down replica shouldn't be allowed when scaleup is in progress
istgtcontrol drf vol1 2 $replica1_id $replica2_id
rc=$?
if [ $rc == 0 ]; then
echo "Replica Scaledown should be failed due to ongoing scaleup process"
exit 1
fi
# wait till unknown replicas become healthy and known replicas
wait_for_healthy_replicas 3
## kill Replica3 process
pkill -9 -P $replica3_pid
sleep 2
## Replica3 will be connected back with new ZVOL_GUID 7164 and Old REPLICA_ID i.e 6163
## This scenario is like replica replacement with new ZVOL_GUID
start_replica -i "$CONTROLLER_IP" -p "$CONTROLLER_PORT" -I "$replica_ip" -P "$new_replica_port" -V $replica3_vdev -u "$replica3_id" -q &
new_replica3_pid=$!
sleep 3
## checking whether process exist or not since it is replica replacement replica should exist
if ps -p $new_replica3_pid > /dev/null 2>&1
then
echo "Replaced replica connected to the target"
else
echo "Target should not disconnect the replica($new_replica_port) process ID: $replica3_pid which is part of replica replacement test"
cat $LOGFILE
exit 1