summaryrefslogtreecommitdiffstats
path: root/tests/snapshot.rc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/snapshot.rc')
-rw-r--r--[-rwxr-xr-x]tests/snapshot.rc208
1 files changed, 198 insertions, 10 deletions
diff --git a/tests/snapshot.rc b/tests/snapshot.rc
index 87ea0df9190..f6da514f826 100755..100644
--- a/tests/snapshot.rc
+++ b/tests/snapshot.rc
@@ -3,7 +3,22 @@
LVM_DEFINED=0
LVM_PREFIX="patchy_snap"
LVM_COUNT=0
-VHD_SIZE="1G"
+VHD_SIZE="300M"
+
+#This function will init B# bricks
+#This is used when launch_cluster is
+#not called to init B#. Call it before
+#setup_lvm
+function init_n_bricks() {
+ local count=$1
+ for i in `seq 1 $count`; do
+ eval "B$i=/d/backends/$i"
+ done
+}
+
+count_snaps () {
+ ls $1/.snaps | wc -l
+}
function init_lvm() {
if [ "$1" == "" ]; then
@@ -79,6 +94,11 @@ function cleanup_lvm() {
return 0
}
+# Find out how this file was sourced, source traps.rc the same way, and use
+# push_trapfunc to make sure cleanup_lvm gets called before we exit.
+. $(dirname ${BASH_SOURCE[0]})/traps.rc
+push_trapfunc cleanup_lvm
+
########################################################
# Private Functions
########################################################
@@ -112,7 +132,7 @@ function _cleanup_lvm() {
function _cleanup_lvm_again() {
local file
- mount | grep $LVM_PREFIX | awk '{print $3}' | xargs -r umount -f
+ mount | grep $LVM_PREFIX | awk '{print $3}' | xargs -r ${UMOUNT_F}
/sbin/vgs | grep $LVM_PREFIX | awk '{print $1}' | xargs -r vgremove -f
@@ -143,8 +163,8 @@ function _create_lv() {
local dir=$1
local num=$2
local vg="VG$num"
- local thinpoolsize="0.8G"
- local virtualsize="0.6G"
+ local thinpoolsize="200M"
+ local virtualsize="150M"
/sbin/pvcreate $dir/${LVM_PREFIX}_loop
/sbin/vgcreate ${!vg} $dir/${LVM_PREFIX}_loop
@@ -167,7 +187,7 @@ function _umount_lv() {
local num=$1
local l="L$num"
- umount -f ${!l} 2>/dev/null || true
+ ${UMOUNT_F} ${!l} 2>/dev/null || true
rmdir ${!l} 2>/dev/null || true
}
@@ -217,7 +237,7 @@ function create_n_snapshots() {
local snap_name=$3
local ret=0
for i in `seq 1 $snap_count`; do
- $CLI_1 snapshot create $snap_name$i ${vol}&
+ $CLI_1 snapshot create $snap_name$i ${vol} no-timestamp &
PID_1=$!
wait $PID_1
ret=$?
@@ -275,6 +295,50 @@ function snapshot_n_exists() {
return $ret
}
+#Check for the status of snapshot for a volume
+#Arg1 : <Snap Name>
+function snapshot_status()
+{
+ local snap=$1;
+ local cli=$CLI_1;
+ if [ "$cli" = "" ]; then
+ cli=$CLI
+ fi
+
+ #TODO: Right now just fetches the status of the single snap volume.
+ #When snapshot will have multiple snap volumes, should have a
+ #cummulative logic for status
+ $cli snapshot info $snap | grep "Status" | sed 's/.*: //';
+}
+
+
+#Check the different status of a particular snapshot
+#Arg1 : <Snap name>
+#Arg2 : <Filed in status>
+#Arg3 : <Expected value>
+function snapshot_snap_status()
+{
+
+ local snap=$1;
+ local cli=$CLI_1;
+ local field=$2;
+ local expected=$3;
+ if [ "$cli" = "" ]; then
+ cli=$CLI
+ fi
+ for i in $($cli snapshot status $snap | grep "$field" | \
+ cut -d ':' -f2 | awk '{print $1}') ;
+ do
+ if [ "$i" != "$expected" ]; then
+ echo "Failed"
+ return 1;
+ fi;
+ done;
+echo "Success"
+return 0;
+}
+
+
# TODO: Cleanup code duplication
function volinfo_field()
{
@@ -286,11 +350,135 @@ function volinfo_field()
function volume_exists() {
- local volname=$1
- $CLI_1 volume info $volname 2>&1 | grep -q 'does not exist'
+ $CLI_1 volume info $1 > /dev/null 2>&1
if [ $? -eq 0 ]; then
- return 1
+ echo "Y"
+ else
+ echo "N"
+ fi
+}
+
+# arg-1 : From which node the command should be trigerred
+# Ex : $CLI_1, $CLI_2, etc.
+# arg-2 : Volume name
+# arg-3 : Starting index for the snapname "snap$i"
+# arg-4 : Number of snapshots to be taken
+function snap_create()
+{
+ eval local cli_index=\$$1
+ local volname=$2
+ local i=$3
+ local limit=$[$i + $4]
+
+ while [ $i -lt $limit ]
+ do
+ $cli_index snapshot create snap$i $volname no-timestamp
+ i=$[$i+1]
+ done
+}
+
+# arg-1 : From which node the command should be trigerred
+# Ex : $CLI_1. $CLI_2, etc.
+# arg-2 : Volume name.
+function get_snap_count()
+{
+ eval local cli_index=\$$1
+ local volname=$2
+
+
+ if [ -z "$2" ]
+ then
+ $cli_index snapshot list | grep -v "No snapshots present"\
+ | wc -l
else
- return 0
+ $cli_index snapshot list $volname\
+ | grep -v "No snapshots present"\
+ | wc -l
+ fi
+}
+
+# arg-1 : From which node the command should be trigerred
+# Ex : $CLI_1, $CLI_2, etc.
+# arg-2 : Starting index for the snapname "snap$i"
+# arg-3 : Number of snapshots to be deleted.
+function snap_delete()
+{
+ eval local cli_index=\$$1
+ local i=$2
+ local limit=$[$i + $3]
+
+ while [ $i -lt $limit ]
+ do
+ $cli_index snapshot delete snap$i
+ i=$[$i+1]
+ done
+}
+
+# arg-1 : From which node the command should be triggered
+# Ex : $CLI_1, $CLI_2, etc.
+# arg-2 : key value
+function snap_config()
+{
+ eval local cli_index=\$$1
+ local var=$2
+ $cli_index snapshot config | grep "^$var" | sed 's/.*: //'
+}
+
+function check_if_snapd_exist() {
+ local pid
+ pid=$(ps aux | grep "snapd" | grep -v grep | awk '{print $2}')
+ if [ -n "$pid" ]; then echo "Y"; else echo "N"; fi
+}
+
+# returns number of snapshot being displayed in ".snaps" directory
+function uss_count_snap_displayed() {
+ local path=$1
+ ls $path/.snaps | wc -l
+}
+
+function snap_info_volume()
+{
+ eval local cli_index=\$$1
+ local var=$2
+ local vol=$3
+ $cli_index snapshot info volume $vol | grep "^$var" | sed 's/.*: //'
+}
+
+function snap_config_volume()
+{
+ eval local cli_index=\$$1
+ local var=$2
+ local vol=$3
+ $cli_index snapshot config $vol| grep "^$var" | sed 's/.*: //'
+}
+
+#return specific fields of xml output
+function get-cmd-field-xml()
+{
+ local cli=$CLI_1;
+ if [ "$cli" = "" ]; then
+ cli=$CLI
fi
+
+ COMMAND=$1
+ PATTERN=$2
+
+ $cli $COMMAND --xml | xmllint --format - | grep $PATTERN
}
+
+function get_snap_brick_status()
+{
+ local snap=$1;
+
+ $CLI snapshot status $snap | grep "Brick Running" | sed 's/.*: //';
+}
+
+case $OSTYPE in
+NetBSD)
+ echo "Skip test on LVM which is not available on NetBSD" >&2
+ SKIP_TESTS
+ exit 0
+ ;;
+*)
+ ;;
+esac