File: zpool_script.shlib

package info (click to toggle)
zfs-linux 2.3.4~git20250812.3b64a96-1
  • links: PTS, VCS
  • area: contrib
  • in suites: experimental
  • size: 70,688 kB
  • sloc: ansic: 393,668; sh: 68,068; asm: 47,734; python: 8,160; makefile: 5,125; perl: 859; sed: 41
file content (49 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (5)
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
#
# Common functions used by the zpool_status and zpool_iostat tests for running
# scripts with the -c option.
#
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
#

. $STF_SUITE/include/libtest.shlib

function test_zpool_script {
	script="$1"
	testpool="$2"
	cmd="$3"
	wholecmd="$cmd $script $testpool"
	out="$($wholecmd)"

	# Default number of columns that get printed without -c
	if [ "$cmd" != "${cmd/iostat/_/}" ]; then
		# iostat
		dcols=7
	else
		
		# status
		dcols=5
	fi
		
	# Get the new column name that the script created
	col="$(echo "$out" | \
	    awk '/^pool +alloc +free +read +write +/ {print $8} \
	    /NAME +STATE +READ +WRITE +CKSUM/ {print $6}')"

	if [ -z "$col" ] ; then
		log_fail "'$wholecmd' created no new columns"
	fi

	# Count the number of columns for each vdev.  Each script should produce
	# at least one new column value.  Even if scripts return blank, zpool
	# will convert the blank to a '-' to make things awk-able.  Normal
	# zpool iostat -v output is 7 columns, so if the script ran correctly
	# we should see more than that.
	if ! newcols=$(echo "$out" | \
		awk '/\/dev/ {print NF-'$dcols'; if (NF <= '$dcols') {exit 1}}' | \
		head -n 1)
  then
		log_fail "'$wholecmd' didn't create a new column value"
	else
		log_note "'$wholecmd' passed ($newcols new columns)"
	fi
}