-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade pulsar addon to v1.0 API and add scripts ut (#1111)
- Loading branch information
Showing
56 changed files
with
2,723 additions
and
2,197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,498 changes: 0 additions & 1,498 deletions
1,498
addons/pulsar/config/broker-config-constraint.cue
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 | ||
|
||
# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run. | ||
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then | ||
echo "bookies_member_leave_spec.sh skip cases because dependency bash version 4 or higher is not installed." | ||
exit 0 | ||
fi | ||
|
||
Describe "Pulsar Bookies Member Leave Bash Script Tests" | ||
# load the scripts to be tested and dependencies | ||
Include ../scripts/bookies-member-leave.sh | ||
|
||
init() { | ||
ut_mode="true" | ||
} | ||
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 | ||
|
||
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" | ||
} | ||
|
||
When call bookies_member_leave | ||
The output should include "format_bookie called with true true" | ||
End | ||
|
||
It "skips formatting when condition is not met" | ||
export CURRENT_POD_NAME="pod-1" | ||
export BOOKKEEPER_COMP_REPLICAS="2" | ||
|
||
When call bookies_member_leave | ||
The output should include "Skipping Bookie formatting" | ||
End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 | ||
|
||
# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run. | ||
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then | ||
echo "check_bookies_spec.sh skip cases because dependency bash version 4 or higher is not installed." | ||
exit 0 | ||
fi | ||
|
||
Describe "Pulsar Check Bookies Bash Script Tests" | ||
# load the scripts to be tested and dependencies | ||
Include ../scripts/check-bookies.sh | ||
|
||
init() { | ||
ut_mode="true" | ||
} | ||
BeforeAll "init" | ||
|
||
Describe "apply_config_from_env()" | ||
It "applies configuration from environment variables" | ||
# mock command to apply configuration from environment variables | ||
bin/apply-config-from-env.py() { | ||
return 0 | ||
} | ||
|
||
When call apply_config_from_env | ||
The output should include "Applying configuration from environment variables:" | ||
The output should include " - Command: bin/apply-config-from-env.py conf/bookkeeper.conf" | ||
The status should be success | ||
End | ||
End | ||
|
||
Describe "wait_for_bookkeeper()" | ||
It "waits for bookkeeper to start" | ||
# mock command to check if bookkeeper instance id is available | ||
bin/bookkeeper() { | ||
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then | ||
return 0 | ||
fi | ||
return 1 | ||
} | ||
|
||
When run wait_for_bookkeeper | ||
The output should include "Waiting for bookkeeper to start..." | ||
The output should include "Bookkeeper started successfully" | ||
The status should be success | ||
End | ||
End | ||
|
||
Describe "set_tcp_keepalive()" | ||
It "sets TCP keepalive parameters" | ||
sysctl() { | ||
return 0 | ||
} | ||
|
||
When run set_tcp_keepalive | ||
The output should include "Setting TCP keepalive parameters:" | ||
The output should include " - net.ipv4.tcp_keepalive_time=1" | ||
The output should include " - net.ipv4.tcp_keepalive_intvl=11" | ||
The output should include " - net.ipv4.tcp_keepalive_probes=3" | ||
The status should be success | ||
End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# shellcheck shell=bash | ||
# shellcheck disable=SC2034 | ||
|
||
# validate_shell_type_and_version defined in shellspec/spec_helper.sh used to validate the expected shell type and version this script needs to run. | ||
if ! validate_shell_type_and_version "bash" 4 &>/dev/null; then | ||
echo "init_bookies_spec.sh skip cases because dependency bash version 4 or higher is not installed." | ||
exit 0 | ||
fi | ||
|
||
Describe "Pulsar Init Bookies Bash Script Tests" | ||
# load the scripts to be tested and dependencies | ||
Include ../scripts/init-bookies.sh | ||
|
||
init() { | ||
ut_mode="true" | ||
} | ||
BeforeAll "init" | ||
|
||
Describe "wait_for_zookeeper()" | ||
It "waits for Zookeeper to be ready" | ||
nc() { | ||
if [ "$1" = "-q" ] && [ "$2" = "1" ] && [ "$3" = "zookeeper.example.com" ] && [ "$4" = "2181" ]; then | ||
echo "imok" | ||
fi | ||
} | ||
|
||
When call wait_for_zookeeper "zookeeper.example.com:2181" | ||
The output should include "Waiting for Zookeeper at zookeeper.example.com:2181 to be ready..." | ||
The output should include "Zookeeper is ready" | ||
End | ||
End | ||
|
||
Describe "merge_bookkeeper_config()" | ||
It "merges Pulsar configuration files" | ||
python3() { | ||
echo "$1 $2 $3" | ||
} | ||
|
||
When run merge_bookkeeper_config | ||
The output should include "/kb-scripts/merge_pulsar_config.py" | ||
The output should include "Merging Pulsar configuration files:" | ||
The output should include " - Source: conf/bookkeeper.conf" | ||
The output should include " - Destination: /opt/pulsar/conf/bookkeeper.conf" | ||
The status should be success | ||
End | ||
End | ||
|
||
Describe "apply_config_from_env()" | ||
It "applies configuration from environment variables" | ||
bin/apply-config-from-env.py() { | ||
return 0 | ||
} | ||
|
||
When run apply_config_from_env | ||
The output should include "Applying configuration from environment variables to conf/bookkeeper.conf" | ||
The status should be success | ||
End | ||
End | ||
|
||
Describe "init_bookkeeper_cluster()" | ||
It "initializes new BookKeeper cluster if not already initialized" | ||
bin/bookkeeper() { | ||
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then | ||
return 1 | ||
elif [ "$1" = "shell" ] && [ "$2" = "initnewcluster" ]; then | ||
return 0 | ||
fi | ||
} | ||
|
||
When run init_bookkeeper_cluster | ||
The output should include "Checking if BookKeeper cluster is already initialized..." | ||
The output should include "Initializing new BookKeeper cluster" | ||
The status should be success | ||
End | ||
|
||
It "skips initialization if BookKeeper cluster is already initialized" | ||
bin/bookkeeper() { | ||
if [ "$1" = "shell" ] && [ "$2" = "whatisinstanceid" ]; then | ||
return 0 | ||
fi | ||
} | ||
|
||
When run init_bookkeeper_cluster | ||
The output should include "Checking if BookKeeper cluster is already initialized..." | ||
The output should include "BookKeeper cluster is already initialized" | ||
The status should be success | ||
End | ||
End | ||
|
||
Describe "init_bookies()" | ||
It "initializes bookies" | ||
export zkServers="zookeeper.example.com:2181" | ||
|
||
wait_for_zookeeper() { | ||
echo "wait_for_zookeeper called" | ||
} | ||
|
||
merge_bookkeeper_config() { | ||
echo "merge_bookkeeper_config called" | ||
} | ||
|
||
apply_config_from_env() { | ||
echo "apply_config_from_env called" | ||
} | ||
|
||
init_bookkeeper_cluster() { | ||
echo "init_bookkeeper_cluster called" | ||
} | ||
|
||
When run init_bookies | ||
The output should include "wait_for_zookeeper called" | ||
The output should include "merge_bookkeeper_config called" | ||
The output should include "apply_config_from_env called" | ||
The output should include "init_bookkeeper_cluster called" | ||
End | ||
|
||
It "exits with status 1 when zkServers environment variable is not set" | ||
unset zkServers | ||
|
||
When run init_bookies | ||
The output should include "Error: zkServers environment variable is not set, Please set the zkServers environment variable and try again." | ||
The status should be failure | ||
End | ||
End | ||
End |
Oops, something went wrong.