PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_002_pos.ksh

https://github.com/freebsd/freebsd
Korn Shell | 166 lines | 73 code | 36 blank | 57 comment | 14 complexity | 19c3f2b051aa59a0dce3efbfbfcdda3a MD5 | raw file
  1. #!/usr/local/bin/ksh93 -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. # $FreeBSD$
  23. #
  24. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  25. # Use is subject to license terms.
  26. #
  27. # ident "@(#)zpool_import_002_pos.ksh 1.3 07/10/09 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. . $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib
  31. ################################################################################
  32. #
  33. # __stc_assertion_start
  34. #
  35. # ID: zpool_import_002_pos
  36. #
  37. # DESCRIPTION:
  38. # Verify that an exported pool cannot be imported
  39. # more than once.
  40. #
  41. # STRATEGY:
  42. # 1. Populate the default test directory and unmount it.
  43. # 2. Export the default test pool.
  44. # 3. Import it using the various combinations.
  45. # - Regular import
  46. # - Alternate Root Specified
  47. # 4. Verify it shows up under 'zpool list'.
  48. # 5. Verify it contains a file.
  49. # 6. Attempt to import it for a second time. Verify this fails.
  50. #
  51. # TESTABILITY: explicit
  52. #
  53. # TEST_AUTOMATION_LEVEL: automated
  54. #
  55. # CODING_STATUS: COMPLETED (2005-07-04)
  56. #
  57. # __stc_assertion_end
  58. #
  59. ################################################################################
  60. verify_runnable "global"
  61. set -A pools "$TESTPOOL" "$TESTPOOL1"
  62. set -A devs "" "-d $DEVICE_DIR"
  63. set -A options "" "-R $ALTER_ROOT"
  64. set -A mtpts "$TESTDIR" "$TESTDIR1"
  65. function cleanup
  66. {
  67. typeset -i i=0
  68. while (( i < ${#pools[*]} )); do
  69. poolexists ${pools[i]} && \
  70. log_must $ZPOOL export ${pools[i]}
  71. datasetexists "${pools[i]}/$TESTFS" || \
  72. log_must $ZPOOL import ${devs[i]} ${pools[i]}
  73. ismounted "${pools[i]}/$TESTFS" || \
  74. log_must $ZFS mount ${pools[i]}/$TESTFS
  75. [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \
  76. log_must $RM -rf ${mtpts[i]}/$TESTFILE0
  77. ((i = i + 1))
  78. done
  79. cleanup_filesystem $TESTPOOL1 $TESTFS
  80. destroy_pool $TESTPOOL1
  81. [[ -d $ALTER_ROOT ]] && \
  82. log_must $RM -rf $ALTER_ROOT
  83. }
  84. log_onexit cleanup
  85. log_assert "Verify that an exported pool cannot be imported more than once."
  86. setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1
  87. checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}')
  88. typeset -i i=0
  89. typeset -i j=0
  90. typeset basedir
  91. function inner_test
  92. {
  93. typeset pool=$1
  94. typeset target=$2
  95. typeset devs=$3
  96. typeset opts=$4
  97. typeset mtpt=$5
  98. log_must $ZPOOL import ${devs} ${opts} $target
  99. log_must poolexists $pool
  100. log_must ismounted $pool/$TESTFS
  101. basedir=$mtpt
  102. [ -n "$opts" ] && basedir="$ALTER_ROOT/$mtpt"
  103. [ ! -e "$basedir/$TESTFILE0" ] && \
  104. log_fail "ERROR: $basedir/$TESTFILE0 missing after import."
  105. checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}')
  106. [[ "$checksum1" != "$checksum2" ]] && \
  107. log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)"
  108. log_mustnot $ZPOOL import $devs $target
  109. }
  110. while (( i < ${#pools[*]} )); do
  111. log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0
  112. log_must $ZFS umount ${mtpts[i]}
  113. j=0
  114. while (( j < ${#options[*]} )); do
  115. typeset pool=${pools[i]}
  116. typeset vdevdir=""
  117. log_must $ZPOOL export $pool
  118. [ "$pool" = "$TESTPOOL1" ] && vdevdir="$DEVICE_DIR"
  119. guid=$(get_config $pool pool_guid $vdevdir)
  120. log_must test -n "$guid"
  121. log_note "Importing '$pool' by guid '$guid'"
  122. inner_test $pool $guid "${devs[i]}" "${options[j]}" ${mtpts[i]}
  123. log_must $ZPOOL export $pool
  124. log_note "Importing '$pool' by name."
  125. inner_test $pool $pool "${devs[i]}" "${options[j]}" ${mtpts[i]}
  126. ((j = j + 1))
  127. done
  128. ((i = i + 1))
  129. done
  130. log_pass "Able to import exported pools and import only once."