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) 2017 by Delphix. All rights reserved. 15# 16 17. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib 18 19# 20# DESCRIPTION: 21# Listing zfs user properties should work correctly. 22# 23# Note, that this file tests both zfs.list.user_properties 24# and it's alias zfs.list.properties. 25# 26 27verify_runnable "global" 28 29TESTPROP="org.openzfs:test_property" 30TESTPROP1=$TESTPROP-1 31TESTPROP2=$TESTPROP-2 32TESTPROP3=$TESTPROP-3 33TESTPROP4=$TESTPROP-4 34 35TESTVAL="true" 36TESTVAL1="busy" 37TESTVAL2="9223372036854775808" 38TESTVAL3="801f2266-3715-41f4-9080-3d5e913b0f15" 39TESTVAL4="TOZwOfACvQtmDyiq68elB3a3g9YYyxBjSnLtN3ZyQYNOAKykzIE2khKKOBncJiDx" 40 41 42# 0 properties handled correctly 43log_must_program $TESTPOOL - <<-EOF 44 n = 0 45 for p in zfs.list.user_properties("$TESTPOOL/$TESTFS") do 46 n = n + 1 47 end 48 assert(n == 0) 49 return 0 50EOF 51log_must_program $TESTPOOL - <<-EOF 52 n = 0 53 for p in zfs.list.properties("$TESTPOOL/$TESTFS") do 54 n = n + 1 55 end 56 assert(n == 0) 57 return 0 58EOF 59 60# Add a single user property 61log_must zfs set $TESTPROP="$TESTVAL" $TESTPOOL/$TESTFS 62 63log_must_program $TESTPOOL - <<-EOF 64 n = 0 65 for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do 66 assert(p == "$TESTPROP") 67 assert(v == "$TESTVAL") 68 n = n + 1 69 end 70 assert(n == 1) 71 return 0 72EOF 73log_must_program $TESTPOOL - <<-EOF 74 n = 0 75 for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do 76 assert(p == "$TESTPROP") 77 assert(v == "$TESTVAL") 78 n = n + 1 79 end 80 assert(n == 1) 81 return 0 82EOF 83 84log_must zfs set $TESTPROP1="$TESTVAL1" $TESTPOOL/$TESTFS 85log_must zfs set $TESTPROP2="$TESTVAL2" $TESTPOOL/$TESTFS 86log_must zfs set $TESTPROP3="$TESTVAL3" $TESTPOOL/$TESTFS 87log_must zfs set $TESTPROP4="$TESTVAL4" $TESTPOOL/$TESTFS 88 89# All user properties have correct value and appear exactly once 90log_must_program $TESTPOOL - <<-EOF 91 a = {} 92 a["$TESTPROP"] = false 93 a["$TESTPROP1"] = false 94 a["$TESTPROP2"] = false 95 a["$TESTPROP3"] = false 96 a["$TESTPROP4"] = false 97 m = {} 98 m["$TESTPROP"] = "$TESTVAL" 99 m["$TESTPROP1"] = "$TESTVAL1" 100 m["$TESTPROP2"] = "$TESTVAL2" 101 m["$TESTPROP3"] = "$TESTVAL3" 102 m["$TESTPROP4"] = "$TESTVAL4" 103 n = 0 104 for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do 105 assert(not a[p]) 106 a[p] = true 107 assert(v == m[p]) 108 n = n + 1 109 end 110 assert(n == 5) 111 assert(a["$TESTPROP"] and 112 a["$TESTPROP1"] and 113 a["$TESTPROP2"] and 114 a["$TESTPROP3"] and 115 a["$TESTPROP4"]) 116 return 0 117EOF 118log_must_program $TESTPOOL - <<-EOF 119 a = {} 120 a["$TESTPROP"] = false 121 a["$TESTPROP1"] = false 122 a["$TESTPROP2"] = false 123 a["$TESTPROP3"] = false 124 a["$TESTPROP4"] = false 125 m = {} 126 m["$TESTPROP"] = "$TESTVAL" 127 m["$TESTPROP1"] = "$TESTVAL1" 128 m["$TESTPROP2"] = "$TESTVAL2" 129 m["$TESTPROP3"] = "$TESTVAL3" 130 m["$TESTPROP4"] = "$TESTVAL4" 131 n = 0 132 for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do 133 assert(not a[p]) 134 a[p] = true 135 assert(v == m[p]) 136 n = n + 1 137 end 138 assert(n == 5) 139 assert(a["$TESTPROP"] and 140 a["$TESTPROP1"] and 141 a["$TESTPROP2"] and 142 a["$TESTPROP3"] and 143 a["$TESTPROP4"]) 144 return 0 145EOF 146 147log_pass "Listing zfs user properties should work correctly." 148