Skip to content

Commit 25f77fe

Browse files
committed
feat: remove zookeeper dependency from kafka-topics
1 parent d29fefd commit 25f77fe

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

kafkashell/executor.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def handle_cluster_describe(self, split_text):
164164
print("Unknown cluster!")
165165

166166
def handle_kafka_topics_command(self, command):
167-
command += self.handle_zookeeper_flag(command)
167+
command += self.handle_bootstrap_or_zookeeper_flag(command)
168168
return command
169169

170170
def handle_kafka_configs_command(self, command):
@@ -254,6 +254,12 @@ def handle_zookeeper_shell_command(self, command):
254254

255255
# Helpers
256256

257+
def handle_bootstrap_or_zookeeper_flag(self, command):
258+
if self.settings.get_cluster_details()["zookeeper_connect"] is not None:
259+
return self.handle_zookeeper_flag(command)
260+
261+
return self.handle_bootstrap_server_flag(command)
262+
257263
def handle_zookeeper_flag(self, command):
258264
if constants.FLAG_ZOOKEEPER not in command:
259265
zookeeper_flag = self.wrap_with_spaces(constants.FLAG_ZOOKEEPER)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 1
2+
enable:
3+
history: true
4+
save_on_exit: true
5+
auto_complete: true
6+
auto_suggest: true
7+
inline_help: true
8+
fuzzy_search: true
9+
cluster: local
10+
clusters:
11+
local:
12+
bootstrap_servers: localhost:9092

tests/test_executor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@
609609
)
610610
]
611611

612+
no_zookeeper_test_data = [
613+
("kafka-topics --list", "kafka-topics --list --bootstrap-server localhost:9092"),
614+
("kafka-topics --list --bootstrap-server docker:9092", "kafka-topics --list --bootstrap-server docker:9092"),
615+
]
616+
612617
command_prefix_test_data = [
613618
({}, False),
614619
({"command_prefix": ""}, False),
@@ -662,6 +667,18 @@ def test_executor(mock_config_path, mock_os_system, test_input, expected):
662667
mock_os_system.assert_called_once_with(expected)
663668

664669

670+
@mock.patch('os.system')
671+
@mock.patch('kafkashell.config.get_user_config_path')
672+
@pytest.mark.parametrize("test_input,expected", no_zookeeper_test_data)
673+
def test_executor_command_prefix(mock_config_path, mock_os_system, test_input, expected):
674+
mock_config_path.return_value = setup_config_path_for_test("test-no-zookeeper")
675+
676+
executor = kafkashell.executor.Executor(kafkashell.settings.Settings())
677+
executor.execute(test_input)
678+
679+
mock_os_system.assert_called_once_with(expected)
680+
681+
665682
@mock.patch('os.system')
666683
@mock.patch('kafkashell.config.get_user_config_path')
667684
@pytest.mark.parametrize("test_input,expected,config_file", consumer_test_data)

0 commit comments

Comments
 (0)