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_007
32 #
33 # DESCRIPTION:
34 # Entity added through the 'add' subcommand is relative to the
35 # current entity. Passing multi-level entities is not allowed
36 # (e.g svccfg add service_name:instance_name).
37 #
38 #
39 # STRATEGY:
40 # For this test we'll attempt to add an instance from the top-level
41 # scope with an absolute path (e.g. add "service:instance:")
42 #
43 #
44 # end __stf_assertion__
45 ###############################################################################
46
47
48 # First STF library
49 . ${STF_TOOLS}/include/stf.kshlib
50
51 # Load GL library
52 . ${STF_SUITE}/include/gltest.kshlib
53
54
55 readonly ME=$(whence -p ${0})
56 readonly MYLOC=$(dirname ${ME})
57
58 # Initialize test result
59 typeset -i RESULT=$STF_PASS
60
61
62 function cleanup {
63 # Note that $TEST_SERVICE may or may not exist so don't check
64 # results. Just make sure the service is gone.
65 service_delete $TEST_SERVICE
66
67 service_exists ${TEST_SERVICE}
68 [[ $? -eq 0 ]] && {
69 echo "--DIAG: [${assertion}, cleanup]
70 service ${TEST_SERVICE} should not exist in
71 repository after being deleted, but does"
72
73 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
74 }
75
76 rm -f $OUTFILE $ERRFILE $CMDFILE
77
78 exit $RESULT
79 }
80
81 trap cleanup 0 1 2 15
82
83 # make sure that the environment is sane - svc.configd is up and running
84 check_gl_env
85 [[ $? -ne 0 ]] && {
86 echo "--DIAG:
87 Invalid test environment - svc.configd is not available"
88
89 RESULT=$STF_UNRESOLVED
90 exit $RESULT
91 }
92
93 # extract and print assertion information from this source script.
94 extract_assertion_info $ME
95
96 assertion=svccfg_add_007
97
98 # Before starting make sure that the test service doesn't already exist.
99 # If it does then consider it a fatal error.
100 service_exists $TEST_INSTANCE
101 [[ $? -eq 0 ]] && {
102 echo "--DIAG: [${assertion}, test 1]
103 service $TEST_SERVICE should not exist in
104 repository but does"
105
106 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
107 exit $RESULT
108 }
109
110 #
111 # Add the service. If this fails consider it a fatal error
112 #
113 svccfg add $TEST_SERVICE > $OUTFILE 2>$ERRFILE
114 ret=$?
115 [[ $ret -ne 0 ]] && {
116 echo "--DIAG: [${assertion}]
117 error adding service $TEST_SERVICE needed for test
118 error output is $(cat $ERRFILE)"
119
120 RESULT=$(update_result $STF_UNRESOLVED $RESULT)
121 exit $RESULT
122 }
123
124 # Start the test
125 svccfg add $TEST_SERVICE_FMRI:${TEST_INSTANCE}> $OUTFILE 2>$ERRFILE
126 ret=$?
127 [[ $ret -ne 1 ]] && {
128 echo "--DIAG: [${assertion}]
129 svccfg expected to return 1, got $ret"
130
131 RESULT=$STF_FAIL
132 }
133
134 # Verify that nothing in stdout - this is a non-fatal error
135 [[ -s $OUTFILE ]] && {
136 echo "--DIAG: [${assertion}]
137 stdout not expected, but got $(cat $OUTFILE)"
138
139 RESULT=$STF_FAIL
140 }
141
142 # Verify that a message is sent to stderr
143 if ! egrep -s "$INVALID_NAME_ERRMSG" $ERRFILE
144 then
145 echo "--DIAG: [${assertion}]
146 Expected error message \"$INVALID_NAME_ERRMSG\"
147 but got \"$(cat $ERRFILE)\""
148
149 RESULT=$STF_FAIL
150 fi
151
152 exit $RESULT
153