summaryrefslogtreecommitdiffstats
path: root/tests/geo-rep.rc
blob: c33ceaaa64e741de3688998abd654f85481838c3 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
GEO_REP_TIMEOUT=120

function check_status_num_rows()
{
    local search_key=$1
    $GEOREP_CLI $master $slave status | grep -F "$search_key" | wc -l
}

function check_keys_distributed()
{
    local search_key=$(cat /var/lib/glusterd/geo-replication/master_slave_common_secret.pem.pub)
    grep -F "$search_key" ~/.ssh/authorized_keys > /dev/null
    echo $?
}

function check_common_secret_file()
{
    stat /var/lib/glusterd/geo-replication/master_slave_common_secret.pem.pub
    echo $?
}

function create_data()
{
    prefix=$1

    # GF_FOP_MKNOD
    # GF_FOP_MKDIR
    # GF_FOP_UNLINK
    # GF_FOP_RMDIR
    # GF_FOP_SYMLINK
    # GF_FOP_RENAME
    # GF_FOP_LINK
    # GF_FOP_SETXATTR
    # GF_FOP_REMOVEXATTR
    # GF_FOP_CREATE
    # GF_FOP_SETATTR

    # Regular file + data
    echo "HelloWorld!" > ${master_mnt}/${prefix}_f1
    touch ${master_mnt}/${prefix}_f2
    touch ${master_mnt}/${prefix}_f3

    # dir
    mkdir ${master_mnt}/${prefix}_d1
    mkdir ${master_mnt}/${prefix}_d2
    mkdir ${master_mnt}/${prefix}_d3

    # Hardlink
    ln ${master_mnt}/${prefix}_f1 ${master_mnt}/${prefix}_hl1

    # Symlink
    cd ${master_mnt}
    ln -s ${prefix}_f1 ${prefix}_sl1
    cd -

    # UNLINK
    rm ${master_mnt}/${prefix}_f2

    # RMDIR
    rmdir ${master_mnt}/${prefix}_d2

    # Rename - File
    mv ${master_mnt}/${prefix}_f3 ${master_mnt}/${prefix}_f4

    # Rename - Dir
    mv ${master_mnt}/${prefix}_d3 ${master_mnt}/${prefix}_d4

    # chown
    touch ${master_mnt}/${prefix}_chown_f1
    chown 1000:1000 ${master_mnt}/${prefix}_chown_f1
}

function chown_file_ok()
{
    local file_owner=$(stat --format "%u:%g" "$1")
    if test "X$file_owner" != "X1000:1000"; then echo 1; else echo 0; fi
}

function regular_file_ok()
{
    local file_type=$(stat --format "%F" "$1")
    if test "X$file_type" != "Xregular file"; then echo 1; else echo 0; fi
}

function directory_ok()
{
    file_type=$(stat --format "%F" "$1")
    if test "X$file_type" != "Xdirectory"; then echo 1; else echo 0; fi
}

function unlink_ok()
{
    stat "$1" > /dev/null 2>&1
    rc=$?
    echo $rc
}

function hardlink_file_ok()
{
    orig_file=$1
    link_file=$2

    orig_inode=$(stat --format "%i" "$orig_file")
    rc=$?
    if test $rc != 0; then
        echo $rc
    else
        link_inode=$(stat --format "%i" "$link_file")
        rc=$?
        if test $rc != 0; then
            echo $rc
        else
            if test $orig_inode != $link_inode; then
                echo 1
            else
                echo 0
            fi
        fi
    fi
}

function data_ok()
{
    path=$1
    data1="$2"
    data2=$(cat $path)
    echo "data1:$data1"
    echo "data2:$data2"
    if test "X$data1" != "X$data2"; then
        echo 1
    else
        echo 0
    fi
}

function arequal_checksum()
{
    master=$1
    slave=$2
    diff <(arequal-checksum -p $master) <(arequal-checksum -p $slave) | wc -l
}

function symlink_ok()
{
    local orig_file_name=$1
    local symlink_file=$2

    local file_type=$(stat --format "%F" "$symlink_file")
    if test "X$file_type" != "Xsymbolic link"; then
        echo 1
    else
        local fname=$(readlink $symlink_file)
        if test "X$fname" != "X$orig_file_name"; then
            echo 1
        else
            echo 0
        fi
    fi

}

function rename_file_ok()
{
    old_name=$1
    new_name=$2

    if [ -f $old_name ]; then
        echo 1
    elif [ ! -f $new_name ]; then
        echo 1
    else
        echo 0
    fi
}

function rename_dir_ok()
{
    old_name=$1
    new_name=$2

    if [ -d $old_name ]; then
        echo 1
    elif [ ! -d $new_name ]; then
        echo 1
    else
        echo 0
    fi
}

function create_georep_session()
{
    $CLI system:: execute gsec_create
    rc=$?
    if test $rc != 0; then
        echo $rc
    else
        $CLI volume geo-rep $master $slave create push-pem
        rc=$?
        if test $rc != 0; then
            echo $rc
        else
            echo 0
        fi
    fi
}

# logrotate_simulate should be called (rotate_count + 1) times to cause
# an unlink and a gfid re-allocation.
# remember to keep the file name and rotate_count the same across the
# calls
function logrotate_simulate()
{
    file_name=$1
    declare -i rotate_count=$2

    while [ $rotate_count -ge 0 ]; do
        source_file="$file_name.$((rotate_count))"
        if [ $rotate_count -eq 0 ]; then
            source_file="$file_name"
        fi
        if [ -f "${source_file}" ]; then
                mv "${source_file}" "$file_name.$((rotate_count+1))"
        fi
        ((rotate_count--))
    done

    # logrotate causes gfid to be rellocated to a new file created
    # after an unlink and a blind rename later causes georep session
    # to go Faulty
    # this should not happen if source basename on slave is tested
    # to be linked with its own gfid as on master, before invoking
    # the rename syscall
    touch $file_name
    rotate_count=$2
    unlink_file_name="$file_name.$((rotate_count+1))"
    unlink $unlink_file_name 2>/dev/null
}

function create_rename()
{
    file_name=$1
    echo $file_name > $file_name
    mv $file_name $file_name.bak
}

function create_rename_ok()
{
    file_name=$1
    # after a log replay, we don't expect the original file
    # to be recreated i.e. a dangling entry without a corresponding
    # back-end gfid link should not exist on the slave
    if [ -f "$file_name" ]; then
        echo 1
    else
        echo 0
    fi
}

function hardlink_rename()
{
    file_name=$1
    echo $file_name > $file_name
    ln $file_name $file_name.hl
    mv $file_name.hl $file_name.hl1
}

function hardlink_rename_ok()
{
    file_name=$1
    # the hardlink file should not exist on the slave after renaming
    # to one of its links on changelog reprocessing
    if [ ! -f "$file_name" ]; then
        echo 1
    elif [ ! -f "$file_name.hl1" ]; then
        echo 1
    elif [ -f "$file_name.hl" ]; then
        echo 1
    else
        echo 0
    fi
}

function create_symlink_rename_mkdir_data()
{
    mkdir ${master_mnt}/symlink_test1
    touch ${master_mnt}/symlink_test1/file1
    ln -s "./file1" ${master_mnt}/symlink_test1/sym_link
    mv ${master_mnt}/symlink_test1/sym_link ${master_mnt}/symlink_test1/rn_sym_link
    mkdir ${master_mnt}/symlink_test1/sym_link
}
function verify_symlink_rename_mkdir_data()
{
    sym_dir=$1
    if [ ! -f $sym_dir/file1 ]; then
        echo 1
    elif [ ! -h $sym_dir/rn_sym_link ]; then
        echo 1
    elif [ ! -d $sym_dir/sym_link ]; then
        echo 1
    else
        echo 0
    fi
}

function create_rsnapshot_data()
{
    rm -rf /tmp/rsnapshot_symlinkbug
    mkdir /tmp/rsnapshot_symlinkbug
    ln -f -s /does/not/exist /tmp/rsnapshot_symlinkbug/a_symlink
    rsync -a /tmp/rsnapshot_symlinkbug ${master_mnt}/
    cp -al ${master_mnt}/rsnapshot_symlinkbug ${master_mnt}/rsnapshot_symlinkbug.0
    ln -f -s /does/not/exist2 /tmp/rsnapshot_symlinkbug/a_symlink
    rsync -a /tmp/rsnapshot_symlinkbug ${master_mnt}/
    cp -al ${master_mnt}/rsnapshot_symlinkbug ${master_mnt}/rsnapshot_symlinkbug.1
}

function verify_rsnapshot_data()
{
    dir="$1/rsnapshot_symlinkbug"
    dir0="$1/rsnapshot_symlinkbug.0"
    dir1="$1/rsnapshot_symlinkbug.1"
    if [ ! -d "$dir" ]; then
        echo 1
    elif [ ! -h $dir/a_symlink ]; then
        echo 1
    elif test "X$(readlink $dir/a_symlink)" != "X/does/not/exist2"; then
        echo 1
    elif [ ! -h $dir0/a_symlink ]; then
        echo 1
    elif test "X$(readlink $dir0/a_symlink)" != "X/does/not/exist"; then
        echo 1
    elif [ ! -h $dir1/a_symlink ]; then
        echo 1
    elif test "X$(readlink $dir1/a_symlink)" != "X/does/not/exist2"; then
        echo 1
    else
        echo 0
    fi
}

function create_hardlink_rename_data()
{
    dir=${master_mnt}/hardlink_rename_issue
    mkdir $dir
    echo "test_data" > $dir/f1
    ln $dir/f1 $dir/f2
    mv $dir/f2 $dir/f3
    unlink $dir/f1
}

function verify_hardlink_rename_data()
{
    dir=$1/hardlink_rename_issue
    if [ ! -d $dir ]; then
        echo 1
    elif [ -f $dir/f1 ]; then
        echo 1
    elif [ -f $dir/f2 ]; then
        echo 1
    elif [ ! -f $dir/f3 ]; then
        echo 1
    elif test "Xtest_data" != "X$(cat $dir/f3)"; then
        echo 1
    else
        echo 0
    fi
}