1#!/usr/local/bin/ksh93 -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 http://www.opensolaris.org/os/licensing.
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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)history_001_pos.ksh	1.3	07/05/25 SMI"
30#
31
32. $STF_SUITE/tests/history/history_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: history_001_pos
39#
40# DESCRIPTION:
41#	Create a scenario to verify the following zpool subcommands are logged.
42#	    create, destroy, add, remove, offline, online, attach, detach, replace,
43#	    scrub, export, import, clear, upgrade.
44#
45# STRATEGY:
46#	1. Create three virtual disk files.
47#	2. Create a three-way mirror.
48#	3. Invoke every sub-commands to this mirror, except upgrade.
49#	4. Compare 'zpool history' log with expected log.
50#	5. Imported specified pool and upgrade it, verify 'upgrade' was logged.
51#
52# TESTABILITY: explicit
53#
54# TEST_AUTOMATION_LEVEL: automated
55#
56# CODING_STATUS: COMPLETED (2006-07-05)
57#
58# __stc_assertion_end
59#
60################################################################################
61
62verify_runnable "global"
63
64function cleanup
65{
66	destroy_pool $MPOOL
67	destroy_pool $upgrade_pool
68
69	[[ -d $import_dir ]] && $RM -rf $import_dir
70	for file in $REAL_HISTORY $EXPECT_HISTORY \
71	    $VDEV1 $VDEV2 $VDEV3 $VDEV4
72	do
73		[[ -f $file ]] && $RM -f $file
74	done
75}
76
77log_assert "Verify zpool sub-commands which modify state are logged."
78log_onexit cleanup
79
80(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)"
81VDEV1=$TMPDIR/vdev1; VDEV2=$TMPDIR/vdev2;
82VDEV3=$TMPDIR/vdev3; VDEV4=$TMPDIR/vdev4;
83
84log_must create_vdevs $VDEV1 $VDEV2 $VDEV3 $VDEV4
85$CAT /dev/null > $EXPECT_HISTORY
86
87exec_record $ZPOOL create $MPOOL mirror $VDEV1 $VDEV2
88exec_record $ZPOOL add -f $MPOOL spare $VDEV3
89exec_record $ZPOOL remove $MPOOL $VDEV3
90exec_record $ZPOOL offline $MPOOL $VDEV1
91exec_record $ZPOOL online $MPOOL $VDEV1
92exec_record $ZPOOL attach $MPOOL $VDEV1 $VDEV4
93exec_record $ZPOOL detach $MPOOL $VDEV4
94exec_record $ZPOOL replace -f $MPOOL $VDEV1 $VDEV4
95exec_record $ZPOOL export $MPOOL
96exec_record $ZPOOL import -d $TMPDIR $MPOOL
97exec_record $ZPOOL destroy $MPOOL
98exec_record $ZPOOL import -D -f -d $TMPDIR $MPOOL
99exec_record $ZPOOL clear $MPOOL
100
101format_history $MPOOL $REAL_HISTORY
102log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY
103
104import_dir=$TMPDIR/import_dir.${TESTCASE_ID}
105log_must $MKDIR $import_dir
106log_must $CP $STF_SUITE/tests/history/zfs-pool-v4.dat.Z $import_dir
107log_must $UNCOMPRESS $import_dir/zfs-pool-v4.dat.Z
108
109# Truncate $EXPECT_HISTORY file
110log_must eval "$CAT /dev/null > $EXPECT_HISTORY"
111
112upgrade_pool=$($ZPOOL import -d $import_dir | $GREP "pool:" | $AWK '{print $2}')
113exec_record $ZPOOL import -d $import_dir $upgrade_pool
114# Get existing history
115format_history $upgrade_pool $EXPECT_HISTORY
116exec_record $ZPOOL upgrade $upgrade_pool
117
118format_history $upgrade_pool $REAL_HISTORY
119log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY
120
121log_pass "zpool sub-commands which modify state are logged passed. "
122