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_005
32 #
33 # DESCRIPTION:
34 # The 'add' subcommand accepts one argument - the name of a new
35 # entity. If no arguments or more than one argument are
36 # given than a diagnostic message is sent to stderr and an exit
37 # status of 1 is returned.
38 #
39 # STRATEGY:
40 # Check the two tests of this assertions:
41 #
42 # 1) calling 'add' with no arguments.
43 #
44 # 2) calling 'add' with more than one argument.
45 #
46 # For both tests check that nothng printed on stdout, message on
47 # stderr and a return value of 1.
48 #
49 #
50 # end __stf_assertion__
51 ###############################################################################
52
53
54 # First STF library
55 . ${STF_TOOLS}/include/stf.kshlib
56
57 # Load GL library
58 . ${STF_SUITE}/include/gltest.kshlib
59
60
61 readonly ME=$(whence -p ${0})
62 readonly MYLOC=$(dirname ${ME})
63
64 # Initialize test result
65 typeset -i RESULT=$STF_PASS
66
67 function cleanup {
68
69 rm -f $OUTFILE $ERRFILE $CMDFILE
70 }
71
72 trap cleanup 0 1 2 15
73
74 # make sure that the environment is sane - svc.configd is up and running
75 check_gl_env
76 [[ $? -ne 0 ]] && {
77 echo "--DIAG: [$assertion]
78 Invalid test environment - svc.configd not available"
79
80 RESULT=$STF_UNRESOLVED
81 exit $RESULT
82 }
83
84 # extract and print assertion information from this source script.
85 extract_assertion_info $ME
86
87 # Assertion ID
88 readonly assertion=svccfg_add_005
89
90 #
91 # Test #1: "svccfg add" no arguments
92 #
93
94 echo "--INFO: Starting $assertion, test 1 (svccfg add)"
95
96 typeset -i TEST_RESULT=$STF_PASS
97
98 svccfg add > $OUTFILE 2>$ERRFILE
99
100 ret=$?
101
102 # Verify that the return value is as expected - this is a non-fatal error
103 [[ $ret -ne 1 ]] && {
104 echo "--DIAG: [${assertion}, test 1]
105 svccfg expected to return 1, got $ret"
106
107 TEST_RESULT=$STF_FAIL
108 }
109
110 # Verify that nothing in stdout - this is a non-fatal error
111 [[ -s $OUTFILE ]] && {
112 echo "--DIAG: [${assertion}, test 1]
113 stdout not expected, but got $(cat $OUTFILE)"
114
115 TEST_RESULT=$STF_FAIL
116 }
117
118 # Verify that a message is sent to stderr
119 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
120 then
121 echo "--DIAG: [${assertion}, test 1]
122 Expected error message \"$SYNTAX_ERRMSG\"
123 but got \"$(cat $ERRFILE)\""
124
125 TEST_RESULT=$STF_FAIL
126 fi
127
128 rm -f $ERRFILE $OUTFILE
129
130 print_result $TEST_RESULT
131 RESULT=$(update_result $TEST_RESULT $RESULT)
132
133 #
134 # Test #2: more than one argument
135 #
136
137 echo "--INFO: Starting $assertion, test 2 (more than one arg)"
138 typeset -i TEST_RESULT=$STF_PASS
139
140 # Verify that service is not in the repository
141 service_exists ${NEW_ENTITY}
142 [[ $? -eq 0 ]] && {
143 echo "--DIAG: [${assertion}, test 2]
144 service ${NEW_ENTITY} should not be in the
145 repository as a pre-test of the test"
146
147 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
148 exit $RESULT
149
150 }
151
152 cat <<EOF >$CMDFILE
153 add ${NEW_ENTITY} extra_option
154 EOF
155
156 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
157 ret=$?
158
159 # Verify that the return value is as expected
160 [[ $ret -eq 0 ]] && {
161 echo "--DIAG: [${assertion}, test 2]
162 svccfg expected to return 1, got $ret"
163
164 RESULT=$STF_FAIL
165 }
166
167 # Verify that nothing in stdout
168 [[ -s $OUTFILE ]] && {
169 echo "--DIAG: [${assertion}, test 2]
170 stdout not expected, but got $(cat $OUTFILE)"
171
172 TEST_RESULT=$STF_FAIL
173 }
174
175
176 # Verify that a message is sent to stderr
177 if ! egrep -s "$SYNTAX_ERRMSG" $ERRFILE
178 then
179 echo "--DIAG: [${assertion}, test 2]
180 Expected error message \"$SYNTAX_ERRMSG\"
181 but got \"$(cat $ERRFILE)\""
182
183 TEST_RESULT=$STF_FAIL
184 fi
185
186 # Verify that entity was not added
187 service_exists ${NEW_ENTITY}
188 [[ $? -eq 0 ]] && {
189 echo "--DIAG: [${assertion}, test 2]
190 service ${NEW_ENTITY} was unexpectedly added to repository."
191
192 TEST_RESULT=$STF_FAIL
193 }
194
195
196 print_result $TEST_RESULT
197 RESULT=$(update_result $TEST_RESULT $RESULT)
198
199 exit $RESULT