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 be able to split encrypted pools
23#
24# STRATEGY:
25# 1. Create an encrypted pool
26# 2. Split and re-import the pool, verify altroot is mounted.
27#
28
29verify_runnable "both"
30
31function cleanup
32{
33	destroy_pool $TESTPOOL
34	destroy_pool $TESTPOOL2
35	rm -f $DEVICE1 $DEVICE2
36}
37
38log_assert "'zpool split' should be able to split encrypted pools"
39log_onexit cleanup
40
41DEVICE1="$TEST_BASE_DIR/device-1"
42DEVICE2="$TEST_BASE_DIR/device-2"
43passphrase="password"
44altroot="$TESTDIR/zpool-split-$RANDOM"
45
46# 1. Create an encrypted pool
47truncate -s $SPA_MINDEVSIZE $DEVICE1
48truncate -s $SPA_MINDEVSIZE $DEVICE2
49log_must eval "echo "$passphrase" | zpool create -O encryption=aes-256-ccm " \
50	"-O keyformat=passphrase $TESTPOOL mirror $DEVICE1 $DEVICE2"
51
52# 2. Split and re-import the pool, verify altroot is mounted.
53log_must eval "echo "$passphrase" | zpool split -l -R $altroot " \
54	"$TESTPOOL $TESTPOOL2"
55log_must test "$(get_prop 'encryption' $TESTPOOL2)" == "aes-256-ccm"
56log_must test "$(get_pool_prop 'altroot' $TESTPOOL2)" == "$altroot"
57log_must mounted $altroot/$TESTPOOL2
58
59log_pass "'zpool split' can split encrypted pools"
60