PageRenderTime 47ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_001_pos.ksh

https://bitbucket.org/freebsd/freebsd-base
Korn Shell | 139 lines | 78 code | 9 blank | 52 comment | 6 complexity | e96bb4e77b87081198aa84486ece319c 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 "@(#)zfs_promote_001_pos.ksh 1.2 07/01/09 SMI"
  28. #
  29. . $STF_SUITE/include/libtest.kshlib
  30. ################################################################################
  31. #
  32. # __stc_assertion_start
  33. #
  34. # ID: zfs_promote_001_pos
  35. #
  36. # DESCRIPTION:
  37. # 'zfs promote' can promote a clone filesystem to no longer be dependent
  38. # on its "origin" snapshot.
  39. #
  40. # STRATEGY:
  41. # 1. Create a snapshot and a clone of the snapshot
  42. # 2. Promote the clone filesystem
  43. # 3. Verify the promoted filesystem become independent
  44. #
  45. # TESTABILITY: explicit
  46. #
  47. # TEST_AUTOMATION_LEVEL: automated
  48. #
  49. # CODING_STATUS: COMPLETED (2006-05-16)
  50. #
  51. # __stc_assertion_end
  52. #
  53. ################################################################################
  54. verify_runnable "both"
  55. function cleanup
  56. {
  57. if snapexists $csnap; then
  58. log_must $ZFS promote $fs
  59. fi
  60. snapexists $snap && \
  61. log_must $ZFS destroy -rR $snap
  62. typeset data
  63. for data in $file0 $file1; do
  64. [[ -e $data ]] && $RM -f $data
  65. done
  66. }
  67. function testing_verify
  68. {
  69. typeset ds=$1
  70. typeset ds_file=$2
  71. typeset snap_file=$3
  72. typeset c_ds=$4
  73. typeset c_file=$5
  74. typeset csnap_file=$6
  75. typeset origin_prop=""
  76. snapexists $ds@$TESTSNAP && \
  77. log_fail "zfs promote cannot promote $ds@$TESTSNAP."
  78. ! snapexists $c_ds@$TESTSNAP && \
  79. log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist."
  80. origin_prop=$(get_prop origin $ds)
  81. [[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \
  82. log_fail "The dependency of $ds is not correct."
  83. origin_prop=$(get_prop origin $c_ds)
  84. [[ "$origin_prop" != "-" ]] && \
  85. log_fail "The dependency of $c_ds is not correct."
  86. if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then
  87. log_fail "Data file $snap_file cannot be correctly promoted."
  88. fi
  89. if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then
  90. log_fail "There exists data file losing after zfs promote."
  91. fi
  92. log_mustnot $ZFS destroy -r $c_ds
  93. }
  94. log_assert "'zfs promote' can promote a clone filesystem."
  95. log_onexit cleanup
  96. fs=$TESTPOOL/$TESTFS
  97. file0=$TESTDIR/$TESTFILE0
  98. file1=$TESTDIR/$TESTFILE1
  99. snap=$fs@$TESTSNAP
  100. snapfile=$TESTDIR/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0
  101. clone=$TESTPOOL/$TESTCLONE
  102. cfile=/$clone/$CLONEFILE
  103. csnap=$clone@$TESTSNAP
  104. csnapfile=/$clone/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0
  105. # setup for promte testing
  106. log_must $MKFILE $FILESIZE $file0
  107. log_must $ZFS snapshot $snap
  108. log_must $MKFILE $FILESIZE $file1
  109. log_must $RM -f $file0
  110. log_must $ZFS clone $snap $clone
  111. log_must $MKFILE $FILESIZE $cfile
  112. log_must $ZFS promote $clone
  113. # verify the 'promote' operation
  114. testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile
  115. log_note "Verify 'zfs promote' can change back the dependency relationship."
  116. log_must $ZFS promote $fs
  117. #verify the result
  118. testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile
  119. log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\
  120. "as expected."