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_add_006
32 #
33 # DESCRIPTION:
34 # Attempting to add an entity to an instance will result in
35 # a diagnostic message is sent to stderr and an exit status of 1
36 # is returned.
37 #
38 # STRATEGY:
39 #
40 #
41 # end __stf_assertion__
42 ###############################################################################
43
44
45 # First STF library
46 . ${STF_TOOLS}/include/stf.kshlib
47
48 # Load GL library
49 . ${STF_SUITE}/include/gltest.kshlib
50
51 readonly ME=$(whence -p ${0})
52 readonly MYLOC=$(dirname ${ME})
53
54 # Initialize test result
55 typeset -i RESULT=$STF_PASS
56
57
58 function cleanup {
59
60 # Note that $TEST_SERVICE may or may not exist so don't check
61 # results. Just make sure the service is gone.
62 service_delete $TEST_SERVICE
63
64 service_exists ${TEST_SERVICE}
65 [[ $? -eq 0 ]] && {
66 echo "--DIAG: [${assertion}, cleanup]
67 service ${TEST_SERVICE} should not exist in
68 repository after being deleted, but does"
69
70 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
71 }
72
73 rm -f $OUTFILE $ERRFILE $CMDFILE
74
75 exit $RESULT
76 }
77
78 trap cleanup 0 1 2 15
79
80 # make sure that the environment is sane - svc.configd is up and running
81 check_gl_env
82 [[ $? -ne 0 ]] && {
83 echo "--DIAG:
84 Invalid test environment - svc.configd is not available"
85
86 RESULT=$STF_UNRESOLVED
87 exit $RESULT
88 }
89
90 # extract and print assertion information from this source script.
91 extract_assertion_info $ME
92
93 assertion=svccfg_add_006
94
95 # Before starting make sure that the test service doesn't already exist.
96 # If it does then consider it a fatal error.
97 service_exists $TEST_INSTANCE
98 [[ $? -eq 0 ]] && {
99 echo "--DIAG: [${assertion}]
100 service $TEST_SERVICE should not exist in
101 repository but does"
102
103 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
104 exit $RESULT
105 }
106
107
108 #
109 # Add the service and instance. If this fails consider it a fatal
110 # error
111 #
112 cat << EOF >$CMDFILE
113 add ${TEST_SERVICE}
114 select ${TEST_SERVICE}
115 add ${TEST_INSTANCE}
116 EOF
117
118 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
119 ret=$?
120 [[ $ret -ne 0 ]] && {
121 echo "--DIAG: [${assertion}]
122 error adding service/instance ${TEST_SERVICE}:${TEST_INSTANCE} needed for test
123 error output is $(cat $ERRFILE)"
124
125 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
126 exit $RESULT
127 }
128
129 #
130 # Start assertion testing
131 #
132
133 #
134 # Attempt to add a entity of the instance
135 # error
136 #
137 cat << EOF >$CMDFILE
138 select ${TEST_SERVICE}
139 select ${TEST_INSTANCE}
140 add new_entity
141 EOF
142
143 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
144 ret=$?
145 [[ $ret -ne 1 ]] && {
146 echo "--DIAG: [${assertion}]
147 svccfg expected to return 1, got $ret"
148
149 RESULT=$STF_FAIL
150 }
151
152 # Verify that nothing in stdout - this is a non-fatal error
153 [[ -s $OUTFILE ]] && {
154 echo "--DIAG: [${assertion}]
155 stdout not expected, but got $(cat $OUTFILE)"
156
157 RESULT=$STF_FAIL
158 }
159
160 # Verify that a message is sent to stderr
161 if ! egrep -s "$ADD_ENTITIES_ERRMSG" $ERRFILE
162 then
163 echo "--DIAG: [${assertion}]
164 Expected error message \"$ADD_ENTITIES_ERRMSG\"
165 but got \"$(cat $ERRFILE)\""
166
167 RESULT=$STF_FAIL
168 fi
169
170 exit $RESULT