]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/events/events_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / events / events_001_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
25 # Use is subject to license terms.
26 #
27
28 # DESCRIPTION:
29 # Verify zpool events command logs events.
30 #
31 # STRATEGY:
32 # 1. Execute zpool sub-commands on a pool.
33 # 2. Verify the expected events are logged in 'zpool events'.
34 # 3. Verify the expected events are logged by the ZED.
35
36 . $STF_SUITE/include/libtest.shlib
37 . $STF_SUITE/tests/functional/events/events_common.kshlib
38
39 verify_runnable "both"
40
41 function cleanup
42 {
43         if poolexists $MPOOL; then
44                 destroy_pool $MPOOL
45         fi
46
47         for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
48                 [[ -f $file ]] && rm -f $file
49         done
50
51         log_must zed_stop
52 }
53
54 log_assert "Verify zpool sub-commands generate expected events"
55 log_onexit cleanup
56
57 log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3 $VDEV4
58
59 log_must zpool events -c
60 log_must zed_start
61
62 # Create a mirrored pool with two devices.
63 run_and_verify -p "$MPOOL" \
64     -e "sysevent.fs.zfs.pool_create" \
65     -e "sysevent.fs.zfs.history_event" \
66     -e "sysevent.fs.zfs.config_sync" \
67     "zpool create $MPOOL mirror $VDEV1 $VDEV2"
68
69 # Set a pool property.
70 run_and_verify -p "$MPOOL" \
71     -e "sysevent.fs.zfs.history_event" \
72     "zpool set comment=string $MPOOL"
73
74 # Add a cache device then remove it.
75 run_and_verify -p "$MPOOL" \
76     -e "sysevent.fs.zfs.config_sync" \
77     -e "sysevent.fs.zfs.vdev_add" \
78     "zpool add -f $MPOOL spare $VDEV3"
79 run_and_verify -p "$MPOOL" \
80     -e "sysevent.fs.zfs.vdev_remove_aux" \
81     "zpool remove $MPOOL $VDEV3"
82
83 # Add a log device then remove it.
84 run_and_verify -p "$MPOOL" \
85     -e "sysevent.fs.zfs.config_sync" \
86     -e "sysevent.fs.zfs.vdev_add" \
87     "zpool add -f $MPOOL log $VDEV3"
88 run_and_verify -p "$MPOOL" \
89     -e "sysevent.fs.zfs.vdev_remove_dev" \
90     "zpool remove $MPOOL $VDEV3"
91
92 # Offline then online a device.
93 run_and_verify -p "$MPOOL"\
94     -e "resource.fs.zfs.statechange" \
95     -e "sysevent.fs.zfs.config_sync" \
96     "zpool offline $MPOOL $VDEV1"
97 run_and_verify -p "$MPOOL" -d 10 \
98     -e "resource.fs.zfs.statechange" \
99     -e "sysevent.fs.zfs.vdev_online" \
100     -e "sysevent.fs.zfs.resilver_start" \
101     -e "sysevent.fs.zfs.resilver_finish" \
102     -e "sysevent.fs.zfs.history_event" \
103     -e "sysevent.fs.zfs.config_sync" \
104     "zpool online $MPOOL $VDEV1"
105
106 # Attach then detach a device from the mirror.
107 run_and_verify -p "$MPOOL" -d 10 \
108     -e "sysevent.fs.zfs.vdev_attach" \
109     -e "sysevent.fs.zfs.resilver_start" \
110     -e "sysevent.fs.zfs.resilver_finish" \
111     -e "sysevent.fs.zfs.history_event" \
112     -e "sysevent.fs.zfs.config_sync" \
113     "zpool attach $MPOOL $VDEV1 $VDEV4"
114 run_and_verify -p "$MPOOL" \
115     -e "sysevent.fs.zfs.vdev_remove" \
116     -e "sysevent.fs.zfs.config_sync" \
117     "zpool detach $MPOOL $VDEV4"
118
119 # Replace a device
120 run_and_verify -p "$MPOOL" -d 10 \
121     -e "sysevent.fs.zfs.vdev_attach" \
122     -e "sysevent.fs.zfs.resilver_start" \
123     -e "sysevent.fs.zfs.resilver_finish" \
124     -e "sysevent.fs.zfs.vdev_remove" \
125     -e "sysevent.fs.zfs.history_event" \
126     -e "sysevent.fs.zfs.config_sync" \
127     "zpool replace -f $MPOOL $VDEV1 $VDEV4"
128
129 # Scrub a pool.
130 run_and_verify -p "$MPOOL" -d 10 \
131     -e "sysevent.fs.zfs.scrub_start" \
132     -e "sysevent.fs.zfs.scrub_finish" \
133     -e "sysevent.fs.zfs.history_event" \
134     "zpool scrub $MPOOL"
135
136 # Export then import a pool
137 run_and_verify -p "$MPOOL" \
138     -e "sysevent.fs.zfs.pool_export" \
139     -e "sysevent.fs.zfs.config_sync" \
140     "zpool export $MPOOL"
141 run_and_verify -p "$MPOOL" \
142     -e "sysevent.fs.zfs.pool_import" \
143     -e "sysevent.fs.zfs.history_event" \
144     -e "sysevent.fs.zfs.config_sync" \
145     "zpool import -d $TEST_BASE_DIR $MPOOL"
146
147 # Destroy the pool
148 run_and_verify -p "$MPOOL" \
149     -e "sysevent.fs.zfs.pool_destroy" \
150     -e "sysevent.fs.zfs.config_sync" \
151     "zpool destroy $MPOOL"
152
153 log_pass "Verify zpool sub-commands generate expected events"