summaryrefslogtreecommitdiff
path: root/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_labelclear/zpool_labelclear_exported.ksh
blob: 0a9016c471c9fa47bb3706abdb0c8cc15d6fa011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/ksh -p
#
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2016 Nexenta Systems, Inc.
#

. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg

# DESCRIPTION:
# Check that zpool labelclear will refuse to clear the label
# on ACTIVE vdevs of exported pool without -f, and will succeeded with -f.
#
# STRATEGY:
# 1. Create a pool with log device.
# 2. Export the pool.
# 3. Check that zpool labelclear returns non-zero when trying to
#    clear the label on ACTIVE vdevs, and succeeds with -f.
# 4. Add auxilary vdevs (cache/spare).
# 5. Check that zpool labelclear succeeds on auxilary vdevs of
#    exported pool.

verify_runnable "global"

function cleanup
{
	poolexists $TESTPOOL && destroy_pool $TESTPOOL
}

log_onexit cleanup
log_assert "zpool labelclear will fail on ACTIVE vdevs of exported pool and" \
    "succeed with -f"

for vdevtype in "" "cache" "spare"; do
	# Create simple pool, skip any mounts
	log_must zpool create -O mountpoint=none -f $TESTPOOL $disk1 log $disk2
	# Add auxilary vdevs (cache/spare)
	if [[ -n $vdevtype ]]; then
		log_must zpool add $TESTPOOL $vdevtype $disk3
	fi
	# Export the pool
	log_must zpool export $TESTPOOL

	# Check that labelclear will fail without -f
	log_mustnot zpool labelclear $disk1
	log_must zdb -lq $disk1
	log_mustnot zpool labelclear $disk2
	log_must zdb -lq $disk2

	# Check that labelclear will succeed with -f
	log_must zpool labelclear -f $disk1
	log_mustnot zdb -lq $disk1
	log_must zpool labelclear -f $disk2
	log_mustnot zdb -lq $disk2

	# Check that labelclear on auxilary vdevs will succeed
	if [[ -n $vdevtype ]]; then
		log_must zpool labelclear $disk3
		log_mustnot zdb -lq $disk3
	fi
done

log_pass "zpool labelclear will fail on ACTIVE vdevs of exported pool and" \
    "succeed with -f"