xref: /titanic_44/usr/src/test/zfs-tests/tests/functional/migration/migration.kshlib (revision f38cb554a534c6df738be3f4d23327e69888e634)
1*f38cb554SJohn Wren Kennedy#
2*f38cb554SJohn Wren Kennedy# CDDL HEADER START
3*f38cb554SJohn Wren Kennedy#
4*f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
5*f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
6*f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
7*f38cb554SJohn Wren Kennedy#
8*f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
10*f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
11*f38cb554SJohn Wren Kennedy# and limitations under the License.
12*f38cb554SJohn Wren Kennedy#
13*f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
14*f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
16*f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
17*f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
18*f38cb554SJohn Wren Kennedy#
19*f38cb554SJohn Wren Kennedy# CDDL HEADER END
20*f38cb554SJohn Wren Kennedy#
21*f38cb554SJohn Wren Kennedy
22*f38cb554SJohn Wren Kennedy#
23*f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*f38cb554SJohn Wren Kennedy# Use is subject to license terms.
25*f38cb554SJohn Wren Kennedy#
26*f38cb554SJohn Wren Kennedy
27*f38cb554SJohn Wren Kennedy#
28*f38cb554SJohn Wren Kennedy# Copyright (c) 2013 by Delphix. All rights reserved.
29*f38cb554SJohn Wren Kennedy#
30*f38cb554SJohn Wren Kennedy
31*f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/migration/migration.cfg
32*f38cb554SJohn Wren Kennedy
33*f38cb554SJohn Wren Kennedy#
34*f38cb554SJohn Wren Kennedy# This function creates the test archive for migration.
35*f38cb554SJohn Wren Kennedy#
36*f38cb554SJohn Wren Kennedy# Usage:
37*f38cb554SJohn Wren Kennedy# prepare srcdir cmd
38*f38cb554SJohn Wren Kennedy#
39*f38cb554SJohn Wren Kennedy# Return value: 0 on success
40*f38cb554SJohn Wren Kennedy#		1 on failure
41*f38cb554SJohn Wren Kennedy#
42*f38cb554SJohn Wren Kennedy# Where:
43*f38cb554SJohn Wren Kennedy#	srcdir: is the directory where the testfile is
44*f38cb554SJohn Wren Kennedy#	cmd:	is the command to be executed.
45*f38cb554SJohn Wren Kennedy#		E.g.
46*f38cb554SJohn Wren Kennedy#		$TAR cf $TESTDIR/tar$$.tar
47*f38cb554SJohn Wren Kennedy#
48*f38cb554SJohn Wren Kennedyfunction prepare #srcdir cmd
49*f38cb554SJohn Wren Kennedy{
50*f38cb554SJohn Wren Kennedy	typeset srcdir=$1
51*f38cb554SJohn Wren Kennedy	typeset cmd=$2
52*f38cb554SJohn Wren Kennedy	typeset -i retval=0
53*f38cb554SJohn Wren Kennedy
54*f38cb554SJohn Wren Kennedy	cwd=$PWD
55*f38cb554SJohn Wren Kennedy	cd $srcdir
56*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
57*f38cb554SJohn Wren Kennedy
58*f38cb554SJohn Wren Kennedy	$cmd
59*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
60*f38cb554SJohn Wren Kennedy
61*f38cb554SJohn Wren Kennedy	cd $cwd
62*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
63*f38cb554SJohn Wren Kennedy
64*f38cb554SJohn Wren Kennedy	return 0
65*f38cb554SJohn Wren Kennedy}
66*f38cb554SJohn Wren Kennedy
67*f38cb554SJohn Wren Kennedy#
68*f38cb554SJohn Wren Kennedy# This function executes a passed in command and then determines the chksum
69*f38cb554SJohn Wren Kennedy# of the resulting file.  The chksum components are checked against the ones
70*f38cb554SJohn Wren Kennedy# passed in to determine if they are equal.  If they are equal, 0 is returned
71*f38cb554SJohn Wren Kennedy# otherwise 1 is returned.
72*f38cb554SJohn Wren Kennedy#
73*f38cb554SJohn Wren Kennedy# Usage:
74*f38cb554SJohn Wren Kennedy# migrate destdir oldsuma oldsumb command_to_execute
75*f38cb554SJohn Wren Kennedy#
76*f38cb554SJohn Wren Kennedy# Return value: 0 on success
77*f38cb554SJohn Wren Kennedy#		1 on failure
78*f38cb554SJohn Wren Kennedy#
79*f38cb554SJohn Wren Kennedy# Where:
80*f38cb554SJohn Wren Kennedy#	destdir: is the directory where the command is to be executed on
81*f38cb554SJohn Wren Kennedy#	oldsuma: is the first part of the values returned by sum
82*f38cb554SJohn Wren Kennedy#	oldsumb: is the second part of the values returned by sum
83*f38cb554SJohn Wren Kennedy#	cmd: is the command to be executed;
84*f38cb554SJohn Wren Kennedy#		E.g.
85*f38cb554SJohn Wren Kennedy#		"$TAR xf $TESTDIR/tar$$.tar"
86*f38cb554SJohn Wren Kennedy#
87*f38cb554SJohn Wren Kennedyfunction migrate #destdir oldsuma oldsumb cmd
88*f38cb554SJohn Wren Kennedy{
89*f38cb554SJohn Wren Kennedy	typeset destdir=$1
90*f38cb554SJohn Wren Kennedy	typeset oldsuma=$2
91*f38cb554SJohn Wren Kennedy	typeset oldsumb=$3
92*f38cb554SJohn Wren Kennedy	typeset cmd=$4
93*f38cb554SJohn Wren Kennedy	typeset -i retval=0
94*f38cb554SJohn Wren Kennedy
95*f38cb554SJohn Wren Kennedy	cwd=$PWD
96*f38cb554SJohn Wren Kennedy	cd $destdir
97*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
98*f38cb554SJohn Wren Kennedy
99*f38cb554SJohn Wren Kennedy	$cmd
100*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
101*f38cb554SJohn Wren Kennedy
102*f38cb554SJohn Wren Kennedy	sumy=`$SUM ./$BNAME`
103*f38cb554SJohn Wren Kennedy	suma=`$ECHO $sumy | $AWK '{print $1}'`
104*f38cb554SJohn Wren Kennedy	sumb=`$ECHO $sumy | $AWK '{print $2}'`
105*f38cb554SJohn Wren Kennedy
106*f38cb554SJohn Wren Kennedy	if (( $oldsuma != $suma )); then
107*f38cb554SJohn Wren Kennedy		log_note "$SUM values are not the same"
108*f38cb554SJohn Wren Kennedy		retval=1
109*f38cb554SJohn Wren Kennedy	fi
110*f38cb554SJohn Wren Kennedy
111*f38cb554SJohn Wren Kennedy	if (( $oldsumb != $sumb )); then
112*f38cb554SJohn Wren Kennedy		log_note "$SUM values are not the same"
113*f38cb554SJohn Wren Kennedy		retval=1
114*f38cb554SJohn Wren Kennedy	fi
115*f38cb554SJohn Wren Kennedy
116*f38cb554SJohn Wren Kennedy	cd $cwd
117*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
118*f38cb554SJohn Wren Kennedy	return $retval
119*f38cb554SJohn Wren Kennedy}
120*f38cb554SJohn Wren Kennedy
121*f38cb554SJohn Wren Kennedyfunction migrate_cpio
122*f38cb554SJohn Wren Kennedy{
123*f38cb554SJohn Wren Kennedy	typeset destdir=$1
124*f38cb554SJohn Wren Kennedy	typeset archive=$2
125*f38cb554SJohn Wren Kennedy	typeset oldsuma=$3
126*f38cb554SJohn Wren Kennedy	typeset oldsumb=$4
127*f38cb554SJohn Wren Kennedy	typeset -i retval=0
128*f38cb554SJohn Wren Kennedy
129*f38cb554SJohn Wren Kennedy	cwd=$PWD
130*f38cb554SJohn Wren Kennedy	cd $destdir
131*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
132*f38cb554SJohn Wren Kennedy
133*f38cb554SJohn Wren Kennedy	$CPIO -iv < $archive
134*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
135*f38cb554SJohn Wren Kennedy
136*f38cb554SJohn Wren Kennedy	sumy=`$SUM ./$BNAME`
137*f38cb554SJohn Wren Kennedy	suma=`$ECHO $sumy | $AWK '{print $1}'`
138*f38cb554SJohn Wren Kennedy	sumb=`$ECHO $sumy | $AWK '{print $2}'`
139*f38cb554SJohn Wren Kennedy
140*f38cb554SJohn Wren Kennedy	if (( $oldsuma != $suma )); then
141*f38cb554SJohn Wren Kennedy		log_note "$SUM values are not the same"
142*f38cb554SJohn Wren Kennedy		retval=1
143*f38cb554SJohn Wren Kennedy	fi
144*f38cb554SJohn Wren Kennedy
145*f38cb554SJohn Wren Kennedy	if (( $oldsumb != $sumb )); then
146*f38cb554SJohn Wren Kennedy		log_note "$SUM values are not the same"
147*f38cb554SJohn Wren Kennedy		retval=1
148*f38cb554SJohn Wren Kennedy	fi
149*f38cb554SJohn Wren Kennedy
150*f38cb554SJohn Wren Kennedy	cd $cwd
151*f38cb554SJohn Wren Kennedy	(( $? != 0 )) && return 1
152*f38cb554SJohn Wren Kennedy	return $retval
153*f38cb554SJohn Wren Kennedy}
154