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_007_pos.ksh	1.1	07/01/09 SMI"
30#
31
32. $STF_SUITE/tests/history/history_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: history_007_pos
39#
40# DESCRIPTION:
41#	Verify command history moves with pool while pool being migrated
42#
43# STRATEGY:
44#	1. Import uniform platform and cross platform pools
45#	2. Contract the command history of the imported pool
46#	3. Compare imported history log with the previous log.
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING_STATUS: COMPLETED (2006-10-25)
53#
54# __stc_assertion_end
55#
56################################################################################
57
58verify_runnable "global"
59
60function cleanup
61{
62	poolexists $migratedpoolname &&  \
63		log_must $ZPOOL destroy -f $migratedpoolname
64
65	[[ -d $import_dir ]] && $RM -rf $import_dir
66}
67
68log_assert "Verify command history moves with pool while migrating."
69log_onexit cleanup
70
71# The *.orig_history.txt files were made using the America/Denver timezone,
72# and since "zpool history" outputs timestamps in localtime, the test must
73# be run in that same timezone
74export TZ="America/Denver"
75
76tst_dir=$STF_SUITE/tests/history
77import_dir=$TESTDIR/importdir.${TESTCASE_ID}
78migrated_cmds_f=$import_dir/migrated_history.${TESTCASE_ID}
79migratedpoolname=$MIGRATEDPOOLNAME
80typeset -i RET=1
81typeset -i linenum=0
82
83[[ ! -d $import_dir ]] && log_must $MKDIR $import_dir
84
85# We test the migrations on both uniform platform and cross platform
86for arch in "i386" "sparc"; do
87	log_must $CP $tst_dir/${arch}.orig_history.txt $import_dir
88	orig_cmds_f=$import_dir/${arch}.orig_history.txt
89	#remove blank line
90	orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt
91	$CAT $orig_cmds_f | $GREP -v "^$" > $orig_cmds_f1
92
93	log_must $CP $tst_dir/${arch}.migratedpool.DAT.Z $import_dir
94	log_must $UNCOMPRESS $import_dir/${arch}.migratedpool.DAT.Z
95
96	#destroy the pool with same name, so that import operation could succeed.
97	poolexists $migratedpoolname &&  \
98		log_must $ZPOOL destroy -f $migratedpoolname
99
100	log_must $ZPOOL import -d $import_dir $migratedpoolname
101	$ZPOOL history $migratedpoolname | $GREP -v "^$" >$migrated_cmds_f
102	RET=$?
103	(( $RET != 0 )) && log_fail "$ZPOOL histroy $migratedpoolname fails."
104
105	# The migrated history file should differ with original history file on
106	# two commands -- 'export' and 'import', which are included in migrated
107	# history file but not in original history file. so, check the two commands
108	# firstly in migrated history file and then delete them, and then compare
109	# this filtered file with the original history file. They should be identical
110	# at this time.
111	for subcmd in "export" "import"; do
112		$GREP "$subcmd" $migrated_cmds_f >/dev/null 2>&1
113		RET=$?
114		(( $RET != 0 )) && log_fail "zpool $subcmd is not logged for" \
115				"the imported pool $migratedpoolname."
116	done
117
118	tmpfile=$import_dir/cmds_tmp.${TESTCASE_ID}
119	linenum=`$CAT $migrated_cmds_f | $WC -l`
120	(( linenum = linenum - 2 ))
121	$HEAD -n $linenum $migrated_cmds_f > $tmpfile
122	log_must $DIFF $tmpfile $orig_cmds_f1
123
124	#cleanup for next loop testing
125	log_must $ZPOOL destroy -f $migratedpoolname
126	log_must $RM -f `$LS $import_dir`
127done
128
129log_pass "Command history moves with pool as expected while pool being migrated. "
130