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 #
30 # Attempt to import the manifest, collecting any output
31 # produced. If there is no second argument there should
32 # be no error output, and the file should import without
33 # complaint. If there is a second argument this is the
34 # list of errors that should be recognized anything additional
35 # is considered a failure.
36 #
37
38 # First STF library
39 . ${STF_TOOLS}/include/stf.kshlib
40
41 #
42 # Error message translations
43 #
44 SCF_TERR_MISSING_PG="Required property group missing"
45 SCF_TERR_WRONG_PG_TYPE="Property group has bad type"
46 SCF_TERR_MISSING_PROP="Required property missing"
47 SCF_TERR_WRONG_PROP_TYPE="Property has bad type"
48 SCF_TERR_CARDINALITY_VIOLATION="Number of property values violates cardinality restriction"
49 SCF_TERR_VALUE_CONSTRAINT_VIOLATED="Property has illegal value"
50 SCF_TERR_RANGE_VIOLATION="Property value is out of range"
51 SCF_TERR_PROP_TYPE_MISMATCH="Properyt type and value type mismatch"
52 SCF_TERR_VALUE_OUT_OF_RANGE="Value is out of range"
53 SCF_TERR_INVALID_VALUE="Value is not valid"
54 ERR_UNIQUE_NAME_TYPE="pg_pattern with name .*. and type .*. is not unique"
55 ERR_UNIQUE_NAME="pg_pattern with name .*. and empty type is not unique"
56 ERR_UNIQUE_TYPE="pg_pattern with empty name and type .*. is not unique"
57
58 function verify_import {
59 ret=$1
60
61 if [ $2 ]
62 then
63 exec 3<$2
64
65 cnt=0;
66 cp $ERRFILE /tmp/scfvtesterrfile.$$
67 while read -u3 line
68 do
69 eval grep "\"\$${line}\"" \$ERRFILE
70 if [ $? -eq 0 ]; then
71 cnt=`expr $cnt + 1`
72 #
73 # Now remove that line
74 # so that subsequent checks
75 # do not find that line
76 #
77 eval myl="\$${line}"
78 LNUM=`grep -n "$myl" $ERRFILE | \
79 head -1 | awk -F: '{print $1}'`
80 eval sed -e '${LNUM}d' $ERRFILE > ${ERRFILE}.tmp
81 mv ${ERRFILE}.tmp $ERRFILE
82 fi
83 done
84 trueerrcnt=`wc -l $2 | awk '{print $1}'`
85 if [ $cnt -ne $trueerrcnt ]
86 then
87 echo "--DIAG: import did not produce the \c"
88 echo "correct messages cnt = $cnt " \
89 "trueerrcnt = $trueerrcnt"
90
91 echo "------------- ERROR OUTPUT --------------------"
92 cat /tmp/scfvtesterrfile.$$
93 echo "-----------------------------------------------"
94 RESULT=$STF_FAIL
95 fi
96 rm -f /tmp/scfvtesterrfile.$$
97 else
98 if [ $ret -ne 0 ]
99 then
100 echo "-- DIAG: " \
101 "svccfg import expected to return 0, got $ret"
102
103 echo "$OUTFILE :"
104 cat $OUTFILE
105 echo "$ERRFILE :"
106 cat $ERRFILE
107
108 RESULT=$STF_FAIL
109 else
110 errcnt=`wc -l $ERRFILE | awk '{print $1}'`
111 if [ $errcnt -gt 0 ]
112 then
113 echo "--DIAG: unexpected error messages \c"
114 echo "were generated"
115
116 echo "$ERRFILE :"
117 cat $ERRFILE
118
119 RESULT=$STF_FAIL
120 fi
121 fi
122 fi
123 }
124
125 # Initialize test result
126 typeset -i RESULT=$STF_PASS
127 typeset fmri=$1
128 typeset errfile=$2
129
130 #
131 # Dump the manifest with the expected errors if any.
132 #
133 echo "--INFO: Import the following manifest :"
134 echo "----------------------------------------------------------"
135 cat "$fmri"
136 echo "----------------------------------------------------------"
137 if [ $errfile ]; then
138 if [ `wc -l $errfile | awk '{print $1}'` -gt 1 ]; then
139 e="errors"
140 else
141 e="error"
142 fi
143 echo "--INFO: The following $e is expected."
144 echo "----------------------------------------------------------"
145 exec 3<$errfile
146 while read -u3 line
147 do
148 eval echo "\$${line}"
149 done
150 echo "----------------------------------------------------------"
151 fi
152
153
154 svcname=`grep "service name" $1 | awk '{print $2}' | awk -F= '{print $2}' | \
155 sed -e s/\'//g`
156 echo "svccfg import $fmri"
157 svccfg import $fmri >$OUTFILE 2>$ERRFILE
158 iret=$?
159
160 echo "--INFO: Verify the import"
161 verify_import $iret $errfile
162
163 if [ $iret -ne 0 ]
164 then
165 exit $RESULT
166 fi
167
168 svccfg validate ${svcname}:default >$OUTFILE 2>$ERRFILE
169 vret=$?
170
171 echo "--INFO: Verify the validate"
172 verify_import $vret $errfile
173
174 svccfg delete $svcname
175
176 exit $RESULT