diff --git a/addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh b/addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh index da1841c84..a9c9783db 100644 --- a/addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh +++ b/addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh @@ -16,73 +16,27 @@ Describe "Pulsar Bookies Member Leave Bash Script Tests" } BeforeAll "init" - Describe "format_bookie()" - It "formats bookie with force and deleteCookie" - bin/bookkeeper() { - if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ] && [ "$4" = "-force" ] && [ "$5" = "-deleteCookie" ]; then - echo "Bookie formatted with force and deleteCookie" - return 0 - fi - return 1 - } - - When call format_bookie "true" "true" - The output should include "Formatting Bookie..." - The output should include "Bookie formatted with force and deleteCookie" - The status should be success - End - - It "formats bookie without force and deleteCookie" - bin/bookkeeper() { - if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ]; then - echo "Bookie formatted" - return 0 - fi - return 1 - } - - When call format_bookie "false" "false" - The output should include "Formatting Bookie..." - The output should include "Bookie formatted" - The status should be success - End - End - - Describe "should_format_bookie()" - It "returns true when pod index is greater than or equal to replicas" - When call should_format_bookie "pod-3" "2" - The status should be success - End - - It "returns false when pod index is less than replicas" - When call should_format_bookie "pod-1" "2" - The status should be failure - End - End + bin/bookkeeper() { + return 0 + } Describe "bookies_member_leave()" - setup() { - export CURRENT_POD_NAME="pod-3" - export BOOKKEEPER_COMP_REPLICAS="2" - } - It "formats bookie when condition is met" - setup - - format_bookie() { - echo "format_bookie called with $1 $2" - } + export CURRENT_POD_NAME="pod-3" + export KB_LEAVE_MEMBER_POD_NAME="pod-3" When call bookies_member_leave - The output should include "format_bookie called with true true" + The output should include "Formatting Bookie..." + The output should include "Bookie formatted" End It "skips formatting when condition is not met" export CURRENT_POD_NAME="pod-1" - export BOOKKEEPER_COMP_REPLICAS="2" + export KB_LEAVE_MEMBER_POD_NAME="pod-2" When call bookies_member_leave - The output should include "Skipping Bookie formatting" + The output should include "Member to leave is not current pod, skipping Bookie formatting" + The status should be failure End End End \ No newline at end of file diff --git a/addons/pulsar/scripts/bookies-member-leave.sh b/addons/pulsar/scripts/bookies-member-leave.sh index 45a0ce24a..05cf9dd1c 100755 --- a/addons/pulsar/scripts/bookies-member-leave.sh +++ b/addons/pulsar/scripts/bookies-member-leave.sh @@ -1,41 +1,16 @@ #!/bin/bash -format_bookie() { - local force=$1 - local delete_cookie=$2 - - echo "Formatting Bookie..." - if [[ $force == "true" && $delete_cookie == "true" ]]; then - bin/bookkeeper shell bookieformat -nonInteractive -force -deleteCookie || true - else - bin/bookkeeper shell bookieformat -nonInteractive || true - fi - echo "Bookie formatted" -} - -# TODO: this logic should be refactored rather than judging by pod name index -should_format_bookie() { - local current_pod_name=$1 - local current_component_replicas=$2 - - local idx=${current_pod_name##*-} - if [[ $idx -ge $current_component_replicas && $current_component_replicas -ne 0 ]]; then - return 0 - else +bookies_member_leave() { + if [[ "$KB_LEAVE_MEMBER_POD_NAME" != "$CURRENT_POD_NAME" ]]; then + echo "Member to leave is not current pod, skipping Bookie formatting" return 1 fi -} - -bookies_member_leave() { - # shellcheck disable=SC2153 - local current_pod_name=${CURRENT_POD_NAME} - local current_component_replicas=${BOOKKEEPER_COMP_REPLICAS} - if should_format_bookie "$current_pod_name" "$current_component_replicas"; then - format_bookie "true" "true" - else - echo "Skipping Bookie formatting" - fi + # TODO: consider using decommissionbookie? But decommissionbookie needs bookie to stop first, kb doesn't support a "postMemberLeave" hook. + echo "Formatting Bookie..." + export BOOKIE_CONF=/opt/pulsar/conf/bookkeeper.conf + bin/bookkeeper shell bookieformat -nonInteractive -force -deleteCookie + echo "Bookie formatted" } # This is magic for shellspec ut framework.