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