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 https://opensource.org/licenses/CDDL-1.0. 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 39verify_runnable "both" 40 41function 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 54log_assert "Verify zpool sub-commands generate expected events" 55log_onexit cleanup 56 57log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2 $VDEV3 $VDEV4 58 59log_must zpool events -c 60log_must zed_start 61 62# Create a mirrored pool with two devices. 63run_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. 70run_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. 75run_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" 79run_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. 84run_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" 88run_and_verify -p "$MPOOL" \ 89 -e "sysevent.fs.zfs.vdev_remove_dev" \ 90 "zpool remove $MPOOL $VDEV3" 91 92# Offline then online a device. 93run_and_verify -p "$MPOOL"\ 94 -e "resource.fs.zfs.statechange" \ 95 -e "sysevent.fs.zfs.config_sync" \ 96 "zpool offline $MPOOL $VDEV1" 97run_and_verify -p "$MPOOL" \ 98 -e "resource.fs.zfs.statechange" \ 99 -e "sysevent.fs.zfs.vdev_online" \ 100 -e "sysevent.fs.zfs.config_sync" \ 101 -e "sysevent.fs.zfs.resilver_start" \ 102 -e "sysevent.fs.zfs.history_event" \ 103 -e "sysevent.fs.zfs.resilver_finish" \ 104 "zpool online $MPOOL $VDEV1" 105 106# Attach then detach a device from the mirror. 107run_and_verify -p "$MPOOL" \ 108 -e "sysevent.fs.zfs.vdev_attach" \ 109 -e "sysevent.fs.zfs.resilver_start" \ 110 -e "sysevent.fs.zfs.config_sync" \ 111 -e "sysevent.fs.zfs.history_event" \ 112 -e "sysevent.fs.zfs.resilver_finish" \ 113 "zpool attach $MPOOL $VDEV1 $VDEV4" 114run_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 120run_and_verify -p "$MPOOL" \ 121 -e "sysevent.fs.zfs.vdev_attach" \ 122 -e "sysevent.fs.zfs.resilver_start" \ 123 -e "sysevent.fs.zfs.config_sync" \ 124 -e "sysevent.fs.zfs.history_event" \ 125 -e "sysevent.fs.zfs.resilver_finish" \ 126 -e "sysevent.fs.zfs.vdev_remove" \ 127 "zpool replace -f $MPOOL $VDEV1 $VDEV4" 128 129# Scrub a pool. 130run_and_verify -p "$MPOOL" \ 131 -e "sysevent.fs.zfs.scrub_start" \ 132 -e "sysevent.fs.zfs.history_event" \ 133 -e "sysevent.fs.zfs.scrub_finish" \ 134 "zpool scrub $MPOOL" 135 136# Export then import a pool 137run_and_verify -p "$MPOOL" \ 138 -e "sysevent.fs.zfs.pool_export" \ 139 -e "sysevent.fs.zfs.config_sync" \ 140 "zpool export $MPOOL" 141run_and_verify -p "$MPOOL" \ 142 -e "sysevent.fs.zfs.config_sync" \ 143 -e "sysevent.fs.zfs.history_event" \ 144 -e "sysevent.fs.zfs.pool_import" \ 145 "zpool import -d $TEST_BASE_DIR $MPOOL" 146 147# Destroy the pool 148run_and_verify -p "$MPOOL" \ 149 -e "sysevent.fs.zfs.pool_destroy" \ 150 -e "sysevent.fs.zfs.config_sync" \ 151 "zpool destroy $MPOOL" 152 153log_pass "Verify zpool sub-commands generate expected events" 154