14f8ab
From c2decfb59bd1be7cd2b0d792fd2ca2627913638a Mon Sep 17 00:00:00 2001
14f8ab
From: Sunny Kumar <sunkumar@redhat.com>
14f8ab
Date: Tue, 24 Sep 2019 18:22:13 +0530
14f8ab
Subject: [PATCH 310/313] tests : test case for non-root geo-rep setup
14f8ab
14f8ab
Added test case for non-root geo-rep setup.
14f8ab
14f8ab
Backport of:
14f8ab
 > Patch: https://review.gluster.org/22902
14f8ab
 > Change-Id: Ib6ebee79949a9f61bdc5c7b5e11b51b262750e98
14f8ab
 > fixes: bz#1717827
14f8ab
 > Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
14f8ab
14f8ab
Change-Id: Ib6ebee79949a9f61bdc5c7b5e11b51b262750e98
14f8ab
BUG: 1763412
14f8ab
Signed-off-by: Kotresh HR <khiremat@redhat.com>
14f8ab
Reviewed-on: https://code.engineering.redhat.com/gerrit/183664
14f8ab
Tested-by: RHGS Build Bot <nigelb@redhat.com>
14f8ab
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
14f8ab
---
14f8ab
 tests/00-geo-rep/00-georep-verify-non-root-setup.t | 251 +++++++++++++++++++++
14f8ab
 1 file changed, 251 insertions(+)
14f8ab
 create mode 100644 tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
14f8ab
diff --git a/tests/00-geo-rep/00-georep-verify-non-root-setup.t b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
new file mode 100644
14f8ab
index 0000000..e753c1f
14f8ab
--- /dev/null
14f8ab
+++ b/tests/00-geo-rep/00-georep-verify-non-root-setup.t
14f8ab
@@ -0,0 +1,251 @@
14f8ab
+#!/bin/bash
14f8ab
+
14f8ab
+. $(dirname $0)/../include.rc
14f8ab
+. $(dirname $0)/../volume.rc
14f8ab
+. $(dirname $0)/../geo-rep.rc
14f8ab
+. $(dirname $0)/../env.rc
14f8ab
+
14f8ab
+SCRIPT_TIMEOUT=500
14f8ab
+
14f8ab
+### Basic Non-root geo-rep setup test with Distribute Replicate volumes
14f8ab
+
14f8ab
+##Cleanup and start glusterd
14f8ab
+cleanup;
14f8ab
+TEST glusterd;
14f8ab
+TEST pidof glusterd
14f8ab
+
14f8ab
+
14f8ab
+##Variables
14f8ab
+GEOREP_CLI="$CLI volume geo-replication"
14f8ab
+master=$GMV0
14f8ab
+SH0="127.0.0.1"
14f8ab
+slave=${SH0}::${GSV0}
14f8ab
+num_active=2
14f8ab
+num_passive=2
14f8ab
+master_mnt=$M0
14f8ab
+slave_mnt=$M1
14f8ab
+
14f8ab
+##User and group to be used for non-root geo-rep setup
14f8ab
+usr="nroot"
14f8ab
+grp="ggroup"
14f8ab
+
14f8ab
+slave_url=$usr@$slave
14f8ab
+slave_vol=$GSV0
14f8ab
+ssh_url=$usr@$SH0
14f8ab
+
14f8ab
+############################################################
14f8ab
+#SETUP VOLUMES AND VARIABLES
14f8ab
+
14f8ab
+##create_and_start_master_volume
14f8ab
+TEST $CLI volume create $GMV0 replica 2 $H0:$B0/${GMV0}{1,2,3,4};
14f8ab
+TEST $CLI volume start $GMV0
14f8ab
+
14f8ab
+##create_and_start_slave_volume
14f8ab
+TEST $CLI volume create $GSV0 replica 2 $H0:$B0/${GSV0}{1,2,3,4};
14f8ab
+TEST $CLI volume start $GSV0
14f8ab
+
14f8ab
+##Mount master
14f8ab
+#TEST glusterfs -s $H0 --volfile-id $GMV0 $M0
14f8ab
+
14f8ab
+##Mount slave
14f8ab
+#TEST glusterfs -s $H0 --volfile-id $GSV0 $M1
14f8ab
+
14f8ab
+
14f8ab
+##########################################################
14f8ab
+#TEST FUNCTIONS
14f8ab
+
14f8ab
+function distribute_key_non_root()
14f8ab
+{
14f8ab
+    ${GLUSTER_LIBEXECDIR}/set_geo_rep_pem_keys.sh $usr $master $slave_vol
14f8ab
+    echo $?
14f8ab
+}
14f8ab
+
14f8ab
+
14f8ab
+function check_status_non_root()
14f8ab
+{
14f8ab
+    local search_key=$1
14f8ab
+    $GEOREP_CLI $master $slave_url status | grep -F "$search_key" | wc -l
14f8ab
+}
14f8ab
+
14f8ab
+
14f8ab
+function check_and_clean_group()
14f8ab
+{
14f8ab
+        if [ $(getent group $grp) ]
14f8ab
+        then
14f8ab
+                groupdel $grp;
14f8ab
+                echo $?
14f8ab
+        else
14f8ab
+                echo 0
14f8ab
+        fi
14f8ab
+}
14f8ab
+
14f8ab
+function clean_lock_files()
14f8ab
+{
14f8ab
+        if [ ! -f /etc/passwd.lock ];
14f8ab
+        then
14f8ab
+                rm -rf /etc/passwd.lock;
14f8ab
+        fi
14f8ab
+
14f8ab
+        if [ ! -f /etc/group.lock ];
14f8ab
+        then
14f8ab
+                rm -rf /etc/group.lock;
14f8ab
+        fi
14f8ab
+
14f8ab
+        if [ ! -f /etc/shadow.lock ];
14f8ab
+        then
14f8ab
+                rm -rf /etc/shadow.lock;
14f8ab
+        fi
14f8ab
+
14f8ab
+        if [ ! -f /etc/gshadow.lock ];
14f8ab
+        then
14f8ab
+                rm -rf /etc/gshadow.lock;
14f8ab
+        fi
14f8ab
+}
14f8ab
+
14f8ab
+
14f8ab
+###########################################################
14f8ab
+#SETUP NON-ROOT GEO REPLICATION
14f8ab
+
14f8ab
+##Create ggroup group
14f8ab
+##First test if group exists and then create new one
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 check_and_clean_group
14f8ab
+
14f8ab
+##cleanup *.lock files
14f8ab
+
14f8ab
+clean_lock_files
14f8ab
+
14f8ab
+TEST /usr/sbin/groupadd $grp
14f8ab
+
14f8ab
+clean_lock_files
14f8ab
+##Create non-root user and assign it to newly created group
14f8ab
+
14f8ab
+TEST /usr/sbin/useradd -G $grp $usr
14f8ab
+
14f8ab
+##Modify password for non-root user to have control over distributing ssh-key
14f8ab
+echo "$usr:pass" | chpasswd
14f8ab
+
14f8ab
+##Set up mountbroker root
14f8ab
+TEST gluster-mountbroker setup /var/mountbroker-root $grp
14f8ab
+
14f8ab
+##Associate volume and non-root user to the mountbroker
14f8ab
+TEST gluster-mountbroker add $slave_vol $usr
14f8ab
+
14f8ab
+##Check ssh setting for clear text passwords
14f8ab
+sed '/^PasswordAuthentication /{s/no/yes/}' -i /etc/ssh/sshd_config && grep '^PasswordAuthentication ' /etc/ssh/sshd_config && service sshd restart
14f8ab
+
14f8ab
+
14f8ab
+##Restart glusterd to reflect mountbroker changages
14f8ab
+TEST killall_gluster;
14f8ab
+TEST glusterd;
14f8ab
+TEST pidof glusterd;
14f8ab
+
14f8ab
+
14f8ab
+
14f8ab
+##Create, start and mount meta_volume
14f8ab
+TEST $CLI volume create $META_VOL replica 3 $H0:$B0/${META_VOL}{1,2,3};
14f8ab
+TEST $CLI volume start $META_VOL
14f8ab
+TEST mkdir -p $META_MNT
14f8ab
+TEST glusterfs -s $H0 --volfile-id $META_VOL $META_MNT
14f8ab
+
14f8ab
+##Mount master
14f8ab
+TEST glusterfs -s $H0 --volfile-id $GMV0 $M0
14f8ab
+
14f8ab
+##Mount slave
14f8ab
+TEST glusterfs -s $H0 --volfile-id $GSV0 $M1
14f8ab
+
14f8ab
+## Check status of mount-broker
14f8ab
+TEST gluster-mountbroker status
14f8ab
+
14f8ab
+
14f8ab
+##Setup password-less ssh for non-root user
14f8ab
+#sshpass -p "pass" ssh-copy-id -i ~/.ssh/id_rsa.pub $ssh_url
14f8ab
+##Run ssh agent
14f8ab
+eval "$(ssh-agent -s)"
14f8ab
+PASS="pass"
14f8ab
+
14f8ab
+
14f8ab
+##Create a temp script to echo the SSH password, used by SSH_ASKPASS
14f8ab
+
14f8ab
+SSH_ASKPASS_SCRIPT=/tmp/ssh-askpass-script
14f8ab
+cat > ${SSH_ASKPASS_SCRIPT} <
14f8ab
+#!/bin/bash
14f8ab
+echo "${PASS}"
14f8ab
+EOL
14f8ab
+chmod u+x ${SSH_ASKPASS_SCRIPT}
14f8ab
+
14f8ab
+##set no display, necessary for ssh to use with setsid and SSH_ASKPASS
14f8ab
+#export DISPLAY=:0
14f8ab
+
14f8ab
+export SSH_ASKPASS=${SSH_ASKPASS_SCRIPT}
14f8ab
+
14f8ab
+DISPLAY=: setsid ssh-copy-id -i ~/.ssh/id_rsa.pub $ssh_url
14f8ab
+
14f8ab
+##Setting up PATH for gluster binaries in case of source installation
14f8ab
+##ssh -oNumberOfPasswordPrompts=0 -oStrictHostKeyChecking=no $ssh_url "echo "export PATH=$PATH:/usr/local/sbin" >> ~/.bashrc"
14f8ab
+
14f8ab
+##Creating secret pem pub file
14f8ab
+TEST gluster-georep-sshkey generate
14f8ab
+
14f8ab
+##Create geo-rep non-root setup
14f8ab
+
14f8ab
+TEST $GEOREP_CLI $master $slave_url create push-pem
14f8ab
+
14f8ab
+#Config gluster-command-dir
14f8ab
+TEST $GEOREP_CLI $master $slave_url config gluster-command-dir ${GLUSTER_CMD_DIR}
14f8ab
+
14f8ab
+#Config gluster-command-dir
14f8ab
+TEST $GEOREP_CLI $master $slave_url config slave-gluster-command-dir ${GLUSTER_CMD_DIR}
14f8ab
+
14f8ab
+## Test for key distribution
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT  0 distribute_key_non_root
14f8ab
+
14f8ab
+##Wait for common secret pem file to be created
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT  0 check_common_secret_file
14f8ab
+
14f8ab
+#Enable_metavolume
14f8ab
+TEST $GEOREP_CLI $master $slave config use_meta_volume true
14f8ab
+
14f8ab
+#Start_georep
14f8ab
+TEST $GEOREP_CLI $master $slave_url start
14f8ab
+
14f8ab
+## Meta volume is enabled so looking for 2 Active and 2 Passive sessions
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT  2 check_status_non_root "Active"
14f8ab
+
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT  2 check_status_non_root "Passive"
14f8ab
+
14f8ab
+#Pause geo-replication session
14f8ab
+TEST $GEOREP_CLI  $master $slave_url pause
14f8ab
+
14f8ab
+#Resume geo-replication session
14f8ab
+TEST $GEOREP_CLI  $master $slave_url resume
14f8ab
+
14f8ab
+#Validate failure of volume stop when geo-rep is running
14f8ab
+TEST ! $CLI volume stop $GMV0
14f8ab
+
14f8ab
+#Stop Geo-rep
14f8ab
+TEST $GEOREP_CLI $master $slave_url stop
14f8ab
+
14f8ab
+#Delete Geo-rep
14f8ab
+TEST $GEOREP_CLI $master $slave_url delete
14f8ab
+
14f8ab
+#Cleanup authorized_keys
14f8ab
+sed -i '/^command=.*SSH_ORIGINAL_COMMAND#.*/d' ~/.ssh/authorized_keys
14f8ab
+sed -i '/^command=.*gsyncd.*/d' ~/.ssh/authorized_keys
14f8ab
+
14f8ab
+#clear mountbroker
14f8ab
+gluster-mountbroker remove --user $usr
14f8ab
+gluster-mountbroker remove --volume $slave_vol
14f8ab
+
14f8ab
+#delete group and user created for non-root setup
14f8ab
+TEST userdel -r -f $usr
14f8ab
+EXPECT_WITHIN $GEO_REP_TIMEOUT 0 check_and_clean_group
14f8ab
+
14f8ab
+##password script cleanup
14f8ab
+rm -rf /tmp/ssh-askpass-script
14f8ab
+
14f8ab
+
14f8ab
+cleanup;
14f8ab
+
14f8ab
-- 
14f8ab
1.8.3.1
14f8ab