]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/events/events_common.kshlib
9ef97ca62e9586b6e9b075da249f5562221391d6
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / events / events_common.kshlib
1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
24 # Use is subject to license terms.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/events/events.cfg
29
30 function run_and_verify
31 {
32 typeset event pool
33 set -A events
34
35 while getopts "e:p:z:" opt; do
36 case $opt in
37 e)
38 events[${#events[*]}+1]=$OPTARG
39 ;;
40 p)
41 pool=$OPTARG
42 ;;
43 z)
44 zedlog=$OPTARG
45 ;;
46 esac
47 done
48 shift $(($OPTIND - 1))
49
50 pool=${pool:-$TESTPOOL}
51 zedlog=${zedlog:-$ZEDLET_DIR/zed.debug.log}
52 fullcmd="$1"
53 cmd=$(echo $fullcmd | awk '{print $1}')
54 subcmd=$(echo $fullcmd | awk '{print $2}')
55
56 # If we aren't running zpool or zfs, something is wrong
57 [[ $cmd == "zpool" || $cmd == "zfs" ]] || \
58 log_fail "run_and_verify called with \"$cmd ($fullcmd)\""
59
60 # Run the command as provided and collect the new events.
61 log_must zpool events -c
62 if [[ -f $zedlog ]]; then
63 cp -f $zedlog $zedlog.old
64 fi
65
66 log_must eval "$fullcmd"
67
68 log_must zpool events > $TMP_EVENTS 2>/dev/null
69 log_must zpool events -v > $TMP_EVENTS_FULL 2>/dev/null
70 if [[ -f $zedlog ]]; then
71 sleep 5 # Brief delay for the ZED to handle the event.
72 diff $zedlog.old $zedlog | grep "^> " | sed 's/^> //g' \
73 >$TMP_EVENTS_ZED
74 fi
75
76 # Verify all the expected events appear in the log.
77 for event in ${events[*]}; do
78
79 # Verify the event is in in the short output.
80 log_must grep -q "$event" $TMP_EVENTS
81
82 # Verify the event is in the verbose output with pool name.
83 log_must awk -v event="$event" \
84 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
85 $TMP_EVENTS_FULL >$TMP_EVENT_FULL
86 log_must grep -q "pool = \"$pool\"" $TMP_EVENT_FULL
87
88 # Verify the event was received by the ZED and logged.
89 log_must awk -v event="$event" \
90 'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
91 $TMP_EVENTS_ZED >$TMP_EVENT_ZED
92 log_must grep -q "^ZEVENT_POOL=$pool" $TMP_EVENT_ZED
93
94 done
95
96 log_must rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENT_FULL \
97 $TMP_EVENTS_ZED $TMP_EVENT_ZED $zedlog.old
98 }