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 FCOE_SMF="system/fcoe_target"
28 FCOE_MANIFEST="/lib/svc/manifest/system/fcoe_target.xml"
29 FCOE_PORTLIST_PG="fcoe-port-list-pg"
30 FCOE_PORTLIST_PROPERTY="fcoe-port-list-pg/port_list_p"
31
32 #
33 # NAME
34 # fcoe_smf_enable
35 #
36 # SYNOPSIS
37 # fcoe_smf_enable
38 #
39 # DESCRIPTION:
40 # This function executes enable method for testing.
41 #
42 # RETURN
43 # Set the result code if an exception is encountered
44 # void
45 #
46 function fcoe_smf_enable
47 {
48 fcoe_smf_snap
49 CMD="$SVCADM enable -rs $FCOE_SMF"
50 cti_report "Executing: $CMD"
51 run_ksh_cmd "$CMD"
52 if [ `get_cmd_retval` -ne 0 ];then
53 report_err "$CMD"
54 cti_fail "FAIL - $FCOE_SMF smf service can NOT be enabled"
55 return
56 fi
57 verify_fcoe_enable
58 if [ $? -eq 0 ];then
59 cti_pass "$FCOE_SMF smf enable method testing passed."
60 else
61 cti_fail "FAIL - $FCOE_SMF smf enable method testing failed."
62 fi
63 }
64 #
65 # NAME
66 # fcoe_smf_disable
67 #
68 # SYNOPSIS
69 # fcoe_smf_disable
70 #
71 # DESCRIPTION:
72 # This function executes disable method for testing.
73 #
74 # RETURN
75 # Set the result code if an exception is encountered
76 # void
77 #
78 function fcoe_smf_disable
79 {
80 fcoe_smf_snap
81 CMD="$SVCADM disable -s $FCOE_SMF"
82 cti_report "Executing: $CMD"
83 run_ksh_cmd "$CMD"
84 if [ `get_cmd_retval` -ne 0 ];then
85 report_err "$CMD"
86 cti_fail "FAIL - $FCOE_SMF smf service can NOT be disabled"
87 return
88 fi
89 verify_fcoe_disable
90 if [ $? -eq 0 ];then
91 cti_pass "$FCOE_SMF smf disable method testing passed."
92 else
93 cti_fail "FAIL - $FCOE_SMF smf disable method testing failed."
94 fi
95 }
96 #
97 # NAME
98 # fcoe_smf_refresh
99 #
100 # SYNOPSIS
101 # fcoe_smf_refresh
102 #
103 # DESCRIPTION:
104 # This function executes refresh method for testing.
105 #
106 # RETURN
107 # Set the result code if an exception is encountered
108 # void
109 #
110 function fcoe_smf_refresh
111 {
112 fcoe_smf_snap
113 CMD="$SVCADM refresh $FCOE_SMF"
114 cti_report "Executing: $CMD"
115 run_ksh_cmd "$CMD"
116 if [ `get_cmd_retval` -ne 0 ];then
117 report_err "$CMD"
118 cti_fail "FAIL - $FCOE_SMF smf service can NOT be refreshed"
119 return
120 fi
121 sleep 20
122 verify_fcoe_refresh
123 if [ $? -eq 0 ];then
124 cti_pass "$FCOE_SMF smf refresh method testing passed."
125 else
126 cti_fail "FAIL - $FCOE_SMF smf refresh method testing failed."
127 fi
128 }
129 #
130 # NAME
131 # fcoe_smf_restart
132 #
133 # SYNOPSIS
134 # fcoe_smf_restart
135 #
136 # DESCRIPTION:
137 # This function executes restart method for testing.
138 #
139 # RETURN
140 # Set the result code if an exception is encountered
141 # void
142 #
143 function fcoe_smf_restart
144 {
145 fcoe_smf_snap
146 CMD="$SVCADM restart $FCOE_SMF"
147 cti_report "Executing: $CMD"
148 run_ksh_cmd "$CMD"
149 if [ `get_cmd_retval` -ne 0 ];then
150 report_err "$CMD"
151 cti_fail "FAIL - $FCOE_SMF smf service can NOT be restarted"
152 return
153 else
154 cti_report "$CMD passed"
155 fi
156 sleep 20
157 }
158 #
159 # NAME
160 # fcoe_smf_snap
161 #
162 # SYNOPSIS
163 # fcoe_smf_snap
164 #
165 # DESCRIPTION:
166 # This function save the timestamp into temporary variables.
167 #
168 # RETURN
169 # 1 failed
170 # 0 successful
171 #
172 function fcoe_smf_snap
173 {
174 FCOE_SMF_START_TIME=`$SVCS |grep $FCOE_SMF | \
175 grep -v grep | awk '{print $2}'`
176 }
177
178
179 #
180 # NAME
181 # verify_fcoe_enable
182 # DESCRIPTION
183 # Verify that the fcoe enable operation successfully or not.
184 #
185 # RETURN
186 # Sets the result code
187 # 0 - fcoe enable operation succeed
188 # 1 - fcoe enable operation fail
189 function verify_fcoe_enable
190 {
191 FCOE_SMF_CURRENT_TIME=`$SVCS |grep $FCOE_SMF | grep -v grep | \
192 grep online | awk '{print $2}'`
193 if [ -z "$FCOE_SMF_START_TIME" ];then
194 if [ -n "$FCOE_SMF_CURRENT_TIME" ];then
195 cti_report "PASS - svcadm enable $FCOE_SMF passed from disable to enable."
196 fcoe_disable_enable
197 return 0
198 else
199 cti_report "FAIL - $FCOE_SMF service is not started/online (enable)."
200 return 1
201 fi
202 elif [ -n "$FCOE_SMF_START_TIME" ];then
203 if [ "$FCOE_SMF_CURRENT_TIME" = "$FCOE_SMF_START_TIME" ];then
204 cti_report "PASS - svcadm enable $FCOE_SMF passed from enable to enable."
205 return 0
206 else
207 cti_report "FAIL - $FCOE_SMF service is restarted/online (enable)."
208 return 1
209 fi
210 else
211 cti_report "FAIL - $FCOE_SMF service state is invalid (enable)."
212 return 1
213 fi
214 }
215
216 #
217 # NAME
218 # verify_fcoe_disable
219 # DESCRIPTION
220 # Verify that the fcoe disable operation successfully or not.
221 #
222 # RETURN
223 # Sets the result code
224 # 0 - fcoe disable operation succeed
225 # 1 - fcoe disable operation fail
226 function verify_fcoe_disable
227 {
228 FCOE_SMF_CURRENT_TIME=`$SVCS | grep $FCOE_SMF | grep -v grep | \
229 grep online | awk '{print $2}'`
230 if [ -z "$FCOE_SMF_CURRENT_TIME" ];then
231 if [ -n "$FCOE_SMF_START_TIME" ];then
232 cti_report "PASS - svcadm enable $FCOE_SMF passed "\
233 "from enable to disable."
234 fcoe_enable_disable
235 return 0
236 else
237 cti_report "PASS - svcadm disable $FCOE_SMF passed"\
238 "from disable to disable."
239 return 0
240 fi
241 else
242 cti_report "FAIL - $FCOE_SMF service is not stopped after disable.."
243 return 1
244 fi
245 }
246
247
248 #
249 # NAME
250 # verify_fcoe_refresh
251 # DESCRIPTION
252 # Verify that the refresh operation successfully or not.
253 #
254 # RETURN
255 # Sets the result code
256 # 0 - fcoe refresh operation succeed
257 # 1 - fcoe refresh operation fail
258 function verify_fcoe_refresh
259 {
260 FCOE_SMF_CURRENT_TIME=`$SVCS |grep $FCOE_SMF | grep -v grep | \
261 grep online | awk '{print $2}'`
262 if [ -z "$FCOE_SMF_START_TIME" ];then
263 if [ -z "$FCOE_SMF_CURRENT_TIME" ];then
264 cti_report "PASS - svcadm refresh $FCOE_SMF passed, "\
265 "keep $FCOE_SMF offline."
266 return 0
267 else
268 cti_report "FAIL - svcadm refresh $FCOE_SMF failed, "\
269 "$FCOE_SMF is online."
270 return 1
271 fi
272 else
273 if [ -z "$FCOE_SMF_CURRENT_TIME" ];then
274 cti_report "FAIL - svcadm refresh $FCOE_SMF failed, "\
275 "$FCOE_SMF is offline."
276 return 1
277 else
278 cti_report "PASS - svcadm refresh $FCOE_SMF passed, "\
279 "keep $FCOE_SMF online."
280 return 0
281 fi
282 fi
283 }
284 #
285 # NAME
286 # verify_fcoe_restart
287 # DESCRIPTION
288 # Verify that the restart operation successfully or not.
289 #
290 # RETURN
291 # Sets the result code
292 # 0 - fcoe restart operation succeed
293 # 1 - fcoe restart operation fail
294 function verify_fcoe_restart
295 {
296 FCOE_SMF_CURRENT_TIME=`$SVCS |grep $FCOE_SMF | grep -v grep | \
297 grep online | awk '{print $2}'`
298 if [ -z "$FCOE_SMF_START_TIME" ];then
299 if [ -z "$FCOE_SMF_CURRENT_TIME" ];then
300 cti_report "PASS - svcadm restart $FCOE_SMF passed, "\
301 "keep $FCOE_SMF offline."
302 return 0
303 else
304 cti_report "FAIL - svcadm restart $FCOE_SMF failed, "\
305 "$FCOE_SMF is online."
306 return 1
307 fi
308 else
309 if [ -z "$FCOE_SMF_CURRENT_TIME" ];then
310 cti_report "FAIL - svcadm restart $FCOE_SMF failed, "\
311 "$FCOE_SMF is offline."
312 return 1
313 else
314 cti_report "PASS - svcadm restart $FCOE_SMF passed, "\
315 "keep $FCOE_SMF online."
316 return 0
317 fi
318 fi
319 }
320 #
321 # NAME
322 # check_fcoe_disable
323 # DESCRIPTION
324 # Check fcoe smf service is offline to
325 # make sure target group can be modified.
326 #
327 # RETURN
328 # Sets the result code
329 # 0 - fcoe smf is offline
330 # 1 - fcoe smf is online
331 function check_fcoe_disable
332 {
333 typeset -i ret=`$SVCS -a |grep $FCOE_SMF |grep -v grep | \
334 grep online >/dev/null 2>&1;echo $?`
335 if [ $ret -eq 0 ];then
336 return 1
337 else
338 return 0
339 fi
340 }
341
342 #
343 # NAME
344 # check_fcoe_smf_stored
345 # DESCRIPTION
346 # Check fcoe port information is stored by smf service
347 # Exacmple: check_fcoe_smf_stored nxge0
348 #
349 # RETURN
350 # Sets the result code
351 # 0 - fcoe port information is stored in smf database
352 # 1 - fcoe port information is not stored in smf database
353 function check_fcoe_smf_stored
354 {
355 typeset mac_interface=$1
356 cti_report "$SVCCFG -s $FCOE_SMF listprop $FCOE_PORTLIST_PROPERTY | grep $mac_interface"
357 CMD="$SVCCFG -s $FCOE_SMF listprop $FCOE_PORTLIST_PROPERTY | grep $mac_interface"
358 run_ksh_cmd "$CMD"
359 if [ `get_cmd_retval` -eq 0 ]; then
360 cti_report "check_fcoe_smf_stored found $mac_interface"
361 return 0
362 else
363 cti_report "check_fcoe_smf_stored did not find $mac_interface"
364 return 1
365 fi
366 }
367
368 #
369 # NAME
370 # fcoe_smf_add_propgroup
371 # DESCRIPTION
372 # Add property group to fcoe service
373 # Exacmple: fcoe_smf_add_propvalue
374 #
375 # RETURN
376 # Sets the result code
377 # 0 - added succesfully
378 # 1 - failed to add property value
379 function fcoe_smf_add_propgroup
380 {
381 CMD="$SVCCFG -s $FCOE_SMF addpg $FCOE_PORTLIST_PG astring"
382 cti_report "Executing $CMD"
383 run_ksh_cmd "$CMD"
384 if [ `get_cmd_retval` -eq 0 ]; then
385 cti_report "fcoe_smf_add_propgroup addpg passed"
386 return 0
387 else
388 cti_report "fcoe_smf_add_propgroup addpg failed"
389 return 1
390 fi
391 }
392
393 #
394 # NAME
395 # fcoe_smf_setprop
396 # DESCRIPTION
397 # Create a property name and add a property value to fcoe service
398 # Exacmple: fcoe_smf_add_propvalue nxge0
399 #
400 # RETURN
401 # Sets the result code
402 # 0 - added succesfully
403 # 1 - failed to add property value
404 function fcoe_smf_setprop
405 {
406 typeset mac_interface=$1
407 typeset propvalue="${mac_interface}:0000000000000000:0000000000000000:1:0"
408 CMD="$SVCCFG -s $FCOE_SMF setprop $FCOE_PORTLIST_PROPERTY = ustring: $propvalue"
409 cti_report "Executing $CMD"
410 run_ksh_cmd "$CMD"
411 if [ `get_cmd_retval` -eq 0 ]; then
412 cti_report "fcoe_smf_add_propvalue addpropvalue for $mac_interface passed"
413 return 0
414 else
415 cti_report "fcoe_smf_add_propvalue addpropvalue for $mac_interface failed"
416 return 1
417 fi
418 }
419
420 #
421 # NAME
422 # fcoe_smf_add_propvalue
423 # DESCRIPTION
424 # Add one property value to fcoe service after property is created
425 # Exacmple: fcoe_smf_add_propvalue nxge0
426 #
427 # RETURN
428 # Sets the result code
429 # 0 - added succesfully
430 # 1 - failed to add property value
431 function fcoe_smf_add_propvalue
432 {
433 typeset mac_interface=$1
434 typeset propvalue="${mac_interface}:0000000000000000:0000000000000000:1:0"
435 CMD="$SVCCFG -s $FCOE_SMF addpropvalue $FCOE_PORTLIST_PROPERTY $propvalue"
436 cti_report "Executing $CMD"
437 run_ksh_cmd "$CMD"
438 if [ `get_cmd_retval` -eq 0 ]; then
439 cti_report "fcoe_smf_add_propvalue addpropvalue for $mac_interface passed"
440 return 0
441 else
442 cti_report "fcoe_smf_add_propvalue addpropvalue for $mac_interface failed"
443 return 1
444 fi
445 }
446
447 #
448 # NAME
449 # fcoe_enable_disable
450 # DESCRIPTION
451 # fcoe is changed from enable to disable, all the LU and Target will be
452 # offline, but if disable to disable, the onlined LU and Target will be
453 # kept online
454 #
455 # RETURN
456 # void
457 function fcoe_enable_disable
458 {
459 for port in $G_TARGET
460 do
461 typeset scsi_id=`format_scsiname "$port"`
462 typeset shell_id=`format_shellvar "$scsi_id"`
463 eval TARGET_${shell_id}_ONLINE=N
464 done
465 for vol in $G_VOL
466 do
467 eval typeset -u guid=\$LU_${vol}_GUID
468 eval LU_${guid}_ONLINE=N
469 done
470 }
471
472 #
473 # NAME
474 # fcoe_disable_enable
475 # DESCRIPTION
476 # fcoe is changed from disable to enable, all the LU and Target will be
477 # online, but if enable to enable, the offlined LU and Target will be
478 # kept offline
479 #
480 # RETURN
481 # void
482 function fcoe_disable_enable
483 {
484 for port in $G_TARGET
485 do
486 typeset scsi_id=`format_scsiname "$port"`
487 typeset shell_id=`format_shellvar "$scsi_id"`
488 eval TARGET_${shell_id}_ONLINE=Y
489 done
490 for vol in $G_VOL
491 do
492 eval typeset -u guid=\$LU_${vol}_GUID
493 eval LU_${guid}_ONLINE=Y
494 done
495 }
496
497 #
498 # NAME
499 # fcoe_smf_reload
500 #
501 # SYNOPSIS
502 # fcoe_smf_reload
503 #
504 # DESCRIPTION:
505 # This function clean up all the persitent data in target host and
506 # reload the fcoe service as a cleaned one
507 #
508 # RETURN
509 # Set the result code if an exception is encountered
510 # 1 failed
511 # 0 successful
512 #
513 function fcoe_smf_reload
514 {
515 cti_report "Executing $SVCCFG delete -f $FCOE_SMF"
516 $SVCCFG delete -f $FCOE_SMF
517 if [ $? -ne 0 ];then
518 cti_fail "FAIL - delete smf entry $FCOE_MANIFEST failed."
519 return 1
520 fi
521 cti_report "$FCOE_SMF smf delete method testing passed."
522
523 cti_report "Executing $SVCCFG import $FCOE_MANIFEST"
524 $SVCCFG import $FCOE_MANIFEST
525 if [ $? -ne 0 ];then
526 cti_fail "FAIL - import smf entry $FCOE_MANIFEST failed."
527 return 1
528 fi
529 cti_report "$FCOE_SMF smf import method testing passed."
530 sleep 20
531 return 0
532 }