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