Skip to content

Commit cb9e664

Browse files
committed
Return list of describe config responses instead of merging them
1 parent c65a5e9 commit cb9e664

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

kafka/admin/client.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,19 +820,10 @@ def describe_configs(self, config_resources, include_synonyms=False):
820820
))
821821
else:
822822
raise NotImplementedError(
823-
"Support for DescribeConfigs v{} has not yet been added to KafkaAdminClient."
824-
.format(version))
823+
"Support for DescribeConfigs v{} has not yet been added to KafkaAdminClient.".format(version))
825824

826825
self._wait_for_futures(futures)
827-
828-
# Use one of the results as the general response and add all other resources to it
829-
response = copy.copy(futures[0].value)
830-
response.resources = []
831-
832-
for future in futures:
833-
response.resources.extend(future.value.resources)
834-
835-
return response
826+
return [f.value for f in futures]
836827

837828
@staticmethod
838829
def _convert_alter_config_resource_request(config_resource):

test/test_admin_integration.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from test.testutil import env_kafka_version
44

55
from kafka.errors import NoError
6-
from kafka.admin import ACLFilter, ACLOperation, ACLPermissionType, ResourcePattern, ResourceType, ACL
7-
6+
from kafka.admin import (
7+
ACLFilter, ACLOperation, ACLPermissionType, ResourcePattern, ResourceType, ACL, ConfigResource, ConfigResourceType)
88

9+
910
@pytest.mark.skipif(env_kafka_version() < (0, 11), reason="ACL features require broker >=0.11")
1011
def test_create_describe_delete_acls(kafka_admin_client):
1112
"""Tests that we can add, list and remove ACLs
@@ -80,3 +81,45 @@ def test_create_describe_delete_acls(kafka_admin_client):
8081

8182
assert error is NoError
8283
assert len(acls) == 0
84+
85+
86+
@pytest.mark.skipif(env_kafka_version() < (0, 11), reason="Describe config features require broker >=0.11")
87+
def test_describe_configs_broker_resource_returns_configs(simple_client, kafka_admin_client):
88+
"""Tests that describe config returns configs for broker
89+
"""
90+
broker_id = simple_client.brokers[0].nodeId
91+
configs = kafka_admin_client.describe_configs([ConfigResource(ConfigResourceType.BROKER, broker_id)])
92+
93+
assert len(configs) == 1
94+
assert configs[0].resources[0][2] == ConfigResourceType.BROKER
95+
assert configs[0].resources[0][3] == str(broker_id)
96+
assert len(configs[0].resources[0][4]) > 1
97+
98+
99+
@pytest.mark.skipif(env_kafka_version() < (0, 11), reason="Describe config features require broker >=0.11")
100+
def test_describe_configs_topic_resource_returns_configs(simple_client, kafka_admin_client):
101+
topic = simple_client.topics[0]
102+
configs = kafka_admin_client.describe_configs([ConfigResource(ConfigResourceType.TOPIC, topic)])
103+
104+
assert len(configs) == 1
105+
assert configs[0].resources[0][2] == ConfigResourceType.TOPIC
106+
assert configs[0].resources[0][3] == topic
107+
assert len(configs[0].resources[0][4]) > 1
108+
109+
110+
@pytest.mark.skipif(env_kafka_version() < (0, 11), reason="Describe config features require broker >=0.11")
111+
def test_describe_configs_mixed_resources_returns_configs(simple_client, kafka_admin_client):
112+
topic = simple_client.topics[0]
113+
broker_id = simple_client.brokers[0].nodeId
114+
configs = kafka_admin_client.describe_configs([
115+
ConfigResource(ConfigResourceType.TOPIC, topic),
116+
ConfigResource(ConfigResourceType.BROKER, broker_id)])
117+
118+
assert len(configs) == 2
119+
120+
for config in configs:
121+
assert (config.resources[0][2] == ConfigResourceType.TOPIC
122+
and config.resources[0][3] == topic) or \
123+
(config.resources[0][2] == ConfigResourceType.BROKER
124+
and config.resources[0][3] == str(broker_id))
125+
assert len(config.resources[0][4]) > 1

0 commit comments

Comments
 (0)