Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98ebff8

Browse files
committed
Fix Admin Client api version checking; only test ACL integration on 0.11+
1 parent 5381591 commit 98ebff8

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

kafka/admin/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,20 @@ def _matching_api_version(self, operation):
232232
:param operation: A list of protocol operation versions from kafka.protocol.
233233
:return: The max matching version number between client and broker.
234234
"""
235-
version = min(len(operation) - 1,
236-
self._client.get_api_versions()[operation[0].API_KEY][1])
237-
if version < self._client.get_api_versions()[operation[0].API_KEY][0]:
235+
broker_api_versions = self._client.get_api_versions()
236+
api_key = operation[0].API_KEY
237+
if broker_api_versions is None or api_key not in broker_api_versions:
238+
raise IncompatibleBrokerVersion(
239+
"Kafka broker does not support the '{}' Kafka protocol."
240+
.format(operation[0].__name__))
241+
min_version, max_version = broker_api_versions[api_key]
242+
version = min(len(operation) - 1, max_version)
243+
if version < min_version:
238244
# max library version is less than min broker version. Currently,
239245
# no Kafka versions specify a min msg version. Maybe in the future?
240246
raise IncompatibleBrokerVersion(
241247
"No version of the '{}' Kafka protocol is supported by both the client and broker."
242-
.format(operation.__name__))
248+
.format(operation[0].__name__))
243249
return version
244250

245251
def _validate_timeout(self, timeout_ms):

test/test_admin_integration.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,33 @@
88
from kafka.admin import KafkaAdminClient, ACLFilter, ACLOperation, ACLPermissionType, ResourcePattern, ResourceType, ACL
99

1010

11+
# TODO: Convert to pytest / fixtures
12+
# Note that ACL features require broker 0.11, but other admin apis may work on
13+
# earlier broker versions
1114
class TestAdminClientIntegration(KafkaIntegrationTestCase):
1215
@classmethod
1316
def setUpClass(cls): # noqa
14-
if env_kafka_version() < (0, 10):
17+
if env_kafka_version() < (0, 11):
1518
return
1619

1720
cls.zk = ZookeeperFixture.instance()
1821
cls.server = KafkaFixture.instance(0, cls.zk)
1922

2023
@classmethod
2124
def tearDownClass(cls): # noqa
22-
if env_kafka_version() < (0, 10):
25+
if env_kafka_version() < (0, 11):
2326
return
2427

2528
cls.server.close()
2629
cls.zk.close()
2730

2831
def setUp(self):
29-
if env_kafka_version() < (0, 10):
30-
self.skipTest('Admin Integration test requires KAFKA_VERSION >= 0.10')
32+
if env_kafka_version() < (0, 11):
33+
self.skipTest('Admin ACL Integration test requires KAFKA_VERSION >= 0.11')
3134
super(TestAdminClientIntegration, self).setUp()
3235

3336
def tearDown(self):
34-
if env_kafka_version() < (0, 10):
37+
if env_kafka_version() < (0, 11):
3538
return
3639
super(TestAdminClientIntegration, self).tearDown()
3740

0 commit comments

Comments
 (0)