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
|
#!/usr/bin/env bash
# Copyright (C) 2022 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
# 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,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
SKIP_WITH_LVMLOCKD=1
SKIP_WITH_LVMPOLLD=1
. lib/inittest
aux have_thin 1 0 0 || skip
aux prepare_vg 1
OUT_LOG_FILE="out"
lvcreate -l1 -T $vg/$lv1
lvcreate -l1 -n $lv2 --addtag lv_tag1 -an $vg
lvcreate -l1 -n $lv3 --addtag lv_tag3 --addtag lv_tag1 --addtag lv_tag2 $vg
check_json_vs_log() {
local format_param
local log_output=$2
local extra_cmd_line=$3
if [ -z $1 ]; then
format_param=""
else
format_param="--reportformat $1"
fi
not lvs $format_param $extra_cmd_line -o name $vg/lvolX 2>&1 | tee "$OUT_LOG_FILE"
if [ "$log_output" = "log_in_report" ]; then
# {
# "report": [
# ...
# ]
# "log": [
# { ... "log_message": "Failed to find logical volume" ...},
# ...
# }
grep -E "^[[:space:]]*\"log\": \[" out
grep -E "^[[:space:]]*\{.*\"log_message\":\"Failed to find logical volume.*\}" out
elif [ "$log_output" = "direct_log" ]; then
# Failed to find logical volume ...
not grep -E "^[[:space:]]*\"log\": \[" out
grep -E "[[:space:]]*Failed to find logical volume" out
else
false
fi
}
aux lvmconf "report/output_format = basic"
lvs -o name,kernel_major,data_percent,tags | tee "$OUT_LOG_FILE"
#
# LV KMaj Data% LV Tags
# lvol1 253 0.00
# lvol2 -1 lv_tag1
# lvol3 253 lv_tag1,lv_tag2,lv_tag3
#
grep -E "^[[:space:]]*${lv1}[[:space:]]*[[:digit:]]+[[:space:]]*[[:digit:]]+.[[:digit:]]+[[:space:]]*\$" out
grep -E "^[[:space:]]*${lv2}[[:space:]]*-1[[:space:]]*lv_tag1[[:space:]]*\$" out
grep -E "^[[:space:]]*${lv3}[[:space:]]*[[:digit:]]+[[:space:]]*lv_tag1,lv_tag2,lv_tag3\$" out
check_json_vs_log "" direct_log ""
check_json_vs_log "" direct_log "--config log/report_command_log=1"
check_json_vs_log json log_in_report ""
check_json_vs_log json_std log_in_report ""
check_json_vs_log json direct_log "--config log/report_command_log=0"
check_json_vs_log json_std direct_log "--config log/report_command_log=0"
aux lvmconf "report/output_format = json"
lvs -o name,kernel_major,data_percent,tags | tee "$OUT_LOG_FILE"
# {
# "report": [
# {
# "lv": [
# {"lv_name":"lvol1", "lv_kernel_major":"253", "data_percent":"0.00", "lv_tags":""},
# {"lv_name":"lvol2", "lv_kernel_major":"-1", "data_percent":"", "lv_tags":"lv_tag1"},
# {"lv_name":"lvol3", "lv_kernel_major":"253", "data_percent":"", "lv_tags":"lv_tag1,lv_tag2,lv_tag3"}
# ]
# }
# ]
# }
grep -E "^[[:space:]]*{\"lv_name\":\"$lv1\", \"lv_kernel_major\":\"[[:digit:]]+\", \"data_percent\":\"[[:digit:]]+.[[:digit:]]+\", \"lv_tags\":\"\"},\$" out
grep -E "^[[:space:]]*{\"lv_name\":\"$lv2\", \"lv_kernel_major\":\"-1\", \"data_percent\":\"\", \"lv_tags\":\"lv_tag1\"},\$" out
grep -E "^[[:space:]]*{\"lv_name\":\"$lv3\", \"lv_kernel_major\":\"[[:digit:]]+\", \"data_percent\":\"\", \"lv_tags\":\"lv_tag1,lv_tag2,lv_tag3\"}\$" out
check_json_vs_log "" log_in_report ""
check_json_vs_log "" direct_log "--config log/report_command_log=0"
aux lvmconf "report/output_format = json_std"
lvs -o name,kernel_major,data_percent,tags | tee "$OUT_LOG_FILE"
# {
# "report": [
# {
# "lv": [
# {"lv_name":"lvol1", "lv_kernel_major":253, "data_percent":0.00, "lv_tags":[]},
# {"lv_name":"lvol2", "lv_kernel_major":-1, "data_percent":null, "lv_tags":["lv_tag1"]},
# {"lv_name":"lvol3", "lv_kernel_major":253, "data_percent":null, "lv_tags":["lv_tag1","lv_tag2","lv_tag3"]}
# ]
# }
# ]
# }
grep -E "^[[:space:]]*{\"lv_name\":\"$lv1\", \"lv_kernel_major\":[[:digit:]]+, \"data_percent\":[[:digit:]]+.[[:digit:]]+, \"lv_tags\":\[\]},\$" out
grep -E "^[[:space:]]*{\"lv_name\":\"$lv2\", \"lv_kernel_major\":-1, \"data_percent\":null, \"lv_tags\":\[\"lv_tag1\"\]},\$" out
grep -E "^[[:space:]]*{\"lv_name\":\"$lv3\", \"lv_kernel_major\":[[:digit:]]+, \"data_percent\":null, \"lv_tags\":\[\"lv_tag1\",\"lv_tag2\",\"lv_tag3\"\]}\$" out
check_json_vs_log "" log_in_report ""
check_json_vs_log "" direct_log "--config log/report_command_log=0"
aux lvmconf "log/report_command_log = 0"
check_json_vs_log "" direct_log ""
check_json_vs_log "" log_in_report "--config log/report_command_log=1"
aux lvmconf "log/report_command_log = 1"
check_json_vs_log "" log_in_report ""
check_json_vs_log "" direct_log "--config log/report_command_log=0"
vgremove -ff $vg
|