diff options
Diffstat (limited to 'tests/zfs-tests/tests/functional/cachefile')
9 files changed, 571 insertions, 0 deletions
diff --git a/tests/zfs-tests/tests/functional/cachefile/Makefile.am b/tests/zfs-tests/tests/functional/cachefile/Makefile.am new file mode 100644 index 000000000000..53d8c8c6c9d5 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/Makefile.am @@ -0,0 +1,12 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cachefile +dist_pkgdata_SCRIPTS = \ + cleanup.ksh \ + setup.ksh \ + cachefile_001_pos.ksh \ + cachefile_002_pos.ksh \ + cachefile_003_pos.ksh \ + cachefile_004_pos.ksh + +dist_pkgdata_DATA = \ + cachefile.cfg \ + cachefile.kshlib diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile.cfg b/tests/zfs-tests/tests/functional/cachefile/cachefile.cfg new file mode 100644 index 000000000000..d93ec3ed6f3b --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile.cfg @@ -0,0 +1,37 @@ +# +# 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) 2013 by Delphix. All rights reserved. +# + +export CPATH="/etc/zfs/zpool.cache" +export CPATH1=$TEST_BASE_DIR/cachefile.1.$$ +export CPATH2=$TEST_BASE_DIR/cachefile.2.$$ + +export DISKSARRAY=$DISKS +export DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}') +set_device_dir diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib b/tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib new file mode 100644 index 000000000000..7723e3083f1d --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile.kshlib @@ -0,0 +1,46 @@ +# +# 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) 2013, 2016 by Delphix. All rights reserved. +# + +# +# A function to determine if a given pool name has an entry in cachefile +# returns 1 if the pool is not in the cache, 0 otherwise. +function pool_in_cache { + + # checking for the pool name in the strings output of + # the given cachefile, default is /etc/zfs/zpool.cache + typeset cachefile=${2:-$CPATH} + + RESULT=$(strings $cachefile | grep -w $1) + if [ -z "$RESULT" ] + then + return 1 + fi + return 0 +} diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh new file mode 100755 index 000000000000..f164a1fad32f --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile_001_pos.ksh @@ -0,0 +1,94 @@ +#!/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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cachefile/cachefile.cfg +. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib + +# +# DESCRIPTION: +# +# Creating a pool with "cachefile" set doesn't update zpool.cache +# +# STRATEGY: +# 1. Create a pool with the cachefile property set +# 2. Verify that the pool doesn't have an entry in zpool.cache +# 3. Verify the cachefile property is set +# 4. Create a pool without the cachefile property +# 5. Verify the cachefile property isn't set +# 6. Verify that zpool.cache contains an entry for the pool +# + +function cleanup +{ + typeset file + + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must rm $file + fi + done +} + +verify_runnable "global" + +log_assert "Creating a pool with \"cachefile\" set doesn't update zpool.cache" +log_onexit cleanup + +set -A opts "none" "false" "none" \ + "$CPATH" "true" "-" \ + "$CPATH1" "true" "$CPATH1" \ + "$CPATH2" "true" "$CPATH2" + +typeset -i i=0 + +while (( i < ${#opts[*]} )); do + log_must zpool create -o cachefile=${opts[i]} $TESTPOOL $DISKS + case ${opts[((i+1))]} in + false) log_mustnot pool_in_cache $TESTPOOL + ;; + true) log_must pool_in_cache $TESTPOOL ${opts[i]} + ;; + esac + + PROP=$(get_pool_prop cachefile $TESTPOOL) + if [[ $PROP != ${opts[((i+2))]} ]]; then + log_fail "cachefile property not set as expected. " \ + "Expect: ${opts[((i+2))]}, Current: $PROP" + fi + log_must zpool destroy $TESTPOOL + (( i = i + 3 )) +done + +log_pass "Creating a pool with \"cachefile\" set doesn't update zpool.cache" diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh new file mode 100755 index 000000000000..9268f9786355 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile_002_pos.ksh @@ -0,0 +1,82 @@ +#!/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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cachefile/cachefile.cfg +. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib + +# +# DESCRIPTION: +# +# Importing a pool with "cachefile" set doesn't update zpool.cache +# +# STRATEGY: +# 1. Create a pool with the cachefile property set +# 2. Verify the pool doesn't have an entry in zpool.cache +# 3. Export the pool +# 4. Import the pool +# 5. Verify the pool does have an entry in zpool.cache +# 6. Export the pool +# 7. Import the pool -o cachefile=<cachefile> +# 8. Verify the pool doesn't have an entry in zpool.cache +# + +function cleanup +{ + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi +} + +verify_runnable "global" + +log_assert "Importing a pool with \"cachefile\" set doesn't update zpool.cache" +log_onexit cleanup + +log_must zpool create -o cachefile=none $TESTPOOL $DISKS +typeset DEVICEDIR=$(get_device_dir $DISKS) +log_mustnot pool_in_cache $TESTPOOL + +log_must zpool export $TESTPOOL +log_must zpool import -d $DEVICEDIR $TESTPOOL +log_must pool_in_cache $TESTPOOL + +log_must zpool export $TESTPOOL +log_must zpool import -o cachefile=none -d $DEVICEDIR $TESTPOOL +log_mustnot pool_in_cache $TESTPOOL + +log_must zpool export $TESTPOOL +log_must zpool import -o cachefile=$CPATH -d $DEVICEDIR $TESTPOOL +log_must pool_in_cache $TESTPOOL + +log_must zpool destroy $TESTPOOL + +log_pass "Importing a pool with \"cachefile\" set doesn't update zpool.cache" diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh new file mode 100755 index 000000000000..a5f427cb4135 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile_003_pos.ksh @@ -0,0 +1,100 @@ +#!/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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cachefile/cachefile.cfg +. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib + +# +# DESCRIPTION: +# +# Setting altroot=<path> and cachefile=$CPATH for zpool create is succeed +# +# STRATEGY: +# 1. Attempt to create a pool with -o altroot=<path> -o cachefile=<value> +# 2. Verify the command succeed +# +# + +TESTDIR=/altdir.$$ + +function cleanup +{ + typeset file + + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must rm $file + fi + done + + if [ -d $TESTDIR ] + then + rmdir $TESTDIR + fi +} + +verify_runnable "global" + +log_assert "Setting altroot=path and cachefile=$CPATH for zpool create succeed." +log_onexit cleanup + +typeset -i i=0 + +set -A opts "none" "none" \ + "$CPATH" "-" \ + "$CPATH1" "$CPATH1" \ + "$CPATH2" "$CPATH2" + + +while (( i < ${#opts[*]} )); do + log_must zpool create -o altroot=$TESTDIR -o cachefile=${opts[i]} \ + $TESTPOOL $DISKS + if [[ ${opts[i]} != none ]]; then + log_must pool_in_cache $TESTPOOL ${opts[i]} + else + log_mustnot pool_in_cache $TESTPOOL + fi + + PROP=$(get_pool_prop cachefile $TESTPOOL) + if [[ $PROP != ${opts[((i+1))]} ]]; then + log_fail "cachefile property not set as expected. " \ + "Expect: ${opts[((i+1))]}, Current: $PROP" + fi + log_must zpool destroy $TESTPOOL + (( i = i + 2 )) +done + +log_pass "Setting altroot=path and cachefile=$CPATH for zpool create succeed." diff --git a/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh b/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh new file mode 100755 index 000000000000..841b141e16fc --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cachefile_004_pos.ksh @@ -0,0 +1,124 @@ +#!/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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +# +# Copyright (c) 2013, 2016 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cachefile/cachefile.cfg +. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib + +# +# DESCRIPTION: +# Verify set, export and destroy when cachefile is set on pool. +# +# STRATEGY: +# 1. Create two pools with one same cachefile1. +# 2. Set cachefile of the two pools to another same cachefile2. +# 3. Verify cachefile1 does not exist. +# 4. Export the two pools. +# 5. Verify cachefile2 not exist. +# 6. Import the two pools and set cachefile to cachefile2. +# 7. Destroy the two pools. +# 8. Verify cachefile2 not exist. +# + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 + + mntpnt=$(get_prop mountpoint $TESTPOOL) + typeset -i i=0 + while ((i < 2)); do + if [[ -e $mntpnt/vdev$i ]]; then + log_must rm -f $mntpnt/vdev$i + fi + ((i += 1)) + done + + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must rm $file + fi + done +} + + +log_assert "Verify set, export and destroy when cachefile is set on pool." +log_onexit cleanup + +log_must zpool create $TESTPOOL $DISKS + +mntpnt=$(get_prop mountpoint $TESTPOOL) +typeset -i i=0 +while ((i < 2)); do + log_must mkfile $MINVDEVSIZE $mntpnt/vdev$i + eval vdev$i=$mntpnt/vdev$i + ((i += 1)) +done + +log_must zpool create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0 +log_must pool_in_cache $TESTPOOL1 $CPATH1 +log_must zpool create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1 +log_must pool_in_cache $TESTPOOL2 $CPATH1 + +log_must zpool set cachefile=$CPATH2 $TESTPOOL1 +log_must pool_in_cache $TESTPOOL1 $CPATH2 +log_must zpool set cachefile=$CPATH2 $TESTPOOL2 +log_must pool_in_cache $TESTPOOL2 $CPATH2 +if [[ -s $CPATH1 ]]; then + log_fail "Verify set when cachefile is set on pool." +fi + +log_must zpool export $TESTPOOL1 +log_must zpool export $TESTPOOL2 +if [[ -s $CPATH2 ]]; then + log_fail "Verify export when cachefile is set on pool." +fi + +log_must zpool import -d $mntpnt $TESTPOOL1 +log_must zpool set cachefile=$CPATH2 $TESTPOOL1 +log_must pool_in_cache $TESTPOOL1 $CPATH2 +log_must zpool import -d $mntpnt $TESTPOOL2 +log_must zpool set cachefile=$CPATH2 $TESTPOOL2 +log_must pool_in_cache $TESTPOOL2 $CPATH2 + +log_must zpool destroy $TESTPOOL1 +log_must zpool destroy $TESTPOOL2 +if [[ -s $CPATH2 ]]; then + log_fail "Verify destroy when cachefile is set on pool." +fi + +log_pass "Verify set, export and destroy when cachefile is set on pool." diff --git a/tests/zfs-tests/tests/functional/cachefile/cleanup.ksh b/tests/zfs-tests/tests/functional/cachefile/cleanup.ksh new file mode 100755 index 000000000000..79cd6e9f908e --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/cleanup.ksh @@ -0,0 +1,30 @@ +#!/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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/tests/zfs-tests/tests/functional/cachefile/setup.ksh b/tests/zfs-tests/tests/functional/cachefile/setup.ksh new file mode 100755 index 000000000000..47c7893bfdd6 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cachefile/setup.ksh @@ -0,0 +1,46 @@ +#!/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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cachefile/cachefile.cfg +. $STF_SUITE/tests/functional/cachefile/cachefile.kshlib + +for pool in "$TESTPOOL" "$TESTPOOL2" "$TESTPOOL3" ; do + if poolexists $pool ; then + destroy_pool $pool + fi +done + +for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must rm $file + fi +done + +if pool_in_cache $TESTPOOL; then + log_unsupported "Skipping test group due to existing pool" +fi |