From f77f8c7c603069071d7a609adce3ed9bc1131c37 Mon Sep 17 00:00:00 2001 From: nik-redhat Date: Tue, 26 May 2020 18:45:46 +0530 Subject: tests: added volume operations to increase code coverage Added test for volume options like localtime-logging, fixed enable-shared-storage to include function coverage and few negative tests for other volume options to increase the code coverage in the glusterd component. Change-Id: Ib1706c1fd5bc98a64dcb5c8b15a121d639a597d7 Updates: #1052 Signed-off-by: nik-redhat --- ...le-shared-storage-and-remove-brick-validation.t | 82 ---------------------- tests/bugs/glusterd/remove-brick-validation.t | 68 ++++++++++++++++++ tests/cluster.rc | 14 ++++ .../line-coverage/cli-peer-and-volume-operations.t | 40 +++++++++++ .../log-and-brick-ops-negative-case.t | 82 ++++++++++++++++++++++ tests/volume.rc | 8 +++ 6 files changed, 212 insertions(+), 82 deletions(-) delete mode 100644 tests/bugs/glusterd/enable-shared-storage-and-remove-brick-validation.t create mode 100644 tests/bugs/glusterd/remove-brick-validation.t create mode 100644 tests/line-coverage/log-and-brick-ops-negative-case.t diff --git a/tests/bugs/glusterd/enable-shared-storage-and-remove-brick-validation.t b/tests/bugs/glusterd/enable-shared-storage-and-remove-brick-validation.t deleted file mode 100644 index 11ed0d94d79..00000000000 --- a/tests/bugs/glusterd/enable-shared-storage-and-remove-brick-validation.t +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -. $(dirname $0)/../../include.rc -. $(dirname $0)/../../volume.rc -. $(dirname $0)/../../cluster.rc - -function peer_count { -eval \$CLI_$1 peer status | grep 'Peer in Cluster (Connected)' | wc -l -} - -cleanup; - -## start a 3 node virtual cluster -TEST launch_cluster 3; - -## peer probe server 2 from server 1 cli -TEST $CLI_1 peer probe $H2; - -EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count 1 - -#test case for bug 1266818 - disabling enable-shared-storage option -##should not delete user created volume with name glusterd_shared_storage - -## creating a volume with name glusterd_shared_storage -TEST $CLI_1 volume create glusterd_shared_storage $H1:$B1/${V0}0 $H2:$B2/${V0}1 -TEST $CLI_1 volume start glusterd_shared_storage - -## disabling enable-shared-storage should not succeed and should not delete the -## user created volume with name "glusterd_shared_storage" -TEST ! $CLI_1 volume all enable-shared-storage disable - -## volume with name should exist -TEST $CLI_1 volume info glusterd_shared_storage - -#testcase: bug-1245045-remove-brick-validation - -TEST $CLI_1 peer probe $H3; -EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 - -TEST $CLI_1 volume create $V0 $H1:$B1/$V0 $H2:$B2/$V0 -TEST $CLI_1 volume start $V0 - -kill_glusterd 2 - -#remove-brick should fail as the peer hosting the brick is down -TEST ! $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start - -TEST $glusterd_2 -EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" cluster_brick_up_status 1 $V0 $H2 $B2/${V0} - -EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 - -#volume status should work -TEST $CLI_2 volume status - -EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 3 -TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start -kill_glusterd 2 - -#remove-brick commit should fail as the peer hosting the brick is down -TEST ! $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} commit - -TEST $glusterd_2 -EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" cluster_brick_up_status 1 $V0 $H2 $B2/${V0} - -EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 - -#volume status should work -TEST $CLI_2 volume status - -TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} stop - -kill_glusterd 3 -EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count 1 - -TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start - -TEST start_glusterd 3 -EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 -TEST $CLI_3 volume status - -cleanup diff --git a/tests/bugs/glusterd/remove-brick-validation.t b/tests/bugs/glusterd/remove-brick-validation.t new file mode 100644 index 00000000000..a0ff4ff6a24 --- /dev/null +++ b/tests/bugs/glusterd/remove-brick-validation.t @@ -0,0 +1,68 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc +. $(dirname $0)/../../cluster.rc + +function peer_count { +eval \$CLI_$1 peer status | grep 'Peer in Cluster (Connected)' | wc -l +} + +cleanup; + +## start a 3 node virtual cluster +TEST launch_cluster 3; + +## peer probe server 2 from server 1 cli +TEST $CLI_1 peer probe $H2; + +EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count 1 + +#testcase: bug-1245045-remove-brick-validation + +TEST $CLI_1 peer probe $H3; +EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 + +TEST $CLI_1 volume create $V0 $H1:$B1/$V0 $H2:$B2/$V0 +TEST $CLI_1 volume start $V0 + +kill_glusterd 2 + +#remove-brick should fail as the peer hosting the brick is down +TEST ! $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start + +TEST $glusterd_2 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" cluster_brick_up_status 1 $V0 $H2 $B2/${V0} + +EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 + +#volume status should work +TEST $CLI_2 volume status + +EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 3 +TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start +kill_glusterd 2 + +#remove-brick commit should fail as the peer hosting the brick is down +TEST ! $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} commit + +TEST $glusterd_2 +EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" cluster_brick_up_status 1 $V0 $H2 $B2/${V0} + +EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 + +#volume status should work +TEST $CLI_2 volume status + +TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} stop + +kill_glusterd 3 +EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count 1 + +TEST $CLI_1 volume remove-brick $V0 $H2:$B2/${V0} start + +TEST start_glusterd 3 +EXPECT_WITHIN $PROBE_TIMEOUT 2 peer_count 1 +TEST $CLI_3 volume status + +cleanup diff --git a/tests/cluster.rc b/tests/cluster.rc index 96ca722f273..34f5b02398f 100644 --- a/tests/cluster.rc +++ b/tests/cluster.rc @@ -90,6 +90,20 @@ function kill_glusterd() { kill `cat $pidfile`; } +function restart_glusterd() { + local index=$1 + local b + local pidfile + local g + + b="B$index" + pidfile="${!b}/glusterd.pid" + + kill `cat $pidfile` + + g="glusterd_${index}" + ${!g} +} function kill_node() { local index=$1; diff --git a/tests/line-coverage/cli-peer-and-volume-operations.t b/tests/line-coverage/cli-peer-and-volume-operations.t index a1545048773..0cf8dbe81f9 100644 --- a/tests/line-coverage/cli-peer-and-volume-operations.t +++ b/tests/line-coverage/cli-peer-and-volume-operations.t @@ -77,6 +77,46 @@ TEST ! $CLI_1 volume status $V0 shd #test explicitly provided options TEST $CLI_1 --timeout=120 --log-level=INFO volume status +#changing timezone to a different one, to check localtime logging feature +TEST export TZ='Asia/Kolkata' +TEST restart_glusterd 1 + +#localtime logging enable +TEST $CLI_1 volume set all cluster.localtime-logging enable +EXPECT '1' logging_time_check $LOGDIR + +#localtime logging disable +TEST $CLI_1 volume set all cluster.localtime-logging disable +EXPECT '0' logging_time_check $LOGDIR + +#changing timezone back to original timezone +TEST export TZ='UTC' + +#negative tests for volume options +#'set' option to enable quota/inode-quota is now depreciated +TEST ! $CLI_1 volume set $V0 quota enable +TEST ! $CLI_1 volume set $V0 inode-quota enable + +#invalid transport type 'rcp' +TEST ! $CLI_1 volume set $V0 config.transport rcp + +#'op-version' option is not valid for a single volume +TEST ! $CLI_1 volume set $V0 cluster.op-version 72000 + +#'op-version' option can't be used with any other option +TEST ! $CLI_1 volume set all cluster.localtime-logging disable cluster.op-version 72000 + +#invalid format of 'op-version' +TEST ! $CLI_1 volume set all cluster.op-version 72-000 + +#provided 'op-version' value is greater than max allowed op-version +op_version=$($CLI_1 volume get all cluster.max-op-version | awk 'NR==3 {print$2}') +op_version=$((op_version+1000)) #this can be any number greater than 0 +TEST ! $CLI_1 volume set all cluster.op-version $op_version + +#provided 'op-verison' value cannot be less than the current cluster op-version value +TEST ! $CLI_1 volume set all cluster.op-version 00000 + # system commnds TEST $CLI_1 system help TEST $CLI_1 system uuid get diff --git a/tests/line-coverage/log-and-brick-ops-negative-case.t b/tests/line-coverage/log-and-brick-ops-negative-case.t new file mode 100644 index 00000000000..d86cb452282 --- /dev/null +++ b/tests/line-coverage/log-and-brick-ops-negative-case.t @@ -0,0 +1,82 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup +TEST glusterd +TEST pidof glusterd + +#create volumes +TEST $CLI volume create ${V0}_1 $H0:$B0/v{1..2} + +TEST $CLI volume create ${V0}_2 replica 3 arbiter 1 $H0:$B0/v{3..5} + +TEST $CLI volume create ${V0}_3 disperse 3 redundancy 1 $H0:$B0/v{6..8} +TEST $CLI volume start ${V0}_3 +EXPECT 'Started' volinfo_field ${V0}_3 'Status' + +TEST $CLI volume create ${V0}_4 replica 3 $H0:$B0/v{9..14} +TEST $CLI volume start ${V0}_4 +EXPECT 'Started' volinfo_field ${V0}_4 'Status' + +#log rotate option +#provided volume does not exist +TEST ! $CLI volume log ${V0}_5 rotate + +#volume must be started before using log rotate option +TEST ! $CLI volume log ${V0}_1 rotate +TEST $CLI volume start ${V0}_1 +EXPECT 'Started' volinfo_field ${V0}_1 'Status' + +#incorrect brick provided for the volume +TEST ! $CLI volume log ${V0}_1 rotate $H0:$B0/v15 + +#add-brick operations +#volume must be in started to state to increase replica count +TEST ! $CLI volume add-brick ${V0}_2 replica 4 $H0:$B0/v15 +TEST $CLI volume start ${V0}_2 +EXPECT 'Started' volinfo_field ${V0}_2 'Status' + +#incorrect number of bricks for a replica 4 volume +TEST ! $CLI volume add-brick ${V0}_1 replica 4 $H0:$B0/v15 + +#replica count provided is less than the current replica count +TEST ! $CLI volume add-brick ${V0}_2 replica 2 $H0:$B0/v15 + +#dispersed to replicated dispersed not possible +TEST ! $CLI volume add-brick ${V0}_3 replica 2 $H0:$B0/v15 + +#remove-brick operations +#replica count option provided for dispersed vol +TEST ! $CLI volume remove-brick ${V0}_3 replica 2 $H0:$B0/v8 start + +#given replica count is greater than the current replica count +TEST ! $CLI volume remove-brick ${V0}_2 replica 4 $H0:$B0/v5 start + +#number of bricks to be removed, must be a multiple of replica count +TEST ! $CLI volume remove-brick ${V0}_2 replica 3 $H0:$B0/v{3..4} start + +#less number of bricks given to reduce the replica count +TEST ! $CLI volume remove-brick ${V0}_2 replica 1 $H0:$B0/v3 start + +#bricks should be from different subvol +TEST ! $CLI volume remove-brick ${V0}_4 replica 2 $H0:$B0/v{13..14} start + +#arbiter must be removed to reduce replica count +TEST ! $CLI volume remove-brick ${V0}_2 replica 1 $H0:$B0/v{3..4} start + +#removal of bricks is not allowed without reducing the replica count explicitly +TEST ! $CLI volume remove-brick ${V0}_2 replica 3 $H0:$B0/v{3..5} start + +#incorrect brick for given vol +TEST ! $CLI volume remove-brick ${V0}_1 $H0:$B0/v15 start + +#removing all the bricks are not allowed +TEST ! $CLI volume remove-brick ${V0}_1 $H0:$B0/v{1..2} start + +#volume must not be stopped state while removing bricks +TEST $CLI volume stop ${V0}_1 +TEST ! $CLI volume remove-brick ${V0}_1 $H0:$B0/v1 start + +cleanup \ No newline at end of file diff --git a/tests/volume.rc b/tests/volume.rc index bc768c9434f..3924baeb7fc 100644 --- a/tests/volume.rc +++ b/tests/volume.rc @@ -992,3 +992,11 @@ function get-xml() { $CLI $1 --xml | xmllint --format - | grep $2 | sed 's/\(<"$2">\|<\/"$2">\)//g' } + +function logging_time_check() +{ + local logdir=$1 + local logfile=`echo ${0##*/}`_glusterd1.log + + cat $logdir/1/$logfile | tail -n 2 | head -n 1 | grep $(date +%H:%M) | wc -l +} \ No newline at end of file -- cgit