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_addpg_003
32 #
33 # DESCRIPTION:
34 # The 'addpg name type [flags]' subcommand adds a property
35 # group of name 'name' and type 'type' to the currently
36 # selected entity. If the flags argument is set to some
37 # value other than "H" or "h" then it is considered invalid
38 # and a diagnostic message is sent to stderr and the return
39 # status is set to 1. Invalid values of "flags" should
40 # include: character value, string values, non-terminated
41 # strings (e.g. "abc), integer values.
42 #
43 #
44 # STRATEGY:
45 # This assertion tests that invalid flags are handled correctly.
46 # A series of invalid flags are passed and the result from each
47 # invocation of svccfg are inspected.
48 #
49 # This assertion is verified on a service pg only (not a service
50 # instance pg also)
51 #
52 # end __stf_assertion__
53 ###############################################################################
54
55
56 # First STF library
57 . ${STF_TOOLS}/include/stf.kshlib
58
59 # Load GL library
60 . ${STF_SUITE}/include/gltest.kshlib
61
62
63 readonly ME=$(whence -p ${0})
64 readonly MYLOC=$(dirname ${ME})
65
66 # Initialize test result
67 typeset -i RESULT=$STF_PASS
68
69
70 function cleanup {
71
72 # Note that $TEST_SERVICE may or may not exist so don't check
73 # results. Just make sure the service is gone.
74 service_delete $TEST_SERVICE > /dev/null 2>&1
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 $OUTFILE $ERRFILE $CMDFILE
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 - recache not available"
97
98
99 RESULT=$STF_UNRESOLVED
100 exit $RESULT
101 }
102
103 # extract and print assertion information from this source script.
104 extract_assertion_info $ME
105
106 assertion=svccfg_addpg_003
107
108 typeset -i test_id=0
109
110 # Before starting make sure that the test service doesn't already exist.
111 # If it does then consider it a fatal error.
112 service_exists $TEST_SERVICE
113 [[ $? -eq 0 ]] && {
114 echo "--DIAG: [${assertion}, test 1]
115 service $TEST_SERVICE should not exist in repository but does"
116
117 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
118 exit $RESULT
119 }
120
121
122 #
123 # Add the service. If this fails consider it a fatal error
124 #
125 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
126 ret=$?
127 [[ $ret -ne 0 ]] && {
128 echo "--DIAG: [${assertion}]
129 error adding service $TEST_SERVICE needed for test
130 error output is $(cat $ERRFILE)"
131
132 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
133 exit $RESULT
134 }
135
136
137 for pgflag in abc 123 \"\" \"abc HI J
138 do
139
140 typeset -i TEST_RESULT=$STF_PASS
141 echo "--INFO: Starting $assertion, test $test_id ($pgflag flag)"
142 ((test_id = test_id + 1))
143
144 THIS_PROPERTY=${TEST_PROPERTY}_$pgflag
145
146 #
147 # Add a property group to the service
148 #
149 cat << EOF >$CMDFILE
150 select ${TEST_SERVICE}
151 addpg ${THIS_PROPERTY} astring $pgflag
152 EOF
153
154 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
155 ret=$?
156
157 # Verify that the return value is as expected - non-fatal error
158 [[ $ret -eq 0 ]] && {
159 echo "--DIAG: [${assertion}, test $test_id]
160 svccfg expected to return 1, got $ret"
161
162 TEST_RESULT=$STF_FAIL
163 }
164
165 # Verify that nothing in stdout - non-fatal error
166 [[ -s $OUTFILE ]] && {
167 echo "--DIAG: [${assertion}, test $test_id]
168 stdout not expected, but got $(cat $OUTFILE)"
169
170 TEST_RESULT=$STF_FAIL
171 }
172
173 # Verify that message in stderr - non-fatal error
174 [[ ! -s $ERRFILE ]] && {
175 echo "--DIAG: [${assertion}, test $test_id]
176 message in stderr expected, but got nothing"
177
178 TEST_RESULT=$STF_FAIL
179 }
180
181 #
182 # Check that the property group exists - fatal error
183 #
184 svcprop -p $THIS_PROPERTY $TEST_SERVICE > /dev/null 2>&1
185 ret=$?
186 [[ $ret -eq 0 ]] && {
187 echo "--DIAG: [${assertion}, test $test_id]
188 property group $THIS_PROPERTY does not exist"
189
190 TEST_RESULT=$STF_FAIL
191 }
192
193
194 rm -f $ERRFILE $OUTFILE $CMDFILE
195
196 print_result $TEST_RESULT
197 RESULT=$(update_result $TEST_RESULT $RESULT)
198 done
199
200 exit $RESULT