1#!/bin/ksh -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 https://opensource.org/licenses/CDDL-1.0.
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#
24# Copyright 2020 Attila Fülöp <attila@fueloep.org>
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29typeset STR_DRYRUN="would create '$TESTPOOL' with the following layout:"
30typeset VDEV_PREFIX="$TEST_BASE_DIR/filedev"
31
32#
33# DESCRIPTION:
34# 'zpool create -n <pool> <vdev> ...' can display the correct configuration
35#
36# STRATEGY:
37# 1. Create -n a storage pool and verify the output is as expected.
38#
39
40typeset -a dev=(
41	"${VDEV_PREFIX}00" "${VDEV_PREFIX}01" "${VDEV_PREFIX}02"
42	"${VDEV_PREFIX}03" "${VDEV_PREFIX}04" "${VDEV_PREFIX}05"
43	"${VDEV_PREFIX}06" "${VDEV_PREFIX}07" "${VDEV_PREFIX}08"
44	"${VDEV_PREFIX}09" "${VDEV_PREFIX}10" "${VDEV_PREFIX}11"
45)
46
47typeset -a tests=(
48    (
49	tree="'${dev[0]}' '${dev[1]}' log '${dev[2]}' '${dev[3]}' \
50	    special '${dev[4]}' '${dev[5]}' dedup '${dev[6]}' '${dev[7]}' \
51		spare '${dev[8]}' '${dev[9]}' cache '${dev[10]}' '${dev[11]}'"
52
53	want="$STR_DRYRUN
54
55	$TESTPOOL
56	  ${dev[0]}
57	  ${dev[1]}
58	dedup
59	  ${dev[6]}
60	  ${dev[7]}
61	special
62	  ${dev[4]}
63	  ${dev[5]}
64	logs
65	  ${dev[2]}
66	  ${dev[3]}
67	cache
68	  ${dev[10]}
69	  ${dev[11]}
70	spares
71	  ${dev[8]}
72	  ${dev[9]}"
73    )
74    (
75	tree="mirror '${dev[0]}' '${dev[1]}' \
76	    log mirror '${dev[2]}' '${dev[3]}' \
77	    special mirror '${dev[4]}' '${dev[5]}' \
78	    dedup mirror '${dev[6]}' '${dev[7]}' \
79		spare '${dev[8]}' '${dev[9]}' \
80	    cache '${dev[10]}' '${dev[11]}'"
81
82	want="$STR_DRYRUN
83
84	$TESTPOOL
85	  mirror
86	    ${dev[0]}
87	    ${dev[1]}
88	dedup
89	  mirror
90	    ${dev[6]}
91	    ${dev[7]}
92	special
93	  mirror
94	    ${dev[4]}
95	    ${dev[5]}
96	logs
97	  mirror
98	    ${dev[2]}
99	    ${dev[3]}
100	cache
101	  ${dev[10]}
102	  ${dev[11]}
103	spares
104	  ${dev[8]}
105	  ${dev[9]}"
106    )
107)
108
109verify_runnable "global"
110
111function cleanup
112{
113	rm -f "$VDEV_PREFIX"*
114}
115
116log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration"
117
118log_onexit cleanup
119
120# Create needed file vdevs.
121for (( i=0; i < ${#dev[@]}; i+=1 )); do
122	log_must truncate -s $SPA_MINDEVSIZE "${dev[$i]}"
123done
124
125# Foreach test create pool, add -n devices and check output.
126for (( i=0; i < ${#tests[@]}; i+=1 )); do
127	typeset tree="${tests[$i].tree}"
128	typeset want="${tests[$i].want}"
129
130	typeset out="$(log_must eval "zpool create -n '$TESTPOOL' $tree" | \
131	    sed /^SUCCESS/d)"
132
133	if [[ "$out" != "$want" ]]; then
134		log_fail "Got:\n" "$out" "\nbut expected:\n" "$want"
135	fi
136done
137
138log_pass "'zpool add -n <pool> <vdev> ...' displays config correctly."
139