5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
16 # Copyright (c) 2019 Lawrence Livermore National Security, LLC.
18 .
$STF_SUITE/include
/libtest.shlib
22 # Test that zpool status colored output works.
25 # 1. Create a pool with a bunch of errors and force fault one of the vdevs.
26 # 2. Look for 'pool:' in bold.
27 # 3. Look for 'DEGRADED' in yellow
28 # 3. Look for 'FAULTED' in red
31 verify_runnable
"both"
40 log_assert
"Test colorized zpool status output"
42 DISK2
="$(echo $DISKS | cut -d' ' -f2)"
43 DISK3
="$(echo $DISKS | cut -d' ' -f3)"
45 log_must
dd if=/dev
/urandom of
=/$TESTDIR/testfile bs
=10M count
=1
49 log_must zpool offline
-f $TESTPOOL $DISK3
50 log_must wait_for_degraded
$TESTPOOL
51 log_must zinject
-d $DISK2 -e io
-T read -f 20 $TESTPOOL
52 log_must zinject
-d $DISK2 -e io
-T write -f 20 $TESTPOOL
55 log_must zpool scrub
-w $TESTPOOL
56 log_must zinject
-c all
59 # Use 'script' to fake zpool status into thinking it's running in a tty.
60 # Log the output here in case it's needed for postmortem.
61 log_note
"$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status)"
63 # Replace the escape codes with "ESC" so they're easier to grep
64 out
="$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status | \
65 grep -E 'pool:|DEGRADED' | \
66 sed -r 's/\s+//g;'$(echo -e 's/\033/ESC/g'))"
68 log_note
"$(echo $out)"
70 log_note
"Look for 'pool:' in bold"
71 log_must
eval "echo \"$out\" | grep -q 'ESC\[1mpool:ESC\[0m' "
73 log_note
"Look for 'DEGRADED' in yellow"
74 log_must
eval "echo \"$out\" | grep -q 'ESC\[0;33mDEGRADEDESC\[0m'"
77 # The escape code for 'FAULTED' is a little more tricky. The line starts like
80 # <start red escape code> loop2 FAULTED <end escape code>
82 # Luckily, awk counts the start and end escape codes as separate fields, so
83 # we can easily remove the vdev field to get what we want.
85 out
="$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status \
86 | awk '/FAULTED/{print $1$3$4}' | sed -r $(echo -e 's/\033/ESC/g'))"
88 log_note
"Look for 'FAULTED' in red"
89 log_must
eval "echo \"$out\" | grep -q 'ESC\[0;31mFAULTEDESC\[0m'"
91 log_pass
"zpool status displayed colors"