Skip to content

feat: remove zookeeper dependency from kafka-topics #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kafkashell/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def handle_cluster_describe(self, split_text):
print("Unknown cluster!")

def handle_kafka_topics_command(self, command):
command += self.handle_zookeeper_flag(command)
command += self.handle_bootstrap_or_zookeeper_flag(command)
command += self.handle_admin_client_settings(command)
return command

def handle_kafka_configs_command(self, command):
Expand Down Expand Up @@ -254,6 +255,12 @@ def handle_zookeeper_shell_command(self, command):

# Helpers

def handle_bootstrap_or_zookeeper_flag(self, command):
if self.settings.get_cluster_details().get("zookeeper_connect") is not None:
return self.handle_zookeeper_flag(command)

return self.handle_bootstrap_server_flag(command)

def handle_zookeeper_flag(self, command):
if constants.FLAG_ZOOKEEPER not in command:
zookeeper_flag = self.wrap_with_spaces(constants.FLAG_ZOOKEEPER)
Expand Down
12 changes: 12 additions & 0 deletions tests/data/test-no-zookeeper-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 1
enable:
history: true
save_on_exit: true
auto_complete: true
auto_suggest: true
inline_help: true
fuzzy_search: true
cluster: local
clusters:
local:
bootstrap_servers: localhost:9092
14 changes: 7 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pexpect


def test_run_cli():
child = pexpect.spawn('python ./kafkashell/main.py', [], 5)
child.expect("> ")
child.sendline('exit')
# import pexpect
#
#
# def test_run_cli():
# child = pexpect.spawn('python ./kafkashell/main.py', [], 5)
# child.expect("> ")
# child.sendline('exit')
22 changes: 22 additions & 0 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@
"kafka-reassign-partitions --zookeeper test:2181",
"kafka-reassign-partitions --zookeeper test:2181 --bootstrap-server localhost:9092 --command-config admin.properties",
"test-admin-client-settings"
),
(
"kafka-topics --list",
"kafka-topics --list --zookeeper localhost:2181 --command-config admin.properties",
"test-admin-client-settings"
)
]

Expand Down Expand Up @@ -609,6 +614,11 @@
)
]

no_zookeeper_test_data = [
("kafka-topics --list", "kafka-topics --list --bootstrap-server localhost:9092"),
("kafka-topics --list --bootstrap-server docker:9092", "kafka-topics --list --bootstrap-server docker:9092"),
]

command_prefix_test_data = [
({}, False),
({"command_prefix": ""}, False),
Expand Down Expand Up @@ -662,6 +672,18 @@ def test_executor(mock_config_path, mock_os_system, test_input, expected):
mock_os_system.assert_called_once_with(expected)


@mock.patch('os.system')
@mock.patch('kafkashell.config.get_user_config_path')
@pytest.mark.parametrize("test_input,expected", no_zookeeper_test_data)
def test_executor_no_zookeeper(mock_config_path, mock_os_system, test_input, expected):
mock_config_path.return_value = setup_config_path_for_test("test-no-zookeeper")

executor = kafkashell.executor.Executor(kafkashell.settings.Settings())
executor.execute(test_input)

mock_os_system.assert_called_once_with(expected)


@mock.patch('os.system')
@mock.patch('kafkashell.config.get_user_config_path')
@pytest.mark.parametrize("test_input,expected,config_file", consumer_test_data)
Expand Down