summaryrefslogtreecommitdiffstats
path: root/tests/include/ec.sh
blob: 12f7fe22f426682d1fc14a2ee20e52f423e70218 (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
#!/bin/bash

# Copyright (c) 2016 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: Lin Li   <lilin@redhat.com>

path=$(pwd)
source ../include/utils.sh || exit 1
source ../include/include.sh || exit 1
source ../include/tc.sh || exit 1
source ../include/mpath.sh || exit 1 
source ../include/scsi_debug.sh || exit 1 

#this script usually is only used by current case
#private global variables, lower case and no under line is okay 
mpath=

function _isconfig (){
    [ -z $mpath ] && return 2
    Cmd "multipath -ll $mpath"
}

function _init (){
#will improve this function
#should return the multipathed disk created by scsi_debug, don't consider the other mutipathed disks
#olnly append the black list exception to /etc/multipath.conf not override
    Setup_Multipath || Fail "failed to create multipathed device via scsi_debug" 
    mpath=$RETURN_STR

    _isconfig
}

function _destroy (){
    sleep 10
    Cmd "multipath -F"
    sleep 5
    Cmd "modprobe -r scsi_debug"
}

# ---------------------------------------------------------#
# Print_kernel_info()
# Usage:
# print the detail running kernel information. 
# Parameter: #   NULL
# Returns:
#   Return code:
#       0 on success
#       1 if something went wrong.
# ---------------------------------------------------------#
function Print_kernel_info (){
    Cmd "lsb_release -a"
    Cmd "uname -a"
}



# ---------------------------------------------------------#
# Setup_Multipath ()
# Usage:
#   return mpath_name if we have multipath devices, if not,
#   we use scsi_debug to create a multipath device.
# Parameter:
#   NULL
# Returns:
#   Return code:
#       0 on success
#       1 if something went wrong.
#   Return string:
#       RETURN_STR  # $mpath_name_list, like "mpath0 mpath1"
# ---------------------------------------------------------#

function Setup_Multipath (){
    RETURN_STR=''
    local mpath_name_list=$(dmsetup table \
        | perl -ne 'print "$1 " if /(mpath[a-z0-9]+):[0-9 ]+multipath.*/')
    if [ "CHK${mpath_name_list}" != "CHK" ];then
        mpath_name_list="$(echo ${mpath_name_list} | sed -e 's/ $//')"
        echo "INFO: Found multipath devices: ${mpath_name_list}"
#RHEL 5 will disable some wwn mpath if we install OS with ondisk=mapper/mpath0
# option, so we need to enable them all
        if [ "CHK$(uname -r | egrep "2\.6\.18.*el5")" != "CHK" ];then
            cat << AA > /etc/multipath.conf
defaults {
    user_friendly_names     yes
}
blacklist {
    device {
        vendor .*
        product .*
    }
}
blacklist_exceptions {
    device {
        vendor Linux
        product scsi_debug
    }
    device {
        vendor IQSTOR
        product .*
    }
    device {
        vendor NETAPP
        product .*
    }
    device {
        vendor HITACHI
        product .*
    }
}
AA
        service multipathd start
        sleep 5s #multipathd return premature
        multipath -r
        multipathd -k'reconfigure'
        mpath_name_list=$(dmsetup table \
            | perl -ne 'print "$1 " if /(mpath[a-z0-9]+):[0-9 ]+multipath.*/')
        fi
        if [ "CHK${mpath_name_list}" == "CHK" ];then
            echo -n "FATAL: still no mulipath devices setup,"
            echo " check code in Setup_Multipath()"
            RETURN_STR=''
            return 1
        fi
        RETURN_STR="${mpath_name_list}"
        return 0
    fi
#setup scsi_debug
    echo "INFO: Loading scsi_debug module for simulation of mpath"
    local dev_size=100
    if [ "CHK$(uname -m)" == "CHKi386" ] \
        || [ "CHK$(uname -m)" == "CHKi686" ]; then
#i386 platform cannot allocate 100 MiB in kernel space
        dev_size=10
    fi
    modprobe scsi_debug dev_size_mb=${dev_size} \
        num_tgts=1 vpd_use_hostno=0 \
        add_host=4 delay=20 \
        max_luns=2 no_lun_0=1 2>&1 1>/dev/null

    echo "INFO: Waiting for udev to create /dev/sdX"
    sleep 15s #wait for udev to create /dev/sdX
    rpm -q device-mapper-multipath 2>/dev/null 1>/dev/null
    if [ $? -ne 0 ];then
        echo "INFO: Installing device-mapper-multipath via yum"
        yum -y install device-mapper-multipath
    fi
#enable multipath for scsi_debug.
    cat << AA > /etc/multipath.conf
defaults {
#Enable multibus is for mutlbus testing
    path_grouping_policy multibus
    user_friendly_names     yes
}
blacklist {
        device {
                vendor .*
                product .*
        }
}
blacklist_exceptions {
        device {
                vendor Linux
                product scsi_debug
        }
}
AA
    echo "INFO: /etc/multipath.conf updated"
    cat /etc/multipath.conf
    echo "INFO: Restarting multiapth and reload configuration"
    service multipathd restart
    sleep 5s #multipathd return premature
    multipathd -k'reconfig'

    mpath_name_list=$(dmsetup table | perl -ne 'print "$1 " if /(mpath[a-z0-9]+):[0-9 ]+multipath.*/')
    if [ "CHK${mpath_name_list}" != "CHK" ];then
        mpath_name_list="$(echo ${mpath_name_list} | sed -e 's/ $//')"
        echo "INFO: found mpath: ${mpath_name_list}"
        RETURN_STR="${mpath_name_list}"
        return 0
    fi
    return 1
} #end of functoin Setup_Multipath