1#!/usr/local/bin/ksh93 -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# $FreeBSD$ 24 25# 26# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_snapshot_002_neg.ksh 1.2 07/01/09 SMI" 30# 31. $STF_SUITE/include/libtest.kshlib 32 33################################################################################ 34# 35# __stc_assertion_start 36# 37# ID: zfs_snapshot_002_neg 38# 39# DESCRIPTION: 40# "zfs snapshot -r" fails with invalid arguments or scenarios. 41# The invalid scenarios may include: 42# (1) The child filesystem already has snapshot with the same name 43# (2) The child volume already has snapshot with the same name 44# 45# STRATEGY: 46# 1. Create an array of invalid arguments 47# 2. Execute 'zfs snapshot -r' with each argument in the array, 48# 3. Verify an error is returned. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2006-06-19) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "both" 61 62function cleanup 63{ 64 typeset snap 65 66 for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \ 67 $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP; 68 do 69 snapexists $snap && \ 70 log_must $ZFS destroy $snap 71 done 72 73 datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \ 74 log_must $ZFS destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL 75 76} 77 78log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. " 79log_onexit cleanup 80 81set -A args "" \ 82 "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \ 83 "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \ 84 "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \ 85 "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP" 86 87# setup preparations 88log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 89 90# testing 91typeset -i i=0 92while (( i < ${#args[*]} )); do 93 log_mustnot $ZFS snapshot -r ${args[i]} 94 95 ((i = i + 1)) 96done 97 98# Testing the invalid senario: the child volume already has an 99# identical name snapshot, zfs snapshot -r should fail when 100# creating snapshot with -r for the parent 101log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP 102if is_global_zone; then 103 log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL 104else 105 log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTVOL 106fi 107log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP 108 109log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP 110 111log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected." 112