summaryrefslogtreecommitdiffstats
path: root/tests/tier.rc
blob: da6b0ee4777dec9d1c8ea1c81a450d315faa2289 (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
#!/bin/bash

# Common tier functions

# Check if a file is being migrated
# by checking for the presence of
# the sticky bit
# Args: $1 : path to file

function is_sticky_set () {
        echo $1
        if [ -k $1 ];
        then
                echo "yes"
        else
                echo "no"
        fi
}


function exists_and_regular_file () {
        filepath=$1
        if [ -n "$filepath" ];
        then
                if [ -k "$filepath" ]
                then
                        echo "no"
                else
                        echo "yes"
                fi
        else
                echo "no"
        fi
}


function check_counters {
    index=0
    ret=0
    rm -f /tmp/tc*.txt
    echo "0" > /tmp/tc2.txt
    $CLI volume tier $V0 status | grep localhost > /tmp/tc.txt

    promote=`cat /tmp/tc.txt |awk '{print $2}'`
    demote=`cat /tmp/tc.txt |awk '{print $3}'`
    if [ "${promote}" != "${1}" ]; then
         echo "1" > /tmp/tc2.txt

    elif [ "${demote}" != "${2}" ]; then
         echo "2" > /tmp/tc2.txt
    fi

    # temporarily disable non-Linux tests.
    case $OSTYPE in
        NetBSD | FreeBSD | Darwin)
            echo "0" > /tmp/tc2.txt
            ;;
    esac
    cat /tmp/tc2.txt
}


function detach_start {
        $CLI volume tier $1 detach start
        echo $?;
}


# Grab md5sum without file path (failed attempt notifications are discarded)
function fingerprint {
    md5sum $1 2> /dev/null | grep --only-matching -m 1 '^[0-9a-f]*'
}



# Create a large number of files in the current directory.
# $1 : file name prefix. Will create files $2-1 to $2-$3
# $2 : number of files

function create_many_files {
    filename=$1
    num=$2

    for i in `seq 1 $num`; do
        dd if=/dev/urandom of=./${dirname}/${filename}$i bs=104857 count=1;
    done
}


function confirm_tier_removed {
    $CLI system getspec $V0 | grep $1
    if [ $? == 0 ]; then
        echo "1"
    else
        echo "0"
    fi
}

function confirm_vol_stopped {
    $CLI volume stop $1
    if [ $? == 0 ]; then
        echo "0"
    else
        echo "1"
    fi
}


function sleep_first_cycle {
    startTime=$(date +%s)
    mod=$(( ( $startTime % $1 ) + 1 ))
    sleep $mod
}

function sleep_until_mid_cycle {
    startTime=$(date +%s)
    mod=$(( ( $startTime % $1 ) + 1 ))
    mod=$(( $1 - $mod ))
    mod=$(( $mod + $1 / 2 ))
    sleep $mod
}

function tier_daemon_check () {
    pgrep -f "tierd/$V0"
    echo "$?"
}

function rebalance_run_time () {
    local time=$($CLI volume tier $1 status | awk '{print $6}' | sed -n 3p);
    local hh=$(echo $time | cut -d ':' -f1);
    local mm=$(echo $time | cut -d ':' -f2);
    local ss=$(echo $time | cut -d ':' -f3);
    local total=$(($hh * 3600 + $mm * 60 + $ss));
    echo $total;
}

function tier_detach_commit () {
	$CLI_1 volume tier $V0 detach commit | grep "success" | wc -l
}

function tier_detach_status_node_down () {
        $CLI_1 volume tier $V0 detach status | grep "WARNING" | wc -l
}

function tier_status_node_down () {
        $CLI_1 volume tier $V0 status | grep "WARNING" | wc -l
}

function tier_detach_status () {
        $CLI_1 volume tier $V0 detach status | grep "success" | wc -l
}

function wait_for_tier_start () {
        sleep 5
}