diff options
Diffstat (limited to 'tests/include/ec.sh')
-rwxr-xr-x | tests/include/ec.sh | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/tests/include/ec.sh b/tests/include/ec.sh new file mode 100755 index 0000000..12f7fe2 --- /dev/null +++ b/tests/include/ec.sh @@ -0,0 +1,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 + + |