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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/cli_root/zpool_split/zpool_split.cfg
19
20#
21# DESCRIPTION:
22# 'zpool split' should only work with supported options and parameters.
23#
24# STRATEGY:
25# 1. Verify every supported option is accepted
26# 2. Verify other unsupported options raise an error
27# 3. Verify we cannot split a pool if the destination already exists
28#
29
30verify_runnable "both"
31
32function cleanup
33{
34	destroy_pool $TESTPOOL
35	destroy_pool $TESTPOOL2
36	rm -f $DEVICE1 $DEVICE2 $DEVICE3
37}
38
39function setup_mirror
40{
41	truncate -s $SPA_MINDEVSIZE $DEVICE1
42	truncate -s $SPA_MINDEVSIZE $DEVICE2
43	log_must zpool create -f $TESTPOOL mirror $DEVICE1 $DEVICE2
44}
45
46log_assert "'zpool split' should only work with supported options and parameters."
47log_onexit cleanup
48
49typeset goodopts=(
50    "" "-g" "-L" "-n" "-P" "-o comment=ok" "-o ro -R /mnt" "-l -R /mnt" "-gLnP")
51typeset badopts=(
52    "-f" "-h" "-x" "-Pp" "-l" "-G" "-o" "-o ro" "-o comment" "-R" "-R dir" "=")
53
54DEVICE1="$TEST_BASE_DIR/device-1"
55DEVICE2="$TEST_BASE_DIR/device-2"
56DEVICE3="$TEST_BASE_DIR/device-3"
57
58# 1. Verify every supported option and/or parameter is accepted
59for opt in "${goodopts[@]}"
60do
61	setup_mirror
62	log_must zpool split $opt $TESTPOOL $TESTPOOL2
63	cleanup
64done
65
66# 2. Verify other unsupported options and/or parameters raise an error
67setup_mirror
68for opt in "${badopts[@]}"
69do
70	log_mustnot zpool split $opt $TESTPOOL $TESTPOOL2
71done
72cleanup
73
74# 3. Verify we cannot split a pool if the destination already exists
75setup_mirror
76truncate -s $SPA_MINDEVSIZE $DEVICE3
77log_must zpool create $TESTPOOL2 $DEVICE3
78log_mustnot zpool split $TESTPOOL $TESTPOOL2
79
80log_pass "'zpool split' only works with supported options and parameters."
81