summaryrefslogtreecommitdiffstats
path: root/qa/workunits/fs/cephfs_mirror_helpers.sh
blob: 69f1c6f3d77e086674ac661ace0febc91c061955 (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
PRIMARY_FS='dc'
BACKUP_FS='dc-backup'

REPO=ceph-qa-suite
REPO_DIR=ceph_repo
REPO_PATH_PFX="$REPO_DIR/$REPO"

NR_DIRECTORIES=4
NR_SNAPSHOTS=4
MIRROR_SUBDIR='/mirror'

calc_checksum()
{
    local path=$1
    local -n ref=$2
    ref=`find -L $path -type f -exec md5sum {} +  | awk '{ print $1 }' | md5sum | awk '{ print $1 }'`
}

store_checksum()
{
    local path=$1
    local cksum='' #something invalid
    local fhash=`echo -n $path | md5sum | awk '{ print $1 }'`
    calc_checksum $path cksum
    echo -n $cksum > "/tmp/primary-$fhash"
}

compare_checksum()
{
    local ret=0
    local cksum=$1
    local path=$2
    local fhash=`echo -n $path | md5sum | awk '{ print $1 }'`
    local cksum_ondisk=`cat /tmp/primary-$fhash`
    if [ $cksum != $cksum_ondisk ]; then
        echo "$cksum <> $cksum_ondisk"
        ret=1
    fi
    echo $ret
}

exec_git_cmd()
{
    local arg=("$@")
    local repo_name=${arg[0]}
    local cmd=${arg[@]:1}
    git --git-dir "$repo_name/.git" $cmd
}

clone_repo()
{
    local repo_name=$1
    git clone --branch giant "http://github.com/ceph/$REPO" $repo_name
}

setup_repos()
{
    mkdir "$REPO_DIR"

    for i in `seq 1 $NR_DIRECTORIES`
    do
        local repo_name="${REPO_PATH_PFX}_$i"
        mkdir $repo_name
        clone_repo $repo_name
    done
}