1 #! /usr/bin/ksh -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
28 ###############################################################################
29 # start __stf_assertion__
30 #
31 # ASSERTION: svccfg_import_010
32 #
33 # DESCRIPTION:
34 # Calling the 'import' subcommand with a valid service manifest
35 # that was previously applied (with the same services and
36 # instances) but has additional information will update the repository
37 # with this information.
38 #
39 # STRATEGY:
40 # This test imports in the a simple .xml file - the one from import_001
41 # test. Then the test imports in the .xml file from import_008
42 # test. This .xml file is identical to the import_001 .xml file
43 # with the addition of a astring property "testinfo". To verify
44 # the assertion the test checks that after the second import (of
45 # the import_008 .xml file) the testinfo property exists.
46 #
47 # end __stf_assertion__
48 ###############################################################################
49
50
51 # First STF library
52 . ${STF_TOOLS}/include/stf.kshlib
53
54 # Load GL library
55 . ${STF_SUITE}/include/gltest.kshlib
56
57 # Load svc.startd library for manifest_generate
58 . ${STF_SUITE}/include/svc.startd_config.kshlib
59
60 readonly ME=$(whence -p ${0})
61 readonly MYLOC=$(dirname ${ME})
62
63 # Initialize test result
64 typeset -i RESULT=$STF_PASS
65
66
67 function cleanup {
68
69 # Note that $TEST_SERVICE may or may not exist so don't check
70 # results. Just make sure the service is gone.
71
72 manifest_purgemd5 $registration_file
73
74 service_cleanup ${TEST_SERVICE}
75
76 service_exists ${TEST_SERVICE}
77 [[ $? -eq 0 ]] && {
78 echo "--DIAG: [${assertion}, cleanup]
79 service ${TEST_SERVICE} should not exist in
80 repository after being deleted, but does"
81
82 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
83 }
84
85 rm -f $ERRFILE $OUTFILE /tmp/export.$$.? $registration_file
86
87 exit $RESULT
88 }
89
90 trap cleanup 0 1 2 15
91
92 # make sure that the environment is sane - svc.configd is up and running
93 check_gl_env
94 [[ $? -ne 0 ]] && {
95 echo "--DIAG:
96 Invalid test environment - svc.configd not available"
97
98 RESULT=$STF_UNRESOLVED
99 exit $RESULT
100 }
101
102 assertion=svccfg_import_010
103
104 # extract and print assertion information from this source script.
105 extract_assertion_info $ME
106
107 # Before starting make sure that the test service doesn't already exist.
108 # If it does then consider it a fatal error.
109
110 service_exists $TEST_SERVICE
111 [[ $? -eq 0 ]] && {
112 echo "--DIAG: [${assertion}]
113 service $TEST_SERVICE should not exist in
114 repository but does"
115
116 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
117 exit $RESULT
118 }
119
120 # # Start assertion testing
121 #
122
123 # Start with the import_008.xml template
124 registration_template=$MYLOC/import_001.xml
125 readonly registration_file=$MYLOC/foo.xml
126 readonly LOGFILE=/tmp/log.$$
127 readonly STATEFILE=/tmp/state.$$
128
129 manifest_generate $registration_template \
130 TEST_SERVICE=$TEST_SERVICE \
131 TEST_INSTANCE=$TEST_INSTANCE \
132 SERVICE_APP=$SERVICE_APP \
133 LOGFILE=$LOGFILE \
134 STATEFILE=$STATEFILE >$registration_file
135
136 manifest_purgemd5 $registration_file
137
138 svccfg import $registration_file > $OUTFILE 2>$ERRFILE
139 ret=$?
140
141 [[ $ret -ne 0 ]] && {
142 echo "--DIAG: [${assertion}]
143 svccfg import expected to return 0, got $ret"
144
145 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
146 exit $RESULT
147 }
148
149 service_exists $TEST_SERVICE
150 [[ $? -ne 0 ]] && {
151 echo "--DIAG: [${assertion}]
152 service $TEST_SERVICE should exist in repository but does not"
153
154 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
155 exit $RESULT
156 }
157
158 # Make sure that the instance transitions to online. This ensures
159 # that the state info in the export data will be consistent with the
160 # second export.
161 service_wait_state $TEST_SERVICE:$TEST_INSTANCE online 60
162 ret=$?
163 [[ $? -ne 0 ]] && {
164 echo "--DIAG: [${assertion}]
165 $TEST_SERVICE:$TEST_INSTANCE did not transition online as expected"
166
167 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
168 exit $RESULT
169 }
170
171 svccfg export $TEST_SERVICE > /tmp/export.$$.1
172
173 registration_template=$MYLOC/import_008.xml
174
175 # create a manifest with all the same data EXCEPT the value of one
176 # property should be different
177 manifest_generate $registration_template \
178 TEST_SERVICE=$TEST_SERVICE \
179 TEST_INSTANCE=$TEST_INSTANCE \
180 SERVICE_APP=$SERVICE_APP \
181 LOGFILE=$LOGFILE \
182 STATEFILE=$STATEFILE | sed 's/TESTDATA/foo_xx_bar/' >$registration_file
183
184
185 # Try to import the file again
186 svccfg import $registration_file > $OUTFILE 2>$ERRFILE
187 ret=$?
188 [[ $ret -ne 0 ]] && {
189 echo "--DIAG: [${assertion}]
190 svccfg import expected to return 0, got $ret"
191
192 RESULT=$STF_FAIL
193 }
194
195 # Verify that nothing in stdout - this is a non-fatal error
196 [[ -s $OUTFILE ]] && {
197 echo "--DIAG: [${assertion}]
198 stdout not expected, but got $(cat $OUTFILE)"
199
200 RESULT=$STF_FAIL
201 }
202
203 # Verify that nothing in sterr - this is a non-fatal error
204 [[ -s $ERRFILE ]] && {
205 echo "--DIAG: [${assertion}]
206 stderr not expected, but got $(cat $ERRFILE)"
207
208 RESULT=$STF_FAIL
209 }
210
211
212
213 svccfg export $TEST_SERVICE > /tmp/export.$$.2
214
215 diff /tmp/export.$$.1 /tmp/export.$$.2 | egrep -s foo_xx_bar
216 [[ $ret -ne 0 ]] && {
217 echo "--DIAG: [${assertion}]
218 repository unexpectedly changed after 2nd import.
219 The difference between the first and second import is:
220 $(diff /tmp/export.$$.1 /tmp/export.$$.2)"
221
222 RESULT=$STF_FAIL
223 }
224
225 rm -f $ERRFILE $OUTFILE /tmp/export.$$.?
226 exit $RESULT