1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26
27 ISCSI_INITIATOR_SMF="network/iscsi/initiator"
28 ISCSI_INITIATOR_MANIFEST="/lib/svc/manifest/network/iscsi/iscsi-initiator.xml"
29
30 #
31 # NAME
32 # iscsi_initiator_smf_enable
33 #
34 # SYNOPSIS
35 # iscsi_initiator_smf_enable
36 #
37 # DESCRIPTION:
38 # This function executes enable method for testing.
39 #
40 # ARGUMENT
41 # $1 - host name
42 #
43 # RETURN
44 # Set the result code if an exception is encountered
45 # void
46 #
47 function iscsi_initiator_smf_enable
48 {
49 typeset host_name=$1
50 iscsi_initiator_smf_snap $host_name
51 CMD="$SVCADM enable -rs $ISCSI_INITIATOR_SMF"
52 cti_report "Executing: $CMD"
53 run_rsh_cmd $host_name "$CMD"
54 if [ `get_cmd_retval` -ne 0 ];then
55 report_err "$CMD"
56 cti_fail "FAIL - $ISCSI_INITIATOR_SMF smf service can NOT be enabled"
57 return
58 fi
59 verify_iscsi_initiator_enable $host_name
60 if [ $? -eq 0 ];then
61 cti_pass "$ISCSI_INITIATOR_SMF smf enable method testing passed."
62 else
63 cti_fail "FAIL - $ISCSI_INITIATOR_SMF smf enable method testing failed."
64 fi
65 }
66 #
67 # NAME
68 # iscsi_initiator_smf_disable
69 #
70 # SYNOPSIS
71 # iscsi_initiator_smf_disable
72 #
73 # DESCRIPTION:
74 # This function executes disable method for testing.
75 #
76 # ARGUMENT
77 # $1 - host name
78 #
79 # RETURN
80 # Set the result code if an exception is encountered
81 # void
82 #
83 function iscsi_initiator_smf_disable
84 {
85 typeset host_name=$1
86 iscsi_initiator_smf_snap $host_name
87 CMD="$SVCADM disable -s $ISCSI_INITIATOR_SMF"
88 cti_report "Executing: $CMD"
89 run_rsh_cmd $host_name "$CMD"
90 if [ `get_cmd_retval` -ne 0 ];then
91 report_err "$CMD"
92 cti_fail "FAIL - $ISCSI_INITIATOR_SMF smf service can NOT be disabled"
93 return
94 fi
95 verify_iscsi_initiator_disable $host_name
96 if [ $? -eq 0 ];then
97 cti_pass "$ISCSI_INITIATOR_SMF smf disable method testing passed."
98 else
99 cti_fail "FAIL - $ISCSI_INITIATOR_SMF smf disable method testing failed."
100 fi
101 }
102
103 #
104 # NAME
105 # iscsi_initiator_smf_snap
106 #
107 # SYNOPSIS
108 # iscsi_initiator_smf_snap
109 #
110 # DESCRIPTION:
111 # This function save the timestamp into temporary variables.
112 #
113 # ARGUMENT
114 # $1 - host name
115 #
116 # RETURN
117 # void
118 #
119 function iscsi_initiator_smf_snap
120 {
121 typeset host_name=$1
122 typeset CMD="$SVCS | grep $ISCSI_INITIATOR_SMF | \
123 grep -v grep | awk '{print \$2}'"
124 run_rsh_cmd $host_name "$CMD"
125 if [ `get_cmd_retval` -ne 0 ];then
126 report_err "$CMD"
127 cti_fail "FAIL - can not list the $ISCSI_INITIATOR_SMF smf service information"
128 return
129 fi
130 ISCSI_INITIATOR_SMF_START_TIME=`get_cmd_stdout`
131 }
132
133
134 #
135 # NAME
136 # verify_iscsi_initiator_enable
137 # DESCRIPTION
138 # Verify that the iscsi_initiator enable operation successfully or not.
139 #
140 # ARGUMENT
141 # $1 - host name
142 #
143 # RETURN
144 # Sets the result code
145 # 0 - iscsi_initiator enable operation succeed
146 # 1 - iscsi_initiator enable operation fail
147 function verify_iscsi_initiator_enable
148 {
149 typeset host_name=$1
150 typeset CMD="$SVCS | grep $ISCSI_INITIATOR_SMF | \
151 grep -v grep | grep online | awk '{print \$2}'"
152 run_rsh_cmd $host_name "$CMD"
153 if [ `get_cmd_retval` -ne 0 ];then
154 report_err "$CMD"
155 cti_fail "FAIL - can not list the $ISCSI_INITIATOR_SMF smf service information"
156 return 1
157 fi
158 ISCSI_INITIATOR_SMF_CURRENT_TIME=`get_cmd_stdout`
159 if [ -z "$ISCSI_INITIATOR_SMF_START_TIME" ];then
160 if [ -n "$ISCSI_INITIATOR_SMF_CURRENT_TIME" ];then
161 cti_report "PASS - svcadm enable $ISCSI_INITIATOR_SMF passed from disable to enable."
162 return 0
163 else
164 cti_report "FAIL - $ISCSI_INITIATOR_SMF smf is not started/online (enable)."
165 return 1
166 fi
167 elif [ -n "$ISCSI_INITIATOR_SMF_START_TIME" ];then
168 if [ "$ISCSI_INITIATOR_SMF_CURRENT_TIME" = "$ISCSI_INITIATOR_SMF_START_TIME" ];then
169 cti_report "PASS - svcadm enable $ISCSI_INITIATOR_SMF passed from enable to enable."
170 return 0
171 else
172 cti_report "FAIL - $ISCSI_INITIATOR_SMF smf is restarted/online (enable)."
173 return 1
174 fi
175 else
176 cti_report "FAIL - $ISCSI_INITIATOR_SMF smf is invalid (enable)."
177 return 1
178 fi
179 }
180
181 #
182 # NAME
183 # verify_iscsi_initiator_disable
184 # DESCRIPTION
185 # Verify that the iscsi_initiator disable operation successfully or not.
186 #
187 # ARGUMENT
188 # $1 - host name
189 #
190 # RETURN
191 # Sets the result code
192 # 0 - iscsi_initiator disable operation succeed
193 # 1 - iscsi_initiator disable operation fail
194 function verify_iscsi_initiator_disable
195 {
196 typeset host_name=$1
197 typeset CMD="$SVCS | grep $ISCSI_INITIATOR_SMF | \
198 grep -v grep | grep online | awk '{print \$2}'"
199 run_rsh_cmd $host_name "$CMD"
200 if [ `get_cmd_retval` -ne 0 ];then
201 report_err "$CMD"
202 cti_fail "FAIL - can not list the $ISCSI_INITIATOR_SMF smf service information"
203 return 1
204 fi
205 ISCSI_INITIATOR_SMF_CURRENT_TIME=`get_cmd_stdout`
206 if [ -z "$ISCSI_INITIATOR_SMF_CURRENT_TIME" ];then
207 if [ -n "$ISCSI_INITIATOR_SMF_START_TIME" ];then
208 cti_report "PASS - svcadm enable $ISCSI_INITIATOR_SMF passed "\
209 "from enable to disable."
210 return 0
211 else
212 cti_report "PASS - svcadm disable $ISCSI_INITIATOR_SMF passed"\
213 "from disable to disable."
214 return 0
215 fi
216 else
217 cti_report "FAIL - $ISCSI_INITIATOR_SMF service is not stopped after disable.."
218 return 1
219 fi
220 }
221