2014-06-10 11:20:58 +04:00
#!/bin/sh
2015-03-16 16:55:58 +03:00
# Copyright (C) 2014-2015 Red Hat, Inc. All rights reserved.
2014-06-10 11:20:58 +04:00
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2014-06-10 11:20:58 +04:00
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2014-06-10 11:20:58 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2014-06-10 11:20:58 +04:00
aux prepare_pvs 6 16
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# MAKE SURE ALL PV, VG AND LV NAMES CREATED IN
# THIS TEST ARE UNIQUE - THIS SIMPLIFIES TESTING
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# create $VGS with assorted tags
2014-10-07 11:54:47 +04:00
vgcreate $vg1 --vgmetadatacopies 2 --addtag "vg_tag3" --addtag "vg_tag2" -s 4m " $dev1 " " $dev2 " " $dev3 "
vgcreate $vg2 --addtag "vg_tag2" -s 4m " $dev4 " " $dev5 "
vgcreate $vg3 --addtag "vg_tag1" -s 4m " $dev6 "
2014-06-10 11:20:58 +04:00
# add PV assorted tags
2014-10-07 11:54:47 +04:00
pvchange --addtag "pv_tag3" --addtag "pv_tag1" --addtag "pv_tag2" " $dev1 "
pvchange --addtag "pv_tag1" --addtag "pv_tag4" " $dev6 "
2014-06-10 11:20:58 +04:00
# create $LVS with assorted tags and various sizes
lvcreate --addtag 'lv_tag2.-+/=!:&#' --addtag "lv_tag1" -L8m -n "vol1" $vg1
lvcreate --addtag "lv_tag1" -L4m -n "vol2" $vg1
lvcreate --readahead 512 --addtag "lv_tag1" -L16m -n "abc" $vg2
lvcreate --readahead 512 -My --minor 254 -L4m -n "xyz" $vg3
2014-06-17 20:28:27 +04:00
lvcreate -L4m -aey -n "orig" $vg3
2014-06-10 11:20:58 +04:00
lvcreate -L4m -s " $vg3 /orig " -n "snap"
OUT_LOG_FILE = "out"
ERR_LOG_FILE = "err"
2015-03-16 16:55:58 +03:00
sel( ) {
2014-06-10 11:20:58 +04:00
local items_found
2015-03-16 16:55:58 +03:00
${ 1 } s --noheadings -o ${ 1 } _name --select " $2 " 2>" $ERR_LOG_FILE " | tee " $OUT_LOG_FILE "
shift 2
test -f " $OUT_LOG_FILE " || {
2014-06-10 11:20:58 +04:00
echo " >>> Missing log file to check!"
return 1
}
# there shouldn't be any selection syntax error
2015-03-16 16:55:58 +03:00
grep "Selection syntax error at" " $ERR_LOG_FILE " >/dev/null && {
2014-06-10 11:20:58 +04:00
echo " >>> Selection syntax error hit!"
return 1
}
2015-03-16 16:55:58 +03:00
items_found = $( wc -l " $OUT_LOG_FILE " | cut -f 1 -d ' ' )
2014-06-10 11:20:58 +04:00
# the number of lines on output must match
2015-09-08 15:11:46 +03:00
test " $items_found " -eq $# || {
2014-06-10 11:20:58 +04:00
echo " >>> NUMBER OF ITEMS EXPECTED: $# ( $@ ) "
2014-06-30 23:00:08 +04:00
echo " >>> NUMBER OF ITEMS FOUND: $items_found ( $( < $OUT_LOG_FILE ) ) "
2014-06-10 11:20:58 +04:00
return 1
}
# the names selected must be correct
# each pv, vg and lv name is unique so just check
# the presence of the names given as arg
2015-03-16 16:55:58 +03:00
for name in " $@ " ; do
grep " $name " " $OUT_LOG_FILE " >/dev/null || {
2014-06-10 11:20:58 +04:00
echo " >>> $name not found in the output log "
return 1
}
done
2015-03-16 16:55:58 +03:00
rm -f " $OUT_LOG_FILE " " $ERR_LOG_FILE "
2014-06-10 11:20:58 +04:00
}
##########################
# STRING FIELD SELECTION #
##########################
#$LVS 'lv_name="vol1"' && result vol1
2015-03-16 16:55:58 +03:00
sel lv 'lv_name="vol1"' vol1
2014-06-10 11:20:58 +04:00
#$LVS 'lv_name!="vol1"' && result vol2 abc xyz
2015-03-16 16:55:58 +03:00
sel lv 'lv_name!="vol1"' vol2 abc xyz orig snap
2014-06-10 11:20:58 +04:00
# check string values are accepted without quotes too
2015-03-16 16:55:58 +03:00
sel lv 'lv_name=vol1' vol1
2014-06-10 11:20:58 +04:00
# check single quotes are also accepted instead of double quotes
2015-03-16 16:55:58 +03:00
sel lv "lv_name='vol1'" vol1
2014-06-10 11:20:58 +04:00
###############################
# STRING LIST FIELD SELECTION #
###############################
2015-03-16 16:55:58 +03:00
sel pv 'tags=["pv_tag1"]'
2014-06-10 11:20:58 +04:00
# for one item, no need to use []
2015-03-16 16:55:58 +03:00
sel pv 'tags="pv_tag1"' " $dev1 " " $dev6 "
2014-06-10 11:20:58 +04:00
# no match
2015-03-16 16:55:58 +03:00
sel pv 'tags=["pv_tag1" && "pv_tag2"]'
sel pv 'tags=["pv_tag1" && "pv_tag2" && "pv_tag3"]' " $dev1 "
2014-06-10 11:20:58 +04:00
# check the order has no effect on selection result
2015-03-16 16:55:58 +03:00
sel pv 'tags=["pv_tag3" && "pv_tag2" && "pv_tag1"]' " $dev1 "
sel pv 'tags=["pv_tag4" || "pv_tag3"]' " $dev1 " " $dev6 "
sel pv 'tags!=["pv_tag1"]' " $dev1 " " $dev2 " " $dev3 " " $dev4 " " $dev5 " " $dev6 "
2014-06-10 11:20:58 +04:00
# check mixture of && and || - this is not allowed
2015-03-16 16:55:58 +03:00
not sel pv 'tags=["pv_tag1" && "pv_tag2" || "pv_tag3"]'
2015-09-17 11:19:15 +03:00
# check selection with blank value
sel lv 'tags=""' xyz orig snap
sel lv 'tags={}' xyz orig snap
sel lv 'tags=[]' xyz orig snap
2015-11-18 12:54:09 +03:00
# check subset selection
sel pv 'tags={"pv_tag1"}' " $dev1 " " $dev6 "
sel pv 'tags={"pv_tag1" && "pv_tag2"}' " $dev1 "
2014-06-10 11:20:58 +04:00
##########################
# NUMBER FIELD SELECTION #
##########################
2015-03-16 16:55:58 +03:00
sel vg 'pv_count=3' $vg1
sel vg 'pv_count!=3' $vg3 $vg2
sel vg 'pv_count<2' $vg3
sel vg 'pv_count<=2' $vg3 $vg2
sel vg 'pv_count>2' $vg1
sel vg 'pv_count>=2' $vg1 $vg2
2014-06-10 11:20:58 +04:00
########################
# SIZE FIELD SELECTION #
########################
# check size units are accepted as well as floating point numbers for sizes
2015-03-16 16:55:58 +03:00
sel lv 'size=8388608b' vol1
sel lv 'size=8192k' vol1
sel lv 'size=8m' vol1
sel lv 'size=8.00m' vol1
sel lv 'size=0.0078125g' vol1
sel lv 'size=0.00000762939453125t' vol1
sel lv 'size=0.000000007450580596923828125p' vol1
sel lv 'size=0.0000000000072759576141834259033203125e' vol1
sel lv 'size>8m' abc
sel lv 'size>=8m' abc vol1
sel lv 'size<8m' vol2 xyz orig snap
sel lv 'size<=8m' vol2 xyz vol1 orig snap
2014-06-10 11:20:58 +04:00
###########################
# PERCENT FIELD SELECTION #
###########################
2014-06-18 15:26:47 +04:00
if aux target_at_least dm-snapshot 1 10 0; then
# Test zero percent only if snapshot can be zero.
# Before 1.10.0, the snap percent included metadata size.
2015-03-16 16:55:58 +03:00
sel lv 'snap_percent=0' snap
2014-06-18 15:26:47 +04:00
fi
2015-09-08 15:11:46 +03:00
dd if = /dev/zero of = " $DM_DEV_DIR / $vg3 /snap " bs = 1M count = 1 conv = fdatasync
2015-03-16 16:55:58 +03:00
sel lv 'snap_percent<50' snap
sel lv 'snap_percent>50'
2015-09-08 15:11:46 +03:00
# overflow snapshot -> invalidated, but still showing 100%
not dd if = /dev/zero of = " $DM_DEV_DIR / $vg3 /snap " bs = 1M count = 4 conv = fdatasync
2015-03-16 16:55:58 +03:00
sel lv 'snap_percent=100' snap
2014-06-10 11:20:58 +04:00
# % char is accepted as suffix for percent values
2015-03-16 16:55:58 +03:00
sel lv 'snap_percent=100%' snap
2014-06-10 11:20:58 +04:00
# percent values over 100% are not accepted
2015-03-16 16:55:58 +03:00
not sel lv 'snap_percent=101%'
2014-06-10 11:20:58 +04:00
#########################
# REGEX FIELD SELECTION #
#########################
2015-03-16 16:55:58 +03:00
sel lv 'lv_name=~"^vol[12]"' vol1 vol2
sel lv 'lv_name!~"^vol[12]"' abc xyz orig snap
2014-06-10 11:20:58 +04:00
# check regex is accepted without quotes too
2015-03-16 16:55:58 +03:00
sel lv 'lv_name=~^vol[12]' vol1 vol2
2014-06-10 11:20:58 +04:00
###########
# GENERIC #
###########
# check prefix works for selection too
2015-03-16 16:55:58 +03:00
sel lv 'lv_name="vol1"' vol1
sel lv 'name="vol1"' vol1
2014-06-10 11:20:58 +04:00
# check reserved values are accepted for certain fields as well as usual values
2015-03-16 16:55:58 +03:00
sel vg 'vg_mda_copies=unmanaged' $vg2 $vg3
sel vg 'vg_mda_copies=2' $vg1
2014-10-27 13:53:01 +03:00
# also, we must match only vg1, not including vg2 and vg3
# when comparing ranges - unamanged is mapped onto 2^64 - 1 internally,
# so we need to skip this internal value if it matches with selection criteria!
2015-03-16 16:55:58 +03:00
sel vg 'vg_mda_copies>=2' $vg1
not sel vg 'vg_mda_copies=18446744073709551615'
2014-06-10 11:20:58 +04:00
2015-03-16 16:55:58 +03:00
sel lv 'lv_read_ahead=auto' vol1 vol2 orig snap
sel lv 'lv_read_ahead=256k' abc xyz
2014-06-10 11:20:58 +04:00
2015-03-16 16:55:58 +03:00
sel lv 'lv_minor=-1' vol1 vol2 abc orig snap
sel lv 'lv_minor=undefined' vol1 vol2 abc orig snap
sel lv 'lv_minor=undef' vol1 vol2 abc orig snap
sel lv 'lv_minor=unknown' vol1 vol2 abc orig snap
sel lv 'lv_minor=254' xyz
2015-07-02 12:46:58 +03:00
# also test synonym for string field type
sel lv 'seg_monitor=undefined' vol1 vol2 abc abc orig snap xyz
2014-06-10 11:20:58 +04:00
# if size unit not spefied, the 'm' (MiB) unit is used by default
2015-03-16 16:55:58 +03:00
sel lv 'lv_size=8' vol1
2014-06-10 11:20:58 +04:00
# no need to use quotes for the whole selection string if it does not clash with shell
2015-03-16 16:55:58 +03:00
sel lv name = vol1 vol1
2014-06-10 11:20:58 +04:00
##########################################
# FORMING MORE COMPLEX SELECTION CLAUSES #
##########################################
# AND clause
2015-03-16 16:55:58 +03:00
sel lv 'lv_tags=lv_tag1 && lv_size=4m' vol2
2014-06-10 11:20:58 +04:00
# OR clause
2015-03-16 16:55:58 +03:00
sel lv 'lv_name=vol1 || lv_name=vol2' vol1 vol2
2014-06-10 11:20:58 +04:00
# grouping by using ( )
2015-03-16 16:55:58 +03:00
sel lv '(lv_name=vol1 || lv_name=vol2) || vg_tags=vg_tag1' vol1 vol2 orig snap xyz
sel lv '(lv_name=vol1 && lv_size=100m) || vg_tags=vg_tag1' xyz orig snap
sel lv '(lv_name=vol1 || lv_name=vol2) && vg_tags=vg_tag1'
sel lv '(lv_name=vol1 || lv_name=vol2) && lv_size < 8m' vol2
sel lv '(lv_name=vol1 && lv_size=8m) && vg_tags=vg_tag2' vol1
2014-06-10 11:20:58 +04:00
# negation of clause grouped by ( )
2015-03-16 16:55:58 +03:00
sel lv '!(lv_name=vol1 || lv_name=vol2)' abc xyz orig snap