attachable-with-long-mount 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/bin/sh
  2. # Copyright 2017 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This driver is especially designed to test a long mounting scenario
  16. # which can cause a volume to be detached while mount is in progress.
  17. FLEX_DUMMY_LOG=${FLEX_DUMMY_LOG:-"/tmp/flex-dummy.log"}
  18. VALID_MNTDEVICE=foo
  19. # attach always returns one valid mount device so a different device
  20. # showing up in a subsequent driver call implies a bug
  21. validateMountDeviceOrDie() {
  22. MNTDEVICE=$1
  23. CALL=$2
  24. if [ "$MNTDEVICE" != "$VALID_MNTDEVICE" ]; then
  25. log "{\"status\":\"Failure\",\"message\":\"call "${CALL}" expected device "${VALID_MNTDEVICE}", got device "${MNTDEVICE}"\"}"
  26. exit 0
  27. fi
  28. }
  29. log() {
  30. printf "$*" >&1
  31. }
  32. debug() {
  33. echo "$(date) $*" >> "${FLEX_DUMMY_LOG}"
  34. }
  35. attach() {
  36. debug "attach $@"
  37. log "{\"status\":\"Success\",\"device\":\""${VALID_MNTDEVICE}"\"}"
  38. exit 0
  39. }
  40. detach() {
  41. debug "detach $@"
  42. # TODO issue 44737 detach is passed PV name, not mount device
  43. log "{\"status\":\"Success\"}"
  44. exit 0
  45. }
  46. waitforattach() {
  47. debug "waitforattach $@"
  48. MNTDEVICE=$1
  49. validateMountDeviceOrDie "$MNTDEVICE" "waitforattach"
  50. log "{\"status\":\"Success\",\"device\":\""${MNTDEVICE}"\"}"
  51. exit 0
  52. }
  53. isattached() {
  54. debug "isattached $@"
  55. log "{\"status\":\"Success\",\"attached\":true}"
  56. exit 0
  57. }
  58. domountdevice() {
  59. debug "domountdevice $@"
  60. MNTDEVICE=$2
  61. validateMountDeviceOrDie "$MNTDEVICE" "domountdevice"
  62. MNTPATH=$1
  63. mkdir -p ${MNTPATH} >/dev/null 2>&1
  64. mount -t tmpfs none ${MNTPATH} >/dev/null 2>&1
  65. sleep 120
  66. echo "Hello from flexvolume!" >> "${MNTPATH}/index.html"
  67. log "{\"status\":\"Success\"}"
  68. exit 0
  69. }
  70. unmountdevice() {
  71. debug "unmountdevice $@"
  72. MNTPATH=$1
  73. rm "${MNTPATH}/index.html" >/dev/null 2>&1
  74. umount ${MNTPATH} >/dev/null 2>&1
  75. log "{\"status\":\"Success\"}"
  76. exit 0
  77. }
  78. expandvolume() {
  79. debug "expandvolume $@"
  80. log "{\"status\":\"Success\"}"
  81. exit 0
  82. }
  83. expandfs() {
  84. debug "expandfs $@"
  85. log "{\"status\":\"Success\"}"
  86. exit 0
  87. }
  88. op=$1
  89. if [ "$op" = "init" ]; then
  90. debug "init $@"
  91. log "{\"status\":\"Success\",\"capabilities\":{\"attach\":true, \"requiresFSResize\":true}}"
  92. exit 0
  93. fi
  94. shift
  95. case "$op" in
  96. attach)
  97. attach $*
  98. ;;
  99. detach)
  100. detach $*
  101. ;;
  102. waitforattach)
  103. waitforattach $*
  104. ;;
  105. isattached)
  106. isattached $*
  107. ;;
  108. mountdevice)
  109. domountdevice $*
  110. ;;
  111. unmountdevice)
  112. unmountdevice $*
  113. ;;
  114. expandvolume)
  115. expandvolume $*
  116. ;;
  117. expandfs)
  118. expandfs $*
  119. ;;
  120. *)
  121. log "{\"status\":\"Not supported\"}"
  122. exit 0
  123. esac
  124. exit 1