]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Add zpool events tests
authorBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 18 May 2017 19:57:21 +0000 (15:57 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 22 May 2017 16:34:42 +0000 (12:34 -0400)
* events_001_pos - Verify the expected events are generated when
  invoking the various zpool sub-commands.  These events must
  appear in `zpool event` and be consumed by the ZED.

* events_002_pos - Verify the ZED consumes events which were
  generated while it wasn't running when it is started.
  Additionally, verify that events are only processed once.

As part of this change the default.cfg used by the test suite
was changed to a default.cfg.in file.  This was needed so the
install location of all zed scripts, not only the enabled ones,
could be reliably determined.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #6128

19 files changed:
configure.ac
scripts/zfs-tests.sh
tests/runfiles/linux.run
tests/zfs-tests/include/.gitignore [new file with mode: 0644]
tests/zfs-tests/include/Makefile.am
tests/zfs-tests/include/default.cfg [deleted file]
tests/zfs-tests/include/default.cfg.in [new file with mode: 0644]
tests/zfs-tests/include/libtest.shlib
tests/zfs-tests/tests/functional/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zpool_status/zpool_status_003_pos.ksh
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_005_pos.ksh
tests/zfs-tests/tests/functional/events/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/events/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/events/events.cfg [new file with mode: 0644]
tests/zfs-tests/tests/functional/events/events_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/events/events_002_pos.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/events/events_common.kshlib [new file with mode: 0755]
tests/zfs-tests/tests/functional/events/setup.ksh [new file with mode: 0755]
zfs-script-config.sh.in

index 100ab81d99f6b1cc4d2c37f383a5af2679e965c4..06b6662fd0edad8bdfee5cdb756ba57ed8dd72a4 100644 (file)
@@ -168,6 +168,7 @@ AC_CONFIG_FILES([
        tests/zfs-tests/cmd/threadsappend/Makefile
        tests/zfs-tests/cmd/xattrtest/Makefile
        tests/zfs-tests/include/Makefile
+       tests/zfs-tests/include/default.cfg
        tests/zfs-tests/tests/Makefile
        tests/zfs-tests/tests/functional/Makefile
        tests/zfs-tests/tests/functional/acl/Makefile
@@ -234,6 +235,7 @@ AC_CONFIG_FILES([
        tests/zfs-tests/tests/functional/ctime/Makefile
        tests/zfs-tests/tests/functional/delegate/Makefile
        tests/zfs-tests/tests/functional/devices/Makefile
+       tests/zfs-tests/tests/functional/events/Makefile
        tests/zfs-tests/tests/functional/exec/Makefile
        tests/zfs-tests/tests/functional/fault/Makefile
        tests/zfs-tests/tests/functional/features/async_destroy/Makefile
index f17f1e19fadf81119105d4b72a721349b3682357..3208b8df2a41cb7cab5564c4f3ae951e16c05204 100755 (executable)
@@ -401,6 +401,8 @@ constrain_path
 # Check if ksh exists
 #
 [ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
+[ -e "$STF_SUITE/include/default.cfg" ] || fail \
+    "Missing $STF_SUITE/include/default.cfg file."
 
 #
 # Verify the ZFS module stack if loaded.
index e83a9ed0f369d618b31245c027ad02a594c572ee..7e64c67140b12b4f080b0d49fa3d946f42f7dc38 100644 (file)
@@ -344,6 +344,9 @@ tests = ['zfs_allow_001_pos', 'zfs_allow_002_pos',
 [tests/functional/devices]
 tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos']
 
+[tests/functional/events]
+tests = ['events_001_pos', 'events_002_pos']
+
 [tests/functional/exec]
 tests = ['exec_001_pos', 'exec_002_neg']
 
diff --git a/tests/zfs-tests/include/.gitignore b/tests/zfs-tests/include/.gitignore
new file mode 100644 (file)
index 0000000..30d8a77
--- /dev/null
@@ -0,0 +1 @@
+/default.cfg
index d6fb32b610bf7e10cdf64dc9bef680c84c3c7fc5..579e1356ed0e25ef613c20899e4b22c77b70bdce 100644 (file)
@@ -6,3 +6,8 @@ dist_pkgdata_SCRIPTS = \
        math.shlib \
        properties.shlib \
        zpool_script.shlib
+
+EXTRA_DIST=default.cfg.in
+
+distclean-local::
+       -$(RM) $(dist_pkgdata_SCRIPTS)
diff --git a/tests/zfs-tests/include/default.cfg b/tests/zfs-tests/include/default.cfg
deleted file mode 100644 (file)
index 84edce7..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-#
-# 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 2008 Sun Microsystems, Inc.  All rights reserved.
-# Use is subject to license terms.
-#
-
-#
-# Copyright (c) 2016 by Delphix. All rights reserved.
-# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
-#
-
-. $STF_SUITE/include/commands.cfg
-. $STF_SUITE/include/libtest.shlib
-
-# ZFS Directories
-export ZEDLETDIR=${ZEDLETDIR:-/etc/zfs/zed.d}
-export ZPOOLSCRIPTDIR=${ZPOOLSCRIPTDIR:-/etc/zfs/zpool.d}
-
-# Define run length constants
-export RT_LONG="3"
-export RT_MEDIUM="2"
-export RT_SHORT="1"
-
-# Define macro for zone test
-export ZONE_POOL="zonepool"
-export ZONE_CTR="zonectr"
-
-# ensure we're running in the C locale, since
-# localised messages may result in test failures
-export LC_ALL="C"
-export LANG="C"
-
-#
-# pattern to ignore from 'zpool list'.
-#
-export NO_POOLS="no pools available"
-
-# pattern to ignore from 'zfs list'.
-export NO_DATASETS="no datasets available"
-
-export TEST_BASE_DIR="/var/tmp"
-
-# Default to compression ON
-export COMPRESSION_PROP=on
-
-# Default to using the checksum
-export CHECKSUM_PROP=on
-
-# some common variables used by test scripts :
-export FIO_SCRIPTS=$STF_SUITE/tests/perf/fio
-export PERF_SCRIPTS=$STF_SUITE/tests/perf/scripts
-
-# some test pool names
-export TESTPOOL=testpool
-export TESTPOOL1=testpool1
-export TESTPOOL2=testpool2
-export TESTPOOL3=testpool3
-export PERFPOOL=perfpool
-
-# some test file system names
-export TESTFS=testfs
-export TESTFS1=testfs1
-export TESTFS2=testfs2
-export TESTFS3=testfs3
-
-# some test directory names
-export TESTDIR=${TEST_BASE_DIR%%/}/testdir
-export TESTDIR0=${TEST_BASE_DIR%%/}/testdir0
-export TESTDIR1=${TEST_BASE_DIR%%/}/testdir1
-export TESTDIR2=${TEST_BASE_DIR%%/}/testdir2
-
-# some test sub file system names
-export TESTSUBFS=subfs
-export TESTSUBFS1=subfs1
-export TESTSUBFS2=subfs2
-
-# some temp files
-export TEMPFILE=${TEST_BASE_DIR%%/}/tempfile$$
-export TEMPFILE0=${TEST_BASE_DIR%%/}/tempfile0$$
-export TEMPFILE1=${TEST_BASE_DIR%%/}/tempfile1$$
-export TEMPFILE2=${TEST_BASE_DIR%%/}/tempfile2$$
-
-export ZFSROOT=
-
-export TESTSNAP=testsnap
-export TESTSNAP1=testsnap1
-export TESTSNAP2=testsnap2
-export TESTCLONE=testclone
-export TESTCLONE1=testclone1
-export TESTCLONE2=testclone2
-export TESTCLCT=testclct
-export TESTCTR=testctr
-export TESTCTR1=testctr1
-export TESTCTR2=testctr2
-export TESTVOL=testvol
-export TESTVOL1=testvol1
-export TESTVOL2=testvol2
-export TESTFILE0=testfile0
-export TESTFILE1=testfile1
-export TESTFILE2=testfile2
-export TESTBKMARK=testbkmark
-
-export LONGPNAME="poolname50charslong_012345678901234567890123456789"
-export LONGFSNAME="fsysname50charslong_012345678901234567890123456789"
-export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
-export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
-
-export VOLSIZE=150m
-export BIGVOLSIZE=1eb
-
-# Default to limit disks to be checked
-export MAX_FINDDISKSNUM=6
-
-# Default minimum size for file based vdevs in the test suite
-export MINVDEVSIZE=$((256 * 1024 * 1024))
-
-# Minimum vdev size possible as defined in the OS
-export SPA_MINDEVSIZE=$((64 * 1024 * 1024))
-
-# For iscsi target support
-export ISCSITGTFILE=/tmp/iscsitgt_file
-export ISCSITGT_FMRI=svc:/system/iscsitgt:default
-if ! is_linux; then
-export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \
-    '{print $3}')
-fi
-
-#
-# finally, if we're running in a local zone
-# we take some additional actions
-if ! is_global_zone; then
-       reexport_pool
-fi
-
-export ZFS_VERSION=5
-export ZFS_ALL_VERSIONS="1 2 3 4 5"
-
-for i in $ZFS_ALL_VERSIONS; do
-       eval 'export ZFS_VERSION_$i="v${i}-fs"'
-done
-
-export MAX_PARTITIONS=8
-
-if is_linux; then
-       unpack_opts="--sparse -xf"
-       pack_opts="--sparse -cf"
-       verbose=" -v"
-       unpack_preserve=" -xpf"
-       pack_preserve=" -cpf"
-
-       ZVOL_DEVDIR="/dev/zvol"
-       ZVOL_RDEVDIR="/dev/zvol"
-       DEV_RDSKDIR="/dev"
-       DEV_MPATHDIR="/dev/mapper"
-
-       ZEDLET_DIR="/var/tmp/zed"
-       VDEVID_CONF="$ZEDLET_DIR/vdev_id.conf"
-       VDEVID_CONF_ETC="/etc/zfs/vdev_id.conf"
-
-
-       NEWFS_DEFAULT_FS="ext2"
-else
-       unpack_opts="xv"
-       pack_opts="cf"
-       verbose="v"
-       unpack_preserve="xpf"
-       pack_preserve="cpf"
-
-       ZVOL_DEVDIR="/dev/zvol/dsk"
-       ZVOL_RDEVDIR="/dev/zvol/rdsk"
-       DEV_DSKDIR="/dev/dsk"
-       DEV_RDSKDIR="/dev/rdsk"
-
-       NEWFS_DEFAULT_FS="ufs"
-fi
-export unpack_opts pack_opts verbose unpack_preserve pack_preserve \
-       ZVOL_DEVDIR ZVOL_RDEVDIR NEWFS_DEFAULT_FS DEV_RDSKDIR DEV_MPATHDIR \
-       ZEDLET_DIR VDEVID_CONF VDEVID_CONF_ETC
diff --git a/tests/zfs-tests/include/default.cfg.in b/tests/zfs-tests/include/default.cfg.in
new file mode 100644 (file)
index 0000000..9ac74f2
--- /dev/null
@@ -0,0 +1,201 @@
+#
+# 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 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2016 by Delphix. All rights reserved.
+# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
+#
+
+. $STF_SUITE/include/commands.cfg
+. $STF_SUITE/include/libtest.shlib
+
+# ZFS Directories
+export prefix=@prefix@
+export exec_prefix=@exec_prefix@
+export ZEDLET_ETC_DIR=${ZEDLET_ETC_DIR:-@sysconfdir@/zfs/zed.d}
+export ZEDLET_LIBEXEC_DIR=${ZEDLET_LIBEXEC_DIR:-@libexecdir@/zfs/zed.d}
+export ZPOOL_SCRIPT_DIR=${ZPOOL_SCRIPT_DIR:-@sysconfdir@/zfs/zpool.d}
+
+# Define run length constants
+export RT_LONG="3"
+export RT_MEDIUM="2"
+export RT_SHORT="1"
+
+# Define macro for zone test
+export ZONE_POOL="zonepool"
+export ZONE_CTR="zonectr"
+
+# ensure we're running in the C locale, since
+# localised messages may result in test failures
+export LC_ALL="C"
+export LANG="C"
+
+#
+# pattern to ignore from 'zpool list'.
+#
+export NO_POOLS="no pools available"
+
+# pattern to ignore from 'zfs list'.
+export NO_DATASETS="no datasets available"
+
+export TEST_BASE_DIR="/var/tmp"
+
+# Default to compression ON
+export COMPRESSION_PROP=on
+
+# Default to using the checksum
+export CHECKSUM_PROP=on
+
+# some common variables used by test scripts :
+export FIO_SCRIPTS=$STF_SUITE/tests/perf/fio
+export PERF_SCRIPTS=$STF_SUITE/tests/perf/scripts
+
+# some test pool names
+export TESTPOOL=testpool
+export TESTPOOL1=testpool1
+export TESTPOOL2=testpool2
+export TESTPOOL3=testpool3
+export PERFPOOL=perfpool
+
+# some test file system names
+export TESTFS=testfs
+export TESTFS1=testfs1
+export TESTFS2=testfs2
+export TESTFS3=testfs3
+
+# some test directory names
+export TESTDIR=${TEST_BASE_DIR%%/}/testdir
+export TESTDIR0=${TEST_BASE_DIR%%/}/testdir0
+export TESTDIR1=${TEST_BASE_DIR%%/}/testdir1
+export TESTDIR2=${TEST_BASE_DIR%%/}/testdir2
+
+# some test sub file system names
+export TESTSUBFS=subfs
+export TESTSUBFS1=subfs1
+export TESTSUBFS2=subfs2
+
+# some temp files
+export TEMPFILE=${TEST_BASE_DIR%%/}/tempfile$$
+export TEMPFILE0=${TEST_BASE_DIR%%/}/tempfile0$$
+export TEMPFILE1=${TEST_BASE_DIR%%/}/tempfile1$$
+export TEMPFILE2=${TEST_BASE_DIR%%/}/tempfile2$$
+
+export ZFSROOT=
+
+export TESTSNAP=testsnap
+export TESTSNAP1=testsnap1
+export TESTSNAP2=testsnap2
+export TESTCLONE=testclone
+export TESTCLONE1=testclone1
+export TESTCLONE2=testclone2
+export TESTCLCT=testclct
+export TESTCTR=testctr
+export TESTCTR1=testctr1
+export TESTCTR2=testctr2
+export TESTVOL=testvol
+export TESTVOL1=testvol1
+export TESTVOL2=testvol2
+export TESTFILE0=testfile0
+export TESTFILE1=testfile1
+export TESTFILE2=testfile2
+export TESTBKMARK=testbkmark
+
+export LONGPNAME="poolname50charslong_012345678901234567890123456789"
+export LONGFSNAME="fsysname50charslong_012345678901234567890123456789"
+export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP"
+export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP"
+
+export VOLSIZE=150m
+export BIGVOLSIZE=1eb
+
+# Default to limit disks to be checked
+export MAX_FINDDISKSNUM=6
+
+# Default minimum size for file based vdevs in the test suite
+export MINVDEVSIZE=$((256 * 1024 * 1024))
+
+# Minimum vdev size possible as defined in the OS
+export SPA_MINDEVSIZE=$((64 * 1024 * 1024))
+
+# For iscsi target support
+export ISCSITGTFILE=/tmp/iscsitgt_file
+export ISCSITGT_FMRI=svc:/system/iscsitgt:default
+if ! is_linux; then
+export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \
+    '{print $3}')
+fi
+
+#
+# finally, if we're running in a local zone
+# we take some additional actions
+if ! is_global_zone; then
+       reexport_pool
+fi
+
+export ZFS_VERSION=5
+export ZFS_ALL_VERSIONS="1 2 3 4 5"
+
+for i in $ZFS_ALL_VERSIONS; do
+       eval 'export ZFS_VERSION_$i="v${i}-fs"'
+done
+
+export MAX_PARTITIONS=8
+
+if is_linux; then
+       unpack_opts="--sparse -xf"
+       pack_opts="--sparse -cf"
+       verbose=" -v"
+       unpack_preserve=" -xpf"
+       pack_preserve=" -cpf"
+
+       ZVOL_DEVDIR="/dev/zvol"
+       ZVOL_RDEVDIR="/dev/zvol"
+       DEV_RDSKDIR="/dev"
+       DEV_MPATHDIR="/dev/mapper"
+
+       ZEDLET_DIR="/var/tmp/zed"
+       VDEVID_CONF="$ZEDLET_DIR/vdev_id.conf"
+       VDEVID_CONF_ETC="/etc/zfs/vdev_id.conf"
+
+
+       NEWFS_DEFAULT_FS="ext2"
+else
+       unpack_opts="xv"
+       pack_opts="cf"
+       verbose="v"
+       unpack_preserve="xpf"
+       pack_preserve="cpf"
+
+       ZVOL_DEVDIR="/dev/zvol/dsk"
+       ZVOL_RDEVDIR="/dev/zvol/rdsk"
+       DEV_DSKDIR="/dev/dsk"
+       DEV_RDSKDIR="/dev/rdsk"
+
+       NEWFS_DEFAULT_FS="ufs"
+fi
+export unpack_opts pack_opts verbose unpack_preserve pack_preserve \
+       ZVOL_DEVDIR ZVOL_RDEVDIR NEWFS_DEFAULT_FS DEV_RDSKDIR DEV_MPATHDIR \
+       ZEDLET_DIR VDEVID_CONF VDEVID_CONF_ETC
index 56f765d204c245bad0bff735ddd6814b1ffceaf0..df6b94f5802a453f156156c34241e99b6ffaa31b 100644 (file)
@@ -3280,11 +3280,16 @@ function zed_setup
 
        # Setup minimal ZED configuration.  Individual test cases should
        # add additional ZEDLETs as needed for their specific test.
-       log_must cp ${ZEDLETDIR}/zed.rc $ZEDLET_DIR
-       log_must cp ${ZEDLETDIR}/zed-functions.sh $ZEDLET_DIR
-       log_must cp ${ZEDLETDIR}/all-syslog.sh $ZEDLET_DIR
+       log_must cp ${ZEDLET_ETC_DIR}/zed.rc $ZEDLET_DIR
+       log_must cp ${ZEDLET_ETC_DIR}/zed-functions.sh $ZEDLET_DIR
 
-       log_must zpool events -c
+       # Customize the zed.rc file to enable the full debug log.
+       log_must sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
+       echo "ZED_DEBUG_LOG=$ZEDLET_DIR/zed.debug.log" >>$ZEDLET_DIR/zed.rc
+
+       log_must cp ${ZEDLET_LIBEXEC_DIR}/all-syslog.sh $ZEDLET_DIR
+       log_must cp ${ZEDLET_LIBEXEC_DIR}/all-debug.sh $ZEDLET_DIR
+       log_must touch $ZEDLET_DIR/zed.debug.log
 }
 
 #
@@ -3299,8 +3304,10 @@ function zed_cleanup
        log_must rm -f ${ZEDLET_DIR}/zed.rc
        log_must rm -f ${ZEDLET_DIR}/zed-functions.sh
        log_must rm -f ${ZEDLET_DIR}/all-syslog.sh
+       log_must rm -f ${ZEDLET_DIR}/all-debug.sh
        log_must rm -f ${ZEDLET_DIR}/zed.pid
        log_must rm -f ${ZEDLET_DIR}/zedlog
+       log_must rm -f ${ZEDLET_DIR}/zed.debug.log
        log_must rm -f ${ZEDLET_DIR}/state
        log_must rm -f $VDEVID_CONF_ETC
        log_must rm -f $VDEVID_CONF
@@ -3332,6 +3339,8 @@ function zed_start
        # output to zedlog
        log_must eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
            "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
+
+       return 0
 }
 
 #
@@ -3343,10 +3352,13 @@ function zed_stop
                return
        fi
 
+       log_note "Stopping ZED"
        if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
                zedpid=$(cat ${ZEDLET_DIR}/zed.pid)
                log_must kill $zedpid
        fi
+
+       return 0
 }
 
 #
index a2d78f52082129848d867e000b220d9a3e5ad489..1c3f4b1a877b5131af32f12c761a60ab8e5f8e21 100644 (file)
@@ -14,6 +14,7 @@ SUBDIRS = \
        ctime \
        delegate \
        devices \
+       events \
        exec \
        fault \
        features \
index cf79591610da45b7817a9bc2660c2da49c342cb0..c5e0c6e474a5fa9abd1b74414f85d22135530f18 100755 (executable)
@@ -53,10 +53,10 @@ else
        testpool="${TESTPOOL%%/*}"
 fi
 
-files="$(ls $ZPOOLSCRIPTDIR)"
+files="$(ls $ZPOOL_SCRIPT_DIR)"
 scripts=""
 for i in $files ; do
-       if [ ! -x "$ZPOOLSCRIPTDIR/$i" ] ; then
+       if [ ! -x "$ZPOOL_SCRIPT_DIR/$i" ] ; then
                # Skip non-executables
                continue
        fi
index 0528e0c0a8eaaa28ca49b8ab3ff9c9dd8acff5fd..1ae91c1a84344c37aa62ea7666864672e0cabac5 100755 (executable)
@@ -53,10 +53,10 @@ else
        testpool=${TESTPOOL%%/*}
 fi
 
-files="$(ls $ZPOOLSCRIPTDIR)"
+files="$(ls $ZPOOL_SCRIPT_DIR)"
 scripts=""
 for i in $files ; do
-       if [ ! -x "$ZPOOLSCRIPTDIR/$i" ] ; then
+       if [ ! -x "$ZPOOL_SCRIPT_DIR/$i" ] ; then
                # Skip non-executables
                continue
        fi
diff --git a/tests/zfs-tests/tests/functional/events/Makefile.am b/tests/zfs-tests/tests/functional/events/Makefile.am
new file mode 100644 (file)
index 0000000..7813c18
--- /dev/null
@@ -0,0 +1,8 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/events
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       events.cfg \
+       events_common.kshlib \
+       events_001_pos.ksh \
+       events_002_pos.ksh
diff --git a/tests/zfs-tests/tests/functional/events/cleanup.ksh b/tests/zfs-tests/tests/functional/events/cleanup.ksh
new file mode 100755 (executable)
index 0000000..bc536e2
--- /dev/null
@@ -0,0 +1,31 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+zed_cleanup
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/events/events.cfg b/tests/zfs-tests/tests/functional/events/events.cfg
new file mode 100644 (file)
index 0000000..3fba819
--- /dev/null
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+export MPOOL=mpool.$$
+
+VDEV1=$TEST_BASE_DIR/vdev1
+VDEV2=$TEST_BASE_DIR/vdev2
+VDEV3=$TEST_BASE_DIR/vdev3
+VDEV4=$TEST_BASE_DIR/vdev4
+
+export TMP_EVENTS=/tmp/tmp_events.$$
+export TMP_EVENTS_FULL=/tmp/tmp_events_full.$$
+export TMP_EVENT_FULL=/tmp/tmp_event_full.$$
+export TMP_EVENTS_ZED=/tmp/tmp_events_zed.$$
+export TMP_EVENT_ZED=/tmp/tmp_event_zed.$$
diff --git a/tests/zfs-tests/tests/functional/events/events_001_pos.ksh b/tests/zfs-tests/tests/functional/events/events_001_pos.ksh
new file mode 100755 (executable)
index 0000000..aaf2ad8
--- /dev/null
@@ -0,0 +1,134 @@
+#!/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 zed_start
+
+# Create a mirrored pool with two devices.
+run_and_verify -p "$MPOOL" \
+    -e "sysevent.fs.zfs.config_sync" \
+    -e "sysevent.fs.zfs.pool_create" \
+    "zpool create $MPOOL mirror $VDEV1 $VDEV2"
+
+# 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" \
+    "zpool online $MPOOL $VDEV1"
+
+# Attach then detach a device from the mirror.
+run_and_verify -p "$MPOOL" \
+     -e "sysevent.fs.zfs.vdev_attach" \
+    "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.resilver_finish" \
+    -e "sysevent.fs.zfs.config_sync" \
+    "zpool replace -f $MPOOL $VDEV1 $VDEV4"
+
+# Scrub a pool.
+run_and_verify -p "$MPOOL" \
+    -e "sysevent.fs.zfs.scrub_start" \
+    -e "sysevent.fs.zfs.scrub_finish" \
+    "zpool scrub $MPOOL"
+
+# Export then import a pool (may change to a pool_export event)
+run_and_verify -p "$MPOOL" \
+    -e "sysevent.fs.zfs.pool_destroy" \
+    -e "sysevent.fs.zfs.config_sync" \
+    "zpool export $MPOOL"
+run_and_verify -p "$MPOOL" \
+    -e "sysevent.fs.zfs.pool_import" \
+    -e "sysevent.fs.zfs.config_sync" \
+    "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"
diff --git a/tests/zfs-tests/tests/functional/events/events_002_pos.ksh b/tests/zfs-tests/tests/functional/events/events_002_pos.ksh
new file mode 100755 (executable)
index 0000000..7769b45
--- /dev/null
@@ -0,0 +1,102 @@
+#!/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 ZED handles missed events from a pool when starting.
+#
+# STRATEGY:
+# 1. Create a pool and generate some events.
+# 2. Start the ZED and verify it handles missed events.
+# 3. Stop the ZED
+# 4. Generate additional events.
+# 5. Start the ZED and verify it only handles the new missed events.
+
+. $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; do
+               [[ -f $file ]] && rm -f $file
+       done
+
+       log_must rm -f $TMP_EVENTS_ZED $TMP_EVENTS_ZED
+       log_must rm -f $ZEDLET_DIR/zed.debug.log.old
+       log_must zed_stop
+}
+
+log_assert "Verify ZED handles missed events on when starting"
+log_onexit cleanup
+
+log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
+
+# 1. Create a pool and generate some events.
+log_must cp -f $ZEDLET_DIR/zed.debug.log $ZEDLET_DIR/zed.debug.log.old
+log_must zpool create $MPOOL mirror $VDEV1 $VDEV2
+
+# 2. Start the ZED and verify it handles missed events.
+log_must zed_start
+log_must sleep 1
+diff $ZEDLET_DIR/zed.debug.log.old $ZEDLET_DIR/zed.debug.log | \
+    grep "^> " | sed 's/^> //g' >$TMP_EVENTS_ZED
+log_must awk -v event="sysevent.fs.zfs.pool_create" \
+    'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
+    $TMP_EVENTS_ZED >$TMP_EVENT_ZED
+log_must grep -q "^ZEVENT_POOL=$MPOOL" $TMP_EVENT_ZED
+
+# 3. Stop the ZED
+zed_stop
+
+# 4. Generate additional events.
+log_must cp -f $ZEDLET_DIR/zed.debug.log $ZEDLET_DIR/zed.debug.log.old
+log_must zpool offline $MPOOL $VDEV1
+log_must zpool online $MPOOL $VDEV1
+log_must zpool scrub $MPOOL
+
+# Wait for the scrub to wrap, or is_healthy will be wrong.
+while ! is_pool_scrubbed $MPOOL; do
+       sleep 1
+done
+
+# 5. Start the ZED and verify it only handled the new missed events.
+log_must zed_start
+log_must sleep 3
+diff $ZEDLET_DIR/zed.debug.log.old $ZEDLET_DIR/zed.debug.log | \
+    grep "^> " | sed 's/^> //g' >$TMP_EVENTS_ZED
+
+log_mustnot grep -q "sysevent.fs.zfs.pool_create" $TMP_EVENTS_ZED
+log_must grep -q "sysevent.fs.zfs.vdev_online" $TMP_EVENTS_ZED
+log_must grep -q "sysevent.fs.zfs.resilver_start" $TMP_EVENTS_ZED
+log_must grep -q "sysevent.fs.zfs.resilver_finish" $TMP_EVENTS_ZED
+
+log_pass "Verify ZED handles missed events on when starting"
diff --git a/tests/zfs-tests/tests/functional/events/events_common.kshlib b/tests/zfs-tests/tests/functional/events/events_common.kshlib
new file mode 100755 (executable)
index 0000000..afefef1
--- /dev/null
@@ -0,0 +1,98 @@
+#
+# 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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+. $STF_SUITE/tests/functional/events/events.cfg
+
+function run_and_verify
+{
+       typeset event pool
+       set -A events
+
+       while getopts "e:p:z:" opt; do
+               case $opt in
+               e)
+                       events[${#events[*]}+1]=$OPTARG
+                       ;;
+               p)
+                       pool=$OPTARG
+                       ;;
+               z)
+                       zedlog=$OPTARG
+                       ;;
+               esac
+       done
+       shift $(($OPTIND - 1))
+
+       pool=${pool:-$TESTPOOL}
+       zedlog=${zedlog:-$ZEDLET_DIR/zed.debug.log}
+       fullcmd="$1"
+       cmd=$(echo $fullcmd | awk '{print $1}')
+       subcmd=$(echo $fullcmd | awk '{print $2}')
+
+       # If we aren't running zpool or zfs, something is wrong
+       [[ $cmd == "zpool" || $cmd == "zfs" ]] || \
+           log_fail "run_and_verify called with \"$cmd ($fullcmd)\""
+
+       # Run the command as provided and collect the new events.
+       log_must zpool events -c
+       if [[ -f $zedlog ]]; then
+               cp -f $zedlog $zedlog.old
+       fi
+
+       log_must eval "$fullcmd"
+
+       log_must zpool events > $TMP_EVENTS 2>/dev/null
+       log_must zpool events -v > $TMP_EVENTS_FULL 2>/dev/null
+       if [[ -f $zedlog ]]; then
+               sleep 1 # Brief delay for the ZED to handle the event.
+               diff $zedlog.old $zedlog | grep "^> " | sed 's/^> //g' \
+                   >$TMP_EVENTS_ZED
+       fi
+
+       # Verify all the expected events appear in the log.
+       for event in ${events[*]}; do
+
+               # Verify the event is in in the short output.
+               log_must grep -q "$event" $TMP_EVENTS
+
+               # Verify the event is in the verbose output with pool name.
+               log_must awk -v event="$event" \
+                   'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
+                   $TMP_EVENTS_FULL >$TMP_EVENT_FULL
+               log_must grep -q "pool = \"$pool\"" $TMP_EVENT_FULL
+
+               # Verify the event was received by the ZED and logged.
+               log_must awk -v event="$event" \
+                   'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
+                   $TMP_EVENTS_ZED >$TMP_EVENT_ZED
+               log_must grep -q "^ZEVENT_POOL=$pool" $TMP_EVENT_ZED
+
+       done
+
+       log_must rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENT_FULL \
+           $TMP_EVENTS_ZED $TMP_EVENT_ZED $zedlog.old
+}
diff --git a/tests/zfs-tests/tests/functional/events/setup.ksh b/tests/zfs-tests/tests/functional/events/setup.ksh
new file mode 100755 (executable)
index 0000000..7113c1f
--- /dev/null
@@ -0,0 +1,33 @@
+#!/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.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+zed_setup
+
+default_setup $DISK
index dffab23efa97aa1a6f02f72c60a9110303ad6e3d..593b4d00e023a91b474f14b9b0329d2ef539ac92 100644 (file)
@@ -20,8 +20,10 @@ export ETCDIR=${SRCDIR}/etc
 export TESTSDIR=${SRCDIR}/tests
 export RUNFILEDIR=${TESTSDIR}/runfiles
 export UDEVRULEDIR=${BUILDDIR}/udev/rules.d
-export ZEDLETDIR=${SRCDIR}/cmd/zed/zed.d
-export ZPOOLSCRIPTDIR=${SRCDIR}/cmd/zpool/zpool.d
+
+export ZEDLET_ETC_DIR=${SRCDIR}/cmd/zed/zed.d
+export ZEDLET_LIBEXEC_DIR=${SRCDIR}/cmd/zed/zed.d
+export ZPOOL_SCRIPT_DIR=${SRCDIR}/cmd/zpool/zpool.d
 
 export ZDB=${CMDDIR}/zdb/zdb
 export ZFS=${CMDDIR}/zfs/zfs