/tests/zfs-tests/tests/functional/cli_root/zpool_online/zpool_online_001_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 124 lines · 67 code · 17 blank · 40 comment · 13 complexity · 9d527a29c53933d55cf1f865ede102df MD5 · raw file

  1. #!/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. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. #
  31. # DESCRIPTION:
  32. # Executing 'zpool online' with valid parameters succeeds.
  33. #
  34. # STRATEGY:
  35. # 1. Create an array of correctly formed 'zpool online' options
  36. # 2. Execute each element of the array.
  37. # 3. Verify use of each option is successful.
  38. #
  39. verify_runnable "global"
  40. DISKLIST=$(get_disklist $TESTPOOL)
  41. set -A args ""
  42. function cleanup
  43. {
  44. #
  45. # Ensure we don't leave disks in temporary online state (-t)
  46. #
  47. for disk in $DISKLIST; do
  48. log_must zpool online $TESTPOOL $disk
  49. check_state $TESTPOOL $disk "online"
  50. if [[ $? != 0 ]]; then
  51. log_fail "Unable to online $disk"
  52. fi
  53. done
  54. }
  55. log_assert "Executing 'zpool online' with correct options succeeds"
  56. log_onexit cleanup
  57. if [[ -z $DISKLIST ]]; then
  58. log_fail "DISKLIST is empty."
  59. fi
  60. typeset -i i=0
  61. typeset -i j=0
  62. for disk in $DISKLIST; do
  63. i=0
  64. while [[ $i -lt ${#args[*]} ]]; do
  65. log_must sync_pool $TESTPOOL
  66. log_must zpool offline $TESTPOOL $disk
  67. check_state $TESTPOOL $disk "offline"
  68. if [[ $? != 0 ]]; then
  69. log_fail "$disk of $TESTPOOL did not match offline state"
  70. fi
  71. log_must zpool online ${args[$i]} $TESTPOOL $disk
  72. check_state $TESTPOOL $disk "online"
  73. if [[ $? != 0 ]]; then
  74. log_fail "$disk of $TESTPOOL did not match online state"
  75. fi
  76. while [[ $j -lt 20 ]]; do
  77. is_pool_resilvered $TESTPOOL && break
  78. sleep 0.5
  79. (( j = j + 1 ))
  80. done
  81. is_pool_resilvered $TESTPOOL || \
  82. log_file "Pool didn't resilver after online"
  83. (( i = i + 1 ))
  84. done
  85. done
  86. log_note "Issuing repeated 'zpool online' commands succeeds."
  87. typeset -i iters=20
  88. typeset -i index=0
  89. for disk in $DISKLIST; do
  90. i=0
  91. while [[ $i -lt $iters ]]; do
  92. index=`expr $RANDOM % ${#args[*]}`
  93. log_must zpool online ${args[$index]} $TESTPOOL $disk
  94. check_state $TESTPOOL $disk "online"
  95. if [[ $? != 0 ]]; then
  96. log_fail "$disk of $TESTPOOL did not match online state"
  97. fi
  98. (( i = i + 1 ))
  99. done
  100. done
  101. log_pass "'zpool online' with correct options succeeded"