summaryrefslogtreecommitdiffstats
path: root/tests/basic/bd.t
blob: 7e3637492a3afc8d9a7fbc531be89a0f98a92bee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash

. $(dirname $0)/../include.rc
. $(dirname $0)/../volume.rc

function execute()
{
        cmd=$1
        shift
        ${cmd} $@ >/dev/null 2>&1
}

function bd_cleanup()
{
        execute vgremove -f ${V0}
        execute pvremove ${ld}
        execute losetup -d ${ld}
        execute rm ${BD_DISK}
        cleanup
}

function check()
{
        if [ $? -ne 0 ]; then
                echo prerequsite $@ failed
                bd_cleanup
                exit
        fi
}

SIZE=256 #in MB

bd_cleanup;

## Configure environment needed for BD backend volumes
## Create a file with configured size and
## set it as a temporary loop device to create
## physical volume & VG. These are basic things needed
## for testing BD xlator if anyone of these steps fail,
## test script exits
function configure()
{
    GLDIR=`$CLI system:: getwd`
    BD_DISK=${GLDIR}/bd_disk

    execute truncate -s${SIZE}M ${BD_DISK}
    check ${BD_DISK} creation

    execute losetup -f
    check losetup
    ld=`losetup -f`

    execute losetup ${ld} ${BD_DISK}
    check losetup ${BD_DISK}
    execute pvcreate -f ${ld}
    check pvcreate ${ld}
    execute vgcreate ${V0} ${ld}
    check vgcreate ${V0}
    execute lvcreate --thin ${V0}/pool --size 128M
}

function volinfo_field()
{
    local vol=$1;
    local field=$2;
    $CLI volume info $vol | grep "^$field: " | sed 's/.*: //';
}

function volume_type()
{
        getfattr -n volume.type $M0/. --only-values --absolute-names -e text
}

case $OSTYPE in
NetBSD)
        echo "Skip test on LVM which is not available on NetBSD" >&2
        exit 0
        ;;
*)      
        ;;
esac 

TEST glusterd
TEST pidof glusterd
configure

TEST $CLI volume create $V0 ${H0}:/$B0/$V0?${V0}
EXPECT "$V0" volinfo_field $V0 'Volume Name';
EXPECT 'Created' volinfo_field $V0 'Status';

## Start volume and verify
TEST $CLI volume start $V0;
EXPECT 'Started' volinfo_field $V0 'Status'

TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
EXPECT '1' volume_type

## Create posix file
TEST touch $M0/posix

TEST touch $M0/lv
gfid=`getfattr -n glusterfs.gfid.string $M0/lv --only-values --absolute-names`
TEST setfattr -n user.glusterfs.bd -v "lv:4MB" $M0/lv
# Check if LV is created
TEST stat /dev/$V0/${gfid}

## Create filesystem
sleep 1
TEST mkfs.ext4 -qF $M0/lv
# Cloning
TEST touch $M0/lv_clone
gfid=`getfattr -n glusterfs.gfid.string $M0/lv_clone --only-values --absolute-names`
TEST setfattr -n clone -v ${gfid} $M0/lv
TEST stat /dev/$V0/${gfid}

sleep 1
## Check mounting
TEST mount -o loop $M0/lv $M1
EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M1

# Snapshot
TEST touch $M0/lv_sn
gfid=`getfattr -n glusterfs.gfid.string $M0/lv_sn --only-values --absolute-names`
TEST setfattr -n snapshot -v ${gfid} $M0/lv
TEST stat /dev/$V0/${gfid}

# Merge
sleep 1
TEST setfattr -n merge -v "$M0/lv_sn" $M0/lv_sn
TEST ! stat $M0/lv_sn
TEST ! stat /dev/$V0/${gfid}


rm $M0/* -f

EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
TEST $CLI volume stop ${V0}
EXPECT 'Stopped' volinfo_field $V0 'Status';
TEST $CLI volume delete ${V0}

bd_cleanup