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