/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_004_neg.ksh

https://github.com/adilger/zfs · Korn Shell · 112 lines · 49 code · 15 blank · 48 comment · 1 complexity · 5381e190c1348fb6f1263466af7ea1bd 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. . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib
  31. #
  32. # DESCRIPTION:
  33. # 'zfs rename' should fail when this dataset was changed to an existed
  34. # dataset name or datasets are of different types.
  35. # For example, a filesystem cannot be renamed as a volume.
  36. #
  37. # STRATEGY:
  38. # 1. Given a file system, snapshot and volume.
  39. # 2. Rename each dataset object to a different type.
  40. # 3. Verify that only the original name is displayed by zfs list.
  41. #
  42. verify_runnable "both"
  43. #
  44. # This array is a list of pairs:
  45. # item i: original type
  46. # item i + 1: new type
  47. #
  48. set -A bad_dataset $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR1 \
  49. $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR/$TESTFS1 \
  50. $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \
  51. $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS1 \
  52. $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
  53. $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTVOL \
  54. $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS@snapshot \
  55. $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS1 \
  56. $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTCTR/$TESTFS1 \
  57. $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTVOL \
  58. $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \
  59. $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS1 \
  60. $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTCTR1 \
  61. $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR1 \
  62. $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS@snapshot \
  63. $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS1 \
  64. $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR/$TESTFS1 \
  65. $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR1 \
  66. $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTVOL \
  67. $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS1 \
  68. $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR/$TESTFS1 \
  69. $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%c \
  70. $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%d \
  71. $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%x \
  72. $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%p \
  73. $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%s \
  74. $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS@snapshot/fs \
  75. $TESTPOOL/$RECVFS/%recv $TESTPOOL/renamed.$$
  76. #
  77. # cleanup defined in zfs_rename.kshlib
  78. #
  79. log_onexit cleanup
  80. log_assert "'zfs rename' should fail when datasets are of a different type."
  81. additional_setup
  82. typeset -i i=0
  83. while ((i < ${#bad_dataset[*]} )); do
  84. log_mustnot zfs rename ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
  85. log_must datasetexists ${bad_dataset[i]}
  86. log_mustnot zfs rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]}
  87. log_must datasetexists ${bad_dataset[i]}
  88. ((i = i + 2))
  89. done
  90. #verify 'rename -p' can not work with snapshots
  91. log_mustnot zfs rename -p $TESTPOOL/$TESTFS@snapshot \
  92. $TESTPOOL/$TESTFS@snapshot2
  93. log_must datasetexists $TESTPOOL/$TESTFS@snapshot
  94. log_mustnot zfs rename -p $TESTPOOL/$TESTFS@snapshot \
  95. $TESTPOOL/$TESTFS/$TESTFS@snapshot2
  96. log_must datasetexists $TESTPOOL/$TESTFS@snapshot
  97. log_pass "'zfs rename' fails as expected when given different dataset types."