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