LVM2/test/lib check.sh get.sh test.sh utils.sh
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac at sourceware.org 2012-03-16 12:59:43
Modified files:
test/lib : check.sh get.sh test.sh utils.sh
Log message:
Update test.sh check.sh utils.sh get.sh
Indent
Better shell usage
Function simplification
More usage of 'get' functions
Don't use valgrind tracing for check and get function (faster) Update shell debugging (PS4, better stacktrace) Support paths with spaces
Export SCRIPTNAME for external usage
Watch for dmeventd unexpectedly started during test
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lib/check.sh.diff?cvsroot=lvm2&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lib/get.sh.diff?cvsroot=lvm2&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lib/test.sh.diff?cvsroot=lvm2&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/lib/utils.sh.diff?cvsroot=lvm2&r1=1.8&r2=1.9
test/lib/check.sh +145 -201
@@ -1,6 +1,5 @@ #!/bin/bash - -# Copyright (C) 2010 Red Hat, Inc. All rights reserved. +# Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions
@@ -12,7 +11,7 @@ # check.sh: assert various things about volumes -# USAGE +# USAGE: # check linear VG LV # check lv_on VG LV PV
@@ -23,14 +22,11 @@ # ... -set -e -o pipefail - -trim() -{ - trimmed=${1%% } - trimmed=${trimmed## } +test -z "$BASH" || set -e -o pipefail - echo "$trimmed" +die() { + echo "$@" >&2 + return 1 } lvl() {
@@ -38,258 +34,206 @@ } lvdevices() { - lvl -odevices "$@" | sed 's/([^)]*)//g; s/,/ /g' + get lv_devices "$@" } -mirror_images_redundant() -{ - vg=$1 - lv=$vg/$2 - - lvs -a $vg -o+devices - for i in `lvdevices $lv`; do - echo "# $i:" - lvdevices $vg/$i | sort | uniq - done > check.tmp.all - - (grep -v ^# check.tmp.all || true) | sort | uniq -d > check.tmp - - test "`cat check.tmp | wc -l`" -eq 0 || { - echo "mirror images of $lv expected redundant, but are not:" - cat check.tmp.all - exit 1 - } +mirror_images_redundant() { + local vg=$1 + local lv=$vg/$2 + lvs -a $vg -o+devices + for i in $(lvdevices $lv); do + echo "# $i:" + lvdevices $vg/$i | sort | uniq + done > check.tmp.all + + (grep -v ^# check.tmp.all || true) | sort | uniq -d > check.tmp + + test $(cat check.tmp | wc -l) -eq 0 || \ + die "mirror images of $lv expected redundant, but are not:" \ + $(cat check.tmp.all) +} + +lv_on() { + local lv=$1/$2 + (lvdevices $lv | grep -F "$3") || \ + die "LV $lv expected on $3 but is not:" \ + $(lvdevices $lv) + test $(lvdevices $lv | grep -vF "$3" | wc -l) -eq 0 || \ + die "LV $lv contains unexpected devices:" \ + $(lvdevices $lv) } mirror_images_on() { - vg=$1 - lv=$2 - + local vg=$1 + local lv=$2 shift 2 - - for i in `lvdevices $lv`; do + for i in $(lvdevices $lv); do lv_on $vg $lv $1 shift done } -lv_on() -{ - lv="$1/$2" - lvdevices $lv | grep -F "$3" || { - echo "LV $lv expected on $3 but is not:" >&2 - lvdevices $lv >&2 - exit 1 - } - test `lvdevices $lv | grep -vF "$3" | wc -l` -eq 0 || { - echo "LV $lv contains unexpected devices:" >&2 - lvdevices $lv >&2 - exit 1 - } -} - -mirror_log_on() -{ - vg="$1" - lv="$2" - where="$3" +mirror_log_on() { + local vg=$1 + local lv=$2 + local where=$3 if test "$where" = "core"; then - lvl -omirror_log "$vg/$lv" | not grep mlog + get lv_field $vg/$lv mirror_log | not grep mlog else - lv_on $vg "${lv}_mlog" "$where" + lv_on $vg ${lv}_mlog "$where" fi } -lv_is_contiguous() -{ - test `lvl --segments $1 | wc -l` -eq 1 || { - echo "LV $1 expected to be contiguous, but is not:" - lvl --segments $1 - exit 1 - } -} - -lv_is_clung() -{ - test `lvdevices $1 | sort | uniq | wc -l` -eq 1 || { - echo "LV $1 expected to be clung, but is not:" - lvdevices $! | sort | uniq - exit 1 - } -} - -mirror_images_contiguous() -{ - for i in `lvdevices $1/$2`; do - lv_is_contiguous $1/$i +lv_is_contiguous() { + local lv=$1/$2 + test $(lvl --segments $lv | wc -l) -eq 1 || \ + die "LV $lv expected to be contiguous, but is not:" \ + $(lvl --segments $lv) +} + +lv_is_clung() { + local lv=$1/$2 + test $(lvdevices $lv | sort | uniq | wc -l) -eq 1 || \ + die "LV $lv expected to be clung, but is not:" \ + $(lvdevices $lv | sort | uniq) +} + +mirror_images_contiguous() { + for i in $(lvdevices $1/$2); do + lv_is_contiguous $1 $i done } -mirror_images_clung() -{ - for i in `lvdevices $1/$2`; do - lv_is_clung $1/$i +mirror_images_clung() { + for i in $(lvdevices $1/$2); do + lv_is_clung $1 $i done } mirror() { mirror_nonredundant "$@" - mirror_images_redundant "$1" "$2" + mirror_images_redundant $1 $2 } mirror_nonredundant() { - lv="$1/$2" - lvs -oattr "$lv" | grep "^ *m.......$" >/dev/null || { - if lvs -oattr "$lv" | grep "^ *o.......$" >/dev/null && + local lv=$1/$2 + local attr=$(get lv_field $lv attr) + (echo "$attr" | grep "^m.......$" >/dev/null) || { + if (echo "$attr" | grep "^o.......$" >/dev/null) && lvs -a | fgrep "[${2}_mimage" >/dev/null; then echo "TEST WARNING: $lv is a snapshot origin and looks like a mirror," echo "assuming it is actually a mirror" else - echo "$lv expected a mirror, but is not:" - lvs -a $lv - exit 1 + die "$lv expected a mirror, but is not:" \ + $(lvs $lv) fi } - if test -n "$3"; then mirror_log_on "$1" "$2" "$3"; fi + test -z "$3" || mirror_log_on $1 $2 "$3" } mirror_legs() { - lv="$1/$2" - expect="$3" - lvdevices "$lv" - real=`lvdevices "$lv" | wc -w` - test "$expect" = "$real" + local expect=$3 + test "$expect" -eq $(lvdevices $1/$2 | wc -w) } -mirror_no_temporaries() -{ - vg=$1 - lv=$2 - lvl -oname $vg | grep $lv | not grep "tmp" || { - echo "$lv has temporary mirror images unexpectedly:" - lvl $vg | grep $lv - exit 1 - } +mirror_no_temporaries() { + local vg=$1 + local lv=$2 + (lvl -o name $vg | grep $lv | not grep "tmp") || \ + die "$lv has temporary mirror images unexpectedly:" \ + $(lvl $vg | grep $lv) } linear() { - lv="$1/$2" - lvl -ostripes "$lv" | grep "1" >/dev/null || { - echo "$lv expected linear, but is not:" - lvl "$lv" -o+devices - exit 1 - } + local lv=$1/$2 + test $(get lv_field $lv stripes -a) -eq 1 || \ + die "$lv expected linear, but is not:" \ + $(lvl $lv -o+devices) } active() { - lv="$1/$2" - lvl -oattr "$lv" 2> /dev/null | grep "^ *....a...$" >/dev/null || { - echo "$lv expected active, but lvs says it's not:" - lvl "$lv" -o+devices 2>/dev/null - exit 1 - } - dmsetup table | egrep "$1-$2: *[^ ]+" >/dev/null || { - echo "$lv expected active, lvs thinks it is but there are no mappings!" - dmsetup table | grep $1-$2: - exit 1 - } + local lv=$1/$2 + (get lv_field $lv attr $lv | grep "^....a...$" >/dev/null) || \ + die "$lv expected active, but lvs says it's not:" \ + $(lvl $lv -o+devices) + (dmsetup table | egrep "$1-$2: *[^ ]+" >/dev/null) || \ + die "$lv expected active, lvs thinks it is but there are no mappings!" \ + $(dmsetup table | grep $1-$2:) } inactive() { - lv="$1/$2" - lvl -oattr "$lv" 2> /dev/null | grep '^ *....[-isd]...$' >/dev/null || { - echo "$lv expected inactive, but lvs says it's not:" - lvl "$lv" -o+devices 2>/dev/null - exit 1 - } - dmsetup table | not egrep "$1-$2: *[^ ]+" >/dev/null || { - echo "$lv expected inactive, lvs thinks it is but there are mappings!" - dmsetup table | grep $1-$2: - exit 1 - } + local lv=$1/$2 + (get lv_field $lv attr | grep "^....[-isd]...$" >/dev/null) || \ + die "$lv expected inactive, but lvs says it's not:" \ + $(lvl $lv -o+devices) + (dmsetup table | not egrep "$1-$2: *[^ ]+" >/dev/null) || \ + die "$lv expected inactive, lvs thinks it is but there are mappings!" \ + $(dmsetup table | grep $1-$2:) } +# Check for list of LVs from given VG lv_exists() { - lv="$1/$2" - lvl "$lv" >& /dev/null || { - echo "$lv expected to exist but does not" - exit 1 - } + local vg=$1 + local lv= + while [ $# -gt 1 ]; do + shift + lv="$lv $vg/$1" + done + lvl $lv &>/dev/null || \ + die "$lv expected to exist but does not" +} + +pv_field() { + local actual=$(get pv_field "$1" "$2" "${@:4}") + test "$actual" = "$3" || \ + die "pv_field: PV=\"$1\", field=\"$2\", actual=\"$actual\", expected=\"$3\"" } -pv_field() -{ - actual=$(trim $(pvs --noheadings $4 -o $2 $1)) - - test "$actual" = "$3" || { - echo "pv_field: PV=$1, field=$2, actual=$actual, expected=$3" - exit 1 - } -} - -vg_field() -{ - actual=$(trim $(vgs --noheadings $4 -o $2 $1)) - test "$actual" = "$3" || { - echo "vg_field: vg=$1, field=$2, actual=$actual, expected=$3" - exit 1 - } -} - -lv_field() -{ - actual=$(trim $(lvs --noheadings $4 -o $2 $1)) - test "$actual" = "$3" || { - echo "lv_field: lv=$1, field=$2, actual=$actual, expected=$3" - exit 1 - } -} - -compare_fields() -{ - local cmd1=$1; - local obj1=$2; - local field1=$3; - local cmd2=$4; - local obj2=$5; - local field2=$6; - local val1; - local val2; - - val1=$($cmd1 --noheadings -o $field1 $obj1) - val2=$($cmd2 --noheadings -o $field2 $obj2) - test "$val1" = "$val2" || { - echo "compare_fields $obj1($field1): $val1 $obj2($field2): $val2" - exit 1 - } -} - -compare_vg_field() -{ - local vg1=$1; - local vg2=$2; - local field=$3; - - val1=$(vgs --noheadings -o $field $vg1) - val2=$(vgs --noheadings -o $field $vg2) - test "$val1" = "$val2" || { - echo "compare_vg_field: $vg1: $val1, $vg2: $val2" - exit 1 - } +vg_field() { + local actual=$(get vg_field $1 "$2" "${@:4}") + test "$actual" = "$3" || \ + die "vg_field: vg=$1, field=\"$2\", actual=\"$actual\", expected=\"$3\"" } -pvlv_counts() -{ +lv_field() { + local actual=$(get lv_field $1 "$2" "${@:4}") + test "$actual" = "$3" || \ + die "lv_field: lv=$lv, field=\"$2\", actual=\"$actual\", expected=\"$3\"" +} + +compare_fields() { + local cmd1=$1 + local obj1=$2 + local field1=$3 + local cmd2=$4 + local obj2=$5 + local field2=$6 + local val1=$($cmd1 --noheadings -o "$field1" "$obj1") + local val2=$($cmd2 --noheadings -o "$field2" "$obj2") + test "$val1" = "$val2" || \ + die "compare_fields $obj1($field1): $val1 $obj2($field2): $val2" +} + +compare_vg_field() { + local vg1=$1 + local vg2=$2 + local field=$3 + local val1=$(vgs --noheadings -o "$field" $vg1) + local val2=$(vgs --noheadings -o "$field" $vg2) + test "$val1" = "$val2" || \ + die "compare_vg_field: $vg1: $val1, $vg2: $val2" +} + +pvlv_counts() { local local_vg=$1 local num_pvs=$2 local num_lvs=$3 local num_snaps=$4 - - lvs -a -o+devices $local_vg - + lvs -o+devices $local_vg vg_field $local_vg pv_count $num_pvs vg_field $local_vg lv_count $num_lvs vg_field $local_vg snap_count $num_snaps } +unset LVM_VALGRIND "$@"
test/lib/get.sh +26 -4
@@ -1,4 +1,5 @@ -# Copyright (C) 2011 Red Hat, Inc. All rights reserved. +#!/bin/sh +# Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions
@@ -8,16 +9,37 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# get.sh: get various values from volumes +# +# USAGE: +# get pv_field PV field [pvs params] +# get vg_field VG field [vgs params] +# get lv_field LV field [lvs params] +# +# get lv_devices LV [lvs params] + + +# trims only leading prefix, we should not need trim trailing spaces +trim_() { + #local var=${var%"${var##*[! ]}"} # remove trailing space characters + echo ${1#"${1%%[! ]*}"} # remove leading space characters +} + pv_field() { - pvs --noheading -o $2 $1 | sed 's/^ *//' + trim_ "$(pvs --noheadings -o $2 ${@:3} $1)" } vg_field() { - vgs --noheading -o $2 $1 | sed 's/^ *//' + trim_ "$(vgs --noheadings -o $2 ${@:3} $1)" } lv_field() { - lvs --noheading -o $2 $1 | sed 's/^ *//' + trim_ "$(lvs --noheadings -o $2 ${@:3} $1)" +} + +lv_devices() { + lv_field $1 devices -a "${@:2}" | sed 's/([^)]*)//g; s/,/ /g' } +unset LVM_VALGRIND "$@"
test/lib/test.sh +35 -26
93 lines not on this page · raw message
test/lib/utils.sh +157 -158
350 lines not on this page · raw message