aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/events/events_001_pos.ksh
blob: 189cf435e88e034a8823473285fa0c6a972b22f7 (plain) (blame)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
# Use is subject to license terms.
#

# DESCRIPTION:
# Verify zpool events command logs events.
#
# STRATEGY:
# 1. Execute zpool sub-commands on a pool.
# 2. Verify the expected events are logged in 'zpool events'.
# 3. Verify the expected events are logged by the ZED.

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/events/events_common.kshlib

verify_runnable "both"

function cleanup
{
	if poolexists $MPOOL; then
		destroy_pool $MPOOL
	fi

	for file in $VDEV1 $VDEV2 $VDEV3 $VDEV4; do
		[[ -f $file ]] && rm -f $file
	done

	log_must zed_stop
}

log_assert "Verify zpool sub-commands generate expected events"
log_onexit cleanup

log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3 $VDEV4

log_must zpool events -c
log_must zed_start

# Create a mirrored pool with two devices.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.pool_create" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.config_sync" \
    "zpool create $MPOOL mirror $VDEV1 $VDEV2"

# Set a pool property.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.history_event" \
    "zpool set comment=string $MPOOL"

# Add a cache device then remove it.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.vdev_add" \
    "zpool add -f $MPOOL spare $VDEV3"
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.vdev_remove_aux" \
    "zpool remove $MPOOL $VDEV3"

# Add a log device then remove it.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.vdev_add" \
    "zpool add -f $MPOOL log $VDEV3"
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.vdev_remove_dev" \
    "zpool remove $MPOOL $VDEV3"

# Offline then online a device.
run_and_verify -p "$MPOOL"\
    -e "resource.fs.zfs.statechange" \
    -e "sysevent.fs.zfs.config_sync" \
    "zpool offline $MPOOL $VDEV1"
run_and_verify -p "$MPOOL" \
    -e "resource.fs.zfs.statechange" \
    -e "sysevent.fs.zfs.vdev_online" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.resilver_start" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.resilver_finish" \
    "zpool online $MPOOL $VDEV1"

# Attach then detach a device from the mirror.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.vdev_attach" \
    -e "sysevent.fs.zfs.resilver_start" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.resilver_finish" \
    "zpool attach $MPOOL $VDEV1 $VDEV4"
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.vdev_remove" \
    -e "sysevent.fs.zfs.config_sync" \
    "zpool detach $MPOOL $VDEV4"

# Replace a device
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.vdev_attach" \
    -e "sysevent.fs.zfs.resilver_start" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.resilver_finish" \
    -e "sysevent.fs.zfs.vdev_remove" \
    "zpool replace -f $MPOOL $VDEV1 $VDEV4"

# Scrub a pool.
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.scrub_start" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.scrub_finish" \
    "zpool scrub $MPOOL"

# Export then import a pool
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.pool_export" \
    -e "sysevent.fs.zfs.config_sync" \
    "zpool export $MPOOL"
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.config_sync" \
    -e "sysevent.fs.zfs.history_event" \
    -e "sysevent.fs.zfs.pool_import" \
    "zpool import -d $TEST_BASE_DIR $MPOOL"

# Destroy the pool
run_and_verify -p "$MPOOL" \
    -e "sysevent.fs.zfs.pool_destroy" \
    -e "sysevent.fs.zfs.config_sync" \
    "zpool destroy $MPOOL"

log_pass "Verify zpool sub-commands generate expected events"