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_003
32 #
33 # DESCRIPTION:
34 # Calling the "import file" subcommand where the file contains a
35 # service profile will result in a diagnostic message being sent
36 # to stderr and the command exiting with an exit status of 1.
37 #
38 # end __stf_assertion__
39 ###############################################################################
40
41
42 # First STF library
43 . ${STF_TOOLS}/include/stf.kshlib
44
45 # Load GL library
46 . ${STF_SUITE}/include/gltest.kshlib
47
48 # Load svc.startd library for manifest_generate
49 . ${STF_SUITE}/include/svc.startd_config.kshlib
50
51 readonly ME=$(whence -p ${0})
52 readonly MYLOC=$(dirname ${ME})
53
54 assertion=svccfg_import_003
55
56 # extract and print assertion information from this source script.
57 extract_assertion_info $ME
58
59 # Initialize test result
60 typeset -i RESULT=$STF_PASS
61
62
63 function cleanup {
64
65
66 rm -f $OUTFILE $ERRFILE $profile_file
67
68 exit $RESULT
69 }
70
71 trap cleanup 0 1 2 15
72
73 # make sure that the environment is sane - svc.configd is up and running
74 check_gl_env
75 [[ $? -ne 0 ]] && {
76 echo "--DIAG:
77 Invalid test environment - svc.configd not available"
78
79 RESULT=$STF_UNRESOLVED
80 exit $RESULT
81 }
82
83 # Before starting make sure that the test service doesn't already exist.
84 # If it does then consider it a fatal error.
85
86 service_exists $TEST_SERVICE
87 ret=$?
88 [[ $ret -eq 0 ]] && {
89 echo "--DIAG: [${assertion}]
90 service $TEST_SERVICE should not exist in
91 repository but does"
92
93 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
94 exit $RESULT
95 }
96
97 # Make sure that no instances of the test service are running. This
98 # is to ensure that the subsequent pgrep used to verify the assertion
99 # does not falsely fail.
100 #
101 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
102 ret=$?
103 [[ $ret -eq 0 ]] && {
104 echo "--DIAG: [${assertion}]
105 an instance of $(basename $SERVICE_APP) is running but should not be
106 to ensure correct validation of this test"
107
108 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
109 exit $RESULT
110 }
111
112
113 # # Start assertion testing
114 #
115
116 readonly profile_template=$MYLOC/import_003_profile.xml
117 readonly profile_file=/tmp/import_003_profile.xml
118
119
120 manifest_generate $profile_template \
121 TEST_SERVICE=$TEST_SERVICE \
122 TEST_INSTANCE=$TEST_INSTANCE | sed 's/ENABLE_VALUE/true/' >$profile_file
123
124
125 svccfg import $profile_file > $OUTFILE 2>$ERRFILE
126 ret=$?
127 [[ $ret -ne 1 ]] && {
128 echo "--DIAG: [${assertion}]
129 svccfg import expected to return 1, got $ret"
130
131 RESULT=$STF_FAIL
132 }
133
134
135 # Verify that nothing in stdout - this is a non-fatal error
136 [[ -s $OUTFILE ]] && {
137 echo "--DIAG: [${assertion}]
138 stdout not expected, but got $(cat $OUTFILE)"
139
140 RESULT=$STF_FAIL
141 }
142
143
144 # Verify that a message is sent to stderr
145 if ! egrep -s "$NOT_MANIFEST_ERRMSG" $ERRFILE
146 then
147 echo "--DIAG: [${assertion}]
148 Expected error message \"$NOT_MANIFEST_ERRMSG\"
149 but got \"$(cat $ERRFILE)\""
150
151 TEST_RESULT=$STF_FAIL
152 fi
153
154
155 exit $RESULT