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_inventory_003
32 #
33 # DESCRIPTION:
34 # Calling the 'inventory file' subcommand, where file is
35 # a service archive or profile will result in a diagnostic
36 # message displayed on stderr. The exit status will be 1.
37 #
38 # end __stf_assertion__
39 ###############################################################################
40
41
42 # First STF library
43 . ${STF_TOOLS}/include/stf.kshlib
44
45 # Load GL library
46 . ${STF_SUITE}/include/gltest.kshlib
47
48 # Load svc.startd library
49 . ${STF_SUITE}/include/svc.startd_config.kshlib
50
51 readonly ME=$(whence -p ${0})
52 readonly MYLOC=$(dirname ${ME})
53
54 assertion=svccfg_inventory_003
55
56 # Initialize test result
57 typeset -i RESULT=$STF_PASS
58
59 function cleanup {
60 # Note that $TEST_SERVICE may not exist. So don't check
61 # reslts. Just make sure the service is gone
62
63 manifest_purgemd5 $manifest_file
64
65 rm -f $OUTFILE $ERRFILE $manifest_file $archive_file
66 }
67
68 trap cleanup 0 1 2 15
69
70 # make sure that the environment is sane -- svc.configd is up and running
71 check_gl_env
72 [[ $? -ne 0 ]] && {
73 echo "--DIAG:
74 Invalid test environment - svc.configd not available"
75
76 RESULT=$STF_UNRESOLVED
77 exit $RESULT
78 }
79
80 # Extract and print assertion information from this source script
81 extract_assertion_info $ME
82
83 # Before starting, make sure that the test service doesn't already exist.
84 # If it does, then consider it a fatal error. This also mean the previous
85 # test did not successfully clean up after itself
86 #
87 service_exists $TEST_SERVICE
88 ret=$?
89 [[ $ret -eq 0 ]] && {
90 echo "--DIAG: [${assertion}]
91 service $TEST_SERVICE should not exist in
92 repository but does"
93
94 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
95 exit $RESULT
96 }
97
98 # Make sure that no instances of the test service are running. This
99 # is to ensure that the subsequent pgrep used to verify the assertion
100 # does not falsely fail.
101 #
102 pgrep -z $(zonename) $(basename $SERVICE_APP) > /dev/null 2>&1
103 ret=$?
104 [[ $ret -eq 0 ]] && {
105 echo "--DIAG: [${assertion}]
106 an instance of $(basename $SERVICE_APP) is running but should not be
107 to ensure correct validation of this test"
108
109 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
110 exit $RESULT
111 }
112
113
114 # # Start assertion testing
115 #
116 readonly archive_file=$PWD/svccfg_archive.xml
117 readonly manifest_file=$archive_file
118
119 manifest_purgemd5 $manifest_file
120
121 # Create an svccfg archive file from the current contents of the repository
122 #
123 echo "--INFO: Create an svccfg archive file from current repository contents"
124 svccfg archive > $archive_file 2>&1
125 ret=$?
126 if [[ $ret -ne 0 ]]; then
127 echo "--DIAG: [${assertion}]
128 'svccfg archive' failed to generate proper archives
129 EXPECTED: command exitcode 0
130 RETURNED: command exitcode $ret"
131 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
132 exit $RESULT
133 fi
134
135 # Now verify the assertion
136 echo "--INFO: Now attempt to inventory the generated svccfg archive.
137 Expect failure."
138
139 svccfg inventory $manifest_file > $OUTFILE 2>$ERRFILE
140 ret=$?
141 [[ $ret -ne 1 ]] && {
142 echo "--DIAG: [$assertion]
143 'svccfg inventory' did not fail as expected with an archive file
144 EXPECTED: command exitcode 1
145 RETURNED: command exitcode $ret"
146
147 RESULT=$STF_FAIL
148 }
149
150 # Verify that there's nothing in stdout
151 [[ -s $OUTFILE ]] && {
152 echo "--DIAG: $assertion
153 stdout not expected, but got $(cat $OUTFILE)"
154
155 RESULT=$STF_FAIL
156 }
157
158 # Verify that stderr is not empty
159 [[ ! -s $ERRFILE ]] && {
160 echo "--DIAG: $assertion
161 Expected error output to stderr, but got nothing"
162
163 RESULT=$STF_FAIL
164 }
165
166 # Verify that stderr contains the expected error message
167 if ! egrep -s "$NOT_MANIFEST_ERRMSG" $ERRFILE
168 then
169 echo "--DIAG: [${assertion}]
170 Expected error message \"$NOT_MANIFEST_ERRMSG\"
171 but got \"$(cat $ERRFILE)\""
172
173 RESULT=$STF_FAIL
174 fi
175
176 exit $RESULT