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 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP 31 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP1 32 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP2 33 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP3 34} 35 36log_onexit cleanup 37 38# 0 snapshots handled correctly 39log_must_program $TESTPOOL - <<-EOF 40 n = 0 41 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 42 zfs.debug("ERROR: found snapshot " .. s) 43 n = n + 1 44 end 45 assert(n == 0) 46 return 0 47EOF 48 49# Take a snapshot, make sure it appears 50create_snapshot $TESTPOOL/$TESTFS $TESTSNAP 51 52log_must_program $TESTPOOL - <<-EOF 53 n = 0 54 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 55 assert(s == "$TESTPOOL/$TESTFS@$TESTSNAP") 56 n = n + 1 57 end 58 assert(n == 1) 59 return 0 60EOF 61 62TESTSNAP1=${TESTSNAP}-1 63TESTSNAP2=${TESTSNAP}-2 64TESTSNAP3=${TESTSNAP}-3 65create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 66create_snapshot $TESTPOOL/$TESTFS $TESTSNAP2 67create_snapshot $TESTPOOL/$TESTFS $TESTSNAP3 68 69# All snapshots appear exactly once 70log_must_program $TESTPOOL - <<-EOF 71 a = {} 72 a["$TESTPOOL/$TESTFS@$TESTSNAP"] = false 73 a["$TESTPOOL/$TESTFS@$TESTSNAP1"] = false 74 a["$TESTPOOL/$TESTFS@$TESTSNAP2"] = false 75 a["$TESTPOOL/$TESTFS@$TESTSNAP3"] = false 76 n = 0 77 for s in zfs.list.snapshots("$TESTPOOL/$TESTFS") do 78 assert(not a[s]) 79 a[s] = true 80 n = n + 1 81 end 82 assert(n == 4) 83 assert(a["$TESTPOOL/$TESTFS@$TESTSNAP"] and 84 a["$TESTPOOL/$TESTFS@$TESTSNAP1"] and 85 a["$TESTPOOL/$TESTFS@$TESTSNAP2"] and 86 a["$TESTPOOL/$TESTFS@$TESTSNAP3"]) 87 return 0 88EOF 89 90# Bad input 91log_mustnot_program $TESTPOOL - <<-EOF 92 zfs.list.snapshots("$TESTPOOL/not-a-fs") 93 return 0 94EOF 95 96log_mustnot_program $TESTPOOL - <<-EOF 97 zfs.list.snapshots("not-a-pool/$TESTFS") 98 return 0 99EOF 100 101# Can't look in a different pool than the one specified on command line 102log_mustnot_program $TESTPOOL - <<-EOF 103 zfs.list.snapshots("rpool") 104 return 0 105EOF 106 107log_mustnot_program $TESTPOOL - <<-EOF 108 zfs.list.snapshots("$TESTPOOL/${TESTFS}@$TESTSNAP") 109 return 0 110EOF 111 112log_pass "Listing zfs snapshots should work correctly." 113