PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_003_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 97 lines | 37 code | 15 blank | 45 comment | 2 complexity | 11f692b6bd1306323d7b5b2c2decb715 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  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 2009 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2014, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib
  31. #
  32. # DESCRIPTION:
  33. # 'zpool add -n <pool> <vdev> ...' can display the configuration without adding
  34. # the specified devices to given pool
  35. #
  36. # STRATEGY:
  37. # 1. Create a storage pool
  38. # 2. Use -n to add devices to the pool
  39. # 3. Verify the devices are not added actually
  40. # 4. Add devices to the pool for real this time, verify the vdev tree is the
  41. # same printed by the dryrun iteration
  42. #
  43. verify_runnable "global"
  44. function cleanup
  45. {
  46. destroy_pool $TESTPOOL
  47. rm -f $TMPFILE_PREFIX* $VDEV_PREFIX*
  48. }
  49. log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" \
  50. "without actually adding devices to the pool."
  51. log_onexit cleanup
  52. typeset TMPFILE_PREFIX="$TEST_BASE_DIR/zpool_add_003"
  53. typeset STR_DRYRUN="would update '$TESTPOOL' to the following configuration:"
  54. typeset VDEV_PREFIX="$TEST_BASE_DIR/filedev"
  55. typeset -a VDEV_TYPES=("" "dedup" "special" "log" "cache")
  56. vdevs=""
  57. config=""
  58. # 1. Create a storage pool
  59. log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-root"
  60. log_must zpool create "$TESTPOOL" "$VDEV_PREFIX-root"
  61. log_must poolexists "$TESTPOOL"
  62. for vdevtype in "${VDEV_TYPES[@]}"; do
  63. log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-$vdevtype"
  64. vdevs="$vdevs $VDEV_PREFIX-$vdevtype"
  65. config="$config $vdevtype $VDEV_PREFIX-$vdevtype"
  66. done
  67. # 2. Use -n to add devices to the pool
  68. log_must eval "zpool add -f -n $TESTPOOL $config > $TMPFILE_PREFIX-dryrun"
  69. log_must grep -q "$STR_DRYRUN" "$TMPFILE_PREFIX-dryrun"
  70. # 3. Verify the devices are not added actually
  71. for vdev in $vdevs; do
  72. log_mustnot vdevs_in_pool "$TESTPOOL" "$vdev"
  73. done
  74. # 4. Add devices to the pool for real this time, verify the vdev tree is the
  75. # same printed by the dryrun iteration
  76. log_must zpool add -f $TESTPOOL $config
  77. zpool status $TESTPOOL | awk 'NR == 1, /NAME/ { next } /^$/ {exit}
  78. {print $1}' > "$TMPFILE_PREFIX-vdevtree"
  79. cat "$TMPFILE_PREFIX-dryrun" | awk 'NR == 1, /would/ {next}
  80. {print $1}' > "$TMPFILE_PREFIX-vdevtree-n"
  81. log_must eval "diff $TMPFILE_PREFIX-vdevtree-n $TMPFILE_PREFIX-vdevtree"
  82. log_pass "'zpool add -n <pool> <vdev> ...' executes successfully."