1#!/bin/ksh -p
2
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 Open-E, Inc. All Rights Reserved.
16#
17
18. $STF_SUITE/tests/functional/cli_root/zpool_reopen/zpool_reopen.shlib
19
20#
21# DESCRIPTION:
22# Test if zpool reopen with pool name as argument works correctly.
23#
24# STRATEGY:
25# 1. Create a pool.
26# 2. Remove a disk.
27# 3. Reopen a pool and verify if removed disk is marked as unavailable.
28# 4. "Plug back" disk.
29# 5. Reopen a pool and verify if removed disk is marked online again.
30# 6. Check if reopen caused resilver start.
31#
32
33verify_runnable "global"
34
35function cleanup
36{
37	# bring back removed disk online for further tests
38	insert_disk $REMOVED_DISK $scsi_host
39	poolexists $TESTPOOL && destroy_pool $TESTPOOL
40	clear_labels $REMOVED_DISK $DISK2
41}
42
43log_assert "Testing zpool reopen with no arguments"
44log_onexit cleanup
45
46set_removed_disk
47scsi_host=$(get_scsi_host $REMOVED_DISK)
48
49# 1. Create a pool.
50default_mirror_setup_noexit $REMOVED_DISK_ID $DISK2
51# 2. Remove a disk.
52remove_disk $REMOVED_DISK
53# 3. Reopen a pool and verify if removed disk is marked as unavailable.
54log_must zpool reopen $TESTPOOL
55log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "unavail"
56# Write some data to the pool
57log_must generate_random_file /$TESTPOOL/data $SMALL_FILE_SIZE
58sync_pool $TESTPOOL
59# 4. "Plug back" disk.
60insert_disk $REMOVED_DISK $scsi_host
61# 5. Reopen a pool and verify if removed disk is marked online again.
62log_must zpool reopen $TESTPOOL
63log_must check_state $TESTPOOL "$REMOVED_DISK_ID" "online"
64# 6. Check if reopen caused resilver start.
65log_must wait_for_resilver_end $TESTPOOL $MAXTIMEOUT
66
67# clean up
68log_must zpool destroy $TESTPOOL
69clear_labels $REMOVED_DISK $DISK2
70
71log_pass "Zpool reopen with no arguments test passed"
72