1#!/bin/ksh -p 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright (c) 2016 by Delphix. All rights reserved. 15# 16 17. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib 18 19# 20# DESCRIPTION: 21# Listing zfs snapshots should work correctly. 22# 23 24verify_runnable "global" 25 26log_assert "Listing zfs snapshots should work correctly." 27 28function cleanup 29{ 30 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ 31 log_must zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP 32 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP1 && \ 33 log_must zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP1 34 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP2 && \ 35 log_must zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP2 36 datasetexists $TESTPOOL/$TESTFS@$TESTSNAP3 && \ 37 log_must zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP3 38} 39 40log_onexit cleanup 41 42# 0 snapshots handled correctly 43log_must_program $TESTPOOL - <<-EOF 44 n = 0 45 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 46 zfs.debug("ERROR: found snapshot " .. s) 47 n = n + 1 48 end 49 assert(n == 0) 50 return 0 51EOF 52 53# Take a snapshot, make sure it appears 54create_snapshot $TESTPOOL/$TESTFS $TESTSNAP 55 56log_must_program $TESTPOOL - <<-EOF 57 n = 0 58 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 59 assert(s == "$TESTPOOL/$TESTFS@$TESTSNAP") 60 n = n + 1 61 end 62 assert(n == 1) 63 return 0 64EOF 65 66TESTSNAP1=${TESTSNAP}-1 67TESTSNAP2=${TESTSNAP}-2 68TESTSNAP3=${TESTSNAP}-3 69create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 70create_snapshot $TESTPOOL/$TESTFS $TESTSNAP2 71create_snapshot $TESTPOOL/$TESTFS $TESTSNAP3 72 73# All snapshots appear exactly once 74log_must_program $TESTPOOL - <<-EOF 75 a = {} 76 a["$TESTPOOL/$TESTFS@$TESTSNAP"] = false 77 a["$TESTPOOL/$TESTFS@$TESTSNAP1"] = false 78 a["$TESTPOOL/$TESTFS@$TESTSNAP2"] = false 79 a["$TESTPOOL/$TESTFS@$TESTSNAP3"] = false 80 n = 0 81 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 82 assert(not a[s]) 83 a[s] = true 84 n = n + 1 85 end 86 assert(n == 4) 87 assert(a["$TESTPOOL/$TESTFS@$TESTSNAP"] and 88 a["$TESTPOOL/$TESTFS@$TESTSNAP1"] and 89 a["$TESTPOOL/$TESTFS@$TESTSNAP2"] and 90 a["$TESTPOOL/$TESTFS@$TESTSNAP3"]) 91 return 0 92EOF 93 94# Bad input 95log_mustnot_program $TESTPOOL - <<-EOF 96 zfs.list.snapshots("$TESTPOOL/not-a-fs") 97 return 0 98EOF 99 100log_mustnot_program $TESTPOOL - <<-EOF 101 zfs.list.snapshots("not-a-pool/$TESTFS") 102 return 0 103EOF 104 105# Can't look in a different pool than the one specified on command line 106log_mustnot_program $TESTPOOL - <<-EOF 107 zfs.list.snapshots("rpool") 108 return 0 109EOF 110 111log_mustnot_program $TESTPOOL - <<-EOF 112 zfs.list.snapshots("$TESTPOOL/${TESTFS}@$TESTSNAP") 113 return 0 114EOF 115 116log_pass "Listing zfs snapshots should work correctly." 117