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_listpg_002
32 #
33 # DESCRIPTION:
34 # The 'listpg' subcommand lists all the property groups
35 # of the currently selected entity. The types and flags are also
36 # displayed.
37 #
38 # STRATEGY:
39 # Use the file pg_data which contains property group information
40 # that can be used both to add property group and also to compare
41 # the output of the listpg command.
42 #
43 # end __stf_assertion__
44 ###############################################################################
45
46
47 # First STF library
48 . ${STF_TOOLS}/include/stf.kshlib
49
50 # Load GL library
51 . ${STF_SUITE}/include/gltest.kshlib
52
53
54 readonly ME=$(whence -p ${0})
55 readonly MYLOC=$(dirname ${ME})
56
57
58 # Initialize test result
59 typeset -i RESULT=$STF_PASS
60
61
62 function cleanup {
63
64 # Note that $TEST_SERVICE may or may not exist so don't check
65 # results. Just make sure the service is gone.
66 service_delete $TEST_SERVICE
67
68 service_exists ${TEST_SERVICE}
69 [[ $? -eq 0 ]] && {
70 echo "--DIAG: [${assertion}, cleanup]
71 service ${TEST_SERVICE} should not exist in
72 repository after being deleted, but does"
73
74 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
75 }
76
77 rm -f $OUTFILE $ERRFILE $CMDFILE
78
79 exit $RESULT
80 }
81
82 function create_property_groups
83 {
84 entity=$1
85
86 echo "select $entity" >> $CMDFILE
87 cat $MYLOC/pg_data |
88 while read pg type flag
89 do
90 echo "addpg $pg $type $flag" >> $CMDFILE
91 done
92 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
93 ret=$?
94
95 # Verify that the return value is as expected - non-fatal error
96 [[ $ret -ne 0 ]] && {
97 echo "--DIAG: [${assertion}, test 1]
98 svccfg expected to return 0, got $ret
99 error output is $(cat $ERRFILE)"
100
101 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
102 exit $RESULT
103 }
104 }
105
106 trap cleanup 0 1 2 15
107
108 # make sure that the environment is sane - svc.configd is up and running
109 check_gl_env
110 [[ $? -ne 0 ]] && {
111 echo "--DIAG:
112 Invalid test environment - svc.configd is not available"
113
114 RESULT=$STF_UNRESOLVED
115 exit $RESULT
116 }
117
118 # extract and print assertion information from this source script.
119 extract_assertion_info $ME
120
121 assertion=svccfg_listpg_002
122
123
124 # Before starting make sure that the test service doesn't already exist.
125 # If it does then consider it a fatal error.
126 service_exists $TEST_SERVICE
127 [[ $? -eq 0 ]] && {
128 echo "--DIAG: [${assertion}, test 1]
129 service $TEST_SERVICE should not exist in
130 repository but does"
131
132 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
133 exit $RESULT
134 }
135
136
137 #
138 # Add the service. If this fails consider it a fatal error
139 #
140 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
141 ret=$?
142 [[ $ret -ne 0 ]] && {
143 echo "--DIAG: [${assertion}]
144 error adding service $TEST_SERVICE needed for test
145 error output is $(cat $ERRFILE)"
146
147 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
148 exit $RESULT
149 }
150
151 create_property_groups ${TEST_SERVICE}
152
153 cat << EOF > $CMDFILE
154 select ${TEST_SERVICE}
155 listpg
156 end
157 EOF
158
159 svccfg -f $CMDFILE > $OUTFILE 2>$ERRFILE
160 ret=$?
161
162 # Verify that the return value is as expected - non-fatal error
163 [[ $ret -ne 0 ]] && {
164 echo "--DIAG: [${assertion}, test 1]
165 svccfg expected to return 0, got $ret"
166
167 RESULT=$STF_FAIL
168 }
169
170
171 # Verify that nothing in stderr - non-fatal error
172 [[ -s $ERRFILE ]] && {
173 echo "--DIAG: [${assertion}, test 1]
174 stderr not expected, but got $(cat $ERRFILE)"
175
176 RESULT=$STF_FAIL
177 }
178
179 # Verify the output
180
181 lines_1=$(wc -l $MYLOC/pg_data | awk '{print $1}')
182 lines_2=$(wc -l $OUTFILE | awk '{print $1}')
183 [[ $lines_1 -ne $lines_2 ]] &&
184 RESULT=$STF_FAIL
185
186 cat $MYLOC/pg_data |
187 while read pg type flag
188 do
189 set $(grep "^$pg " $OUTFILE) > /dev/null 2>&1
190 pg_cmp=$1
191 type_cmp=$2
192 flag_cmp=$3
193
194 case $flag in
195 "P") flag=NONPERSISTENT;;
196 "p") flag= ;;
197 esac
198
199 [[ "$pg_cmp" != "$pg" ]] && RESULT=$STF_FAIL
200 [[ "$type_cmp" != "$type" ]] && RESULT=$STF_FAIL
201 [[ "$flag_cmp" != "$flag" ]] && RESULT=$STF_FAIL
202 done
203
204
205 [[ $RESULT -eq $STF_FAIL ]] && {
206
207 echo "--DIAG: An error was found with the listpg command"
208 echo "--DIAG: Here\'s the output of the listpg command:
209 $(cat $OUTFILE)"
210
211 echo "--DIAG: Here\'s the expected output:
212 $(cat $MYLOC/pg_data)"
213 }
214
215 rm -f $ERRFILE $OUTFILE $CMDFILE
216
217 print_result $RESULT
218
219 exit $RESULT