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#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. ${STF_SUITE}/include/libtest.kshlib
28. ${STF_SUITE}/tests/zones/zones_common.kshlib
29
30################################################################################
31#
32# __stc_assertion_start
33#
34# ID:  zones_003_pos
35#
36# DESCRIPTION:
37#
38# Zone cloning via ZFS snapshots works as expected.
39# We can clone zones where the zonepath is the top level of a ZFS filesystem
40# using snapshots. Where the zone is not at the top level of a ZFS filesystem,
41# cloning the zone uses the normal method of copying the files when
42# performing the clone operation.
43#
44# STRATEGY:
45#	1. The setup script should have created the zone.
46#       2. Clone a zone-on-ZFS
47#	3. Verify that ZFS snapshots were taken and used for the clone and that
48#	   the new zone is indeed a clone (in the ZFS sense)
49#	4. Clone a normal zone & verify that no snapshots were taken.
50#	5. Clone a zone-on-ZFS, but specify the "copy" method & verify that no
51#	   snapshots were taken.
52#
53# TESTABILITY: explicit
54#
55# TEST_AUTOMATION_LEVEL: automated
56#
57# CODING_STATUS: COMPLETED (2006-10-12)
58#
59# __stc_assertion_end
60#
61################################################################################
62
63function cleanup {
64
65	log_must $ZONEADM -z $ZONE3 uninstall -F
66	log_must $ZONECFG -z $ZONE3 delete -F
67
68	log_must $ZONEADM -z $ZONE4 uninstall -F
69	log_must $ZONECFG -z $ZONE4 delete -F
70}
71
72
73verify_runnable "global"
74log_onexit cleanup
75
76log_assert "Zone cloning via ZFS snapshots works as expected."
77
78
79# Make sure our zones exist:
80if [ ! -d /$TESTPOOL/$ZONE ]
81then
82	log_fail "Zone dir in /$TESTPOOL/$ZONE not found!"
83fi
84
85if [ ! -d /$TESTPOOL/simple_dir/$ZONE2 ]
86then
87	log_fail "Zone dir /$TESTPOOL/simple_dir/$ZONE2 not found!"
88fi
89
90
91create_zone $ZONE3 /$TESTPOOL
92create_zone $ZONE4 /$TESTPOOL/simple_dir
93
94# Create a new zone3 based on cloning our zone
95log_note "Cloning ZFS rooted zone"
96log_must $ZONEADM -z $ZONE3 clone $ZONE
97
98# Make sure our snapshot and the new filesystem is there
99log_must snapexists $TESTPOOL/$ZONE@SUNWzone1
100log_must datasetexists $TESTPOOL/$ZONE3
101
102# verify that it is in fact a clone:
103ORIGIN=$($ZFS get -H -o value origin $TESTPOOL/$ZONE3)
104if [ "$ORIGIN" != "$TESTPOOL/$ZONE@SUNWzone1" ]
105then
106	log_fail "$ZONE3 does not appear to have been ZFS cloned from $ZONE"
107fi
108
109# Now uninstall that zone & the snapshot it was cloned from
110log_must $ZONEADM -z $ZONE3 uninstall -F
111log_must $ZONECFG -z $ZONE3 delete -F
112
113# Again create a new zone3, but clone the non-ZFS-rooted zone2
114# A snapshot should not have been created this time, but a new filesys
115# should still be created.
116create_zone $ZONE3 /$TESTPOOL SUNWsn1
117log_note "Cloning non-ZFS rooted zone2"
118log_must $ZONEADM -z $ZONE3 clone $ZONE2
119log_mustnot snapexists $TESTPOOL/$ZONE2@SUNWzone1
120log_must datasetexists $TESTPOOL/$ZONE3
121
122# Finally, clone a zone using the old copy method, where
123# a snapshot should not be taken.
124log_note "Cloning ZFS rooted zone using copy method"
125log_must $ZONEADM -z $ZONE4 clone -m copy $ZONE
126log_mustnot snapexists $TESTPOOl/$ZONE@SUNWzone1
127
128log_pass "Zone cloning via ZFS snapshots works as expected."
129