-
Notifications
You must be signed in to change notification settings - Fork 14k
/
version.py
271 lines (216 loc) · 7.64 KB
/
version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from distutils.version import LooseVersion
from kafkatest.utils import kafkatest_version
class KafkaVersion(LooseVersion):
"""Container for kafka versions which makes versions simple to compare.
distutils.version.LooseVersion (and StrictVersion) has robust comparison and ordering logic.
Example:
v10 = KafkaVersion("0.10.0")
v9 = KafkaVersion("0.9.0.1")
assert v10 > v9 # assertion passes!
"""
def __init__(self, version_string):
self.is_dev = (version_string.lower() == "dev")
if self.is_dev:
version_string = kafkatest_version()
# Drop dev suffix if present
dev_suffix_index = version_string.find(".dev")
if dev_suffix_index >= 0:
version_string = version_string[:dev_suffix_index]
# Don't use the form super.(...).__init__(...) because
# LooseVersion is an "old style" python class
LooseVersion.__init__(self, version_string)
def __str__(self):
if self.is_dev:
return "dev"
else:
return LooseVersion.__str__(self)
def _cmp(self, other):
if isinstance(other, str):
other = KafkaVersion(other)
if other.is_dev:
if self.is_dev:
return 0
return -1
elif self.is_dev:
return 1
return LooseVersion._cmp(self, other)
def consumer_supports_bootstrap_server(self):
"""
Kafka supported a new consumer beginning with v0.9.0 where
we can specify --bootstrap-server instead of --zookeeper.
This version also allowed a --consumer-config file where we could specify
a security protocol other than PLAINTEXT.
:return: true if the version of Kafka supports a new consumer with --bootstrap-server
"""
return self >= V_0_9_0_0
def supports_named_listeners(self):
return self >= V_0_10_2_0
def acl_command_supports_bootstrap_server(self):
return self >= V_2_1_0
def topic_command_supports_bootstrap_server(self):
return self >= V_2_3_0
def topic_command_supports_if_not_exists_with_bootstrap_server(self):
return self >= V_2_6_0
def supports_tls_to_zookeeper(self):
# indicate if KIP-515 is available
return self >= V_2_5_0
def reassign_partitions_command_supports_bootstrap_server(self):
return self >= V_2_5_0
def kafka_configs_command_uses_bootstrap_server(self):
# everything except User SCRAM Credentials (KIP-554)
return self >= V_2_6_0
def kafka_configs_command_uses_bootstrap_server_scram(self):
# User SCRAM Credentials (KIP-554)
return self >= V_2_7_0
def supports_topic_ids_when_using_zk(self):
# Supports topic IDs as described by KIP-516.
# Self-managed clusters always support topic ID, so this method only applies to ZK clusters.
return self >= V_2_8_0
def supports_fk_joins(self):
# while we support FK joins since 2.4, rolling upgrade is broken in older versions
# it's only fixed in 3.3.3 (unreleased) and 3.4.0
# -> https://issues.apache.org/jira/browse/KAFKA-14646
return hasattr(self, "version") and self >= V_3_4_0
def get_version(node=None):
"""Return the version attached to the given node.
Default to DEV_BRANCH if node or node.version is undefined (aka None)
"""
if node is not None and hasattr(node, "version") and node.version is not None:
return node.version
else:
return DEV_BRANCH
DEV_BRANCH = KafkaVersion("dev")
DEV_VERSION = KafkaVersion("3.8.0-SNAPSHOT")
# This should match the LATEST_PRODUCTION version defined in MetadataVersion.java
LATEST_STABLE_METADATA_VERSION = "3.8"
# 0.8.2.x versions
V_0_8_2_1 = KafkaVersion("0.8.2.1")
V_0_8_2_2 = KafkaVersion("0.8.2.2")
LATEST_0_8_2 = V_0_8_2_2
# 0.9.0.x versions
V_0_9_0_0 = KafkaVersion("0.9.0.0")
V_0_9_0_1 = KafkaVersion("0.9.0.1")
LATEST_0_9 = V_0_9_0_1
# 0.10.0.x versions
V_0_10_0_0 = KafkaVersion("0.10.0.0")
V_0_10_0_1 = KafkaVersion("0.10.0.1")
LATEST_0_10_0 = V_0_10_0_1
# 0.10.1.x versions
V_0_10_1_0 = KafkaVersion("0.10.1.0")
V_0_10_1_1 = KafkaVersion("0.10.1.1")
LATEST_0_10_1 = V_0_10_1_1
# 0.10.2.x versions
V_0_10_2_0 = KafkaVersion("0.10.2.0")
V_0_10_2_1 = KafkaVersion("0.10.2.1")
V_0_10_2_2 = KafkaVersion("0.10.2.2")
LATEST_0_10_2 = V_0_10_2_2
LATEST_0_10 = LATEST_0_10_2
# 0.11.0.x versions
V_0_11_0_0 = KafkaVersion("0.11.0.0")
V_0_11_0_1 = KafkaVersion("0.11.0.1")
V_0_11_0_2 = KafkaVersion("0.11.0.2")
V_0_11_0_3 = KafkaVersion("0.11.0.3")
LATEST_0_11_0 = V_0_11_0_3
LATEST_0_11 = LATEST_0_11_0
# 1.0.x versions
V_1_0_0 = KafkaVersion("1.0.0")
V_1_0_1 = KafkaVersion("1.0.1")
V_1_0_2 = KafkaVersion("1.0.2")
LATEST_1_0 = V_1_0_2
# 1.1.x versions
V_1_1_0 = KafkaVersion("1.1.0")
V_1_1_1 = KafkaVersion("1.1.1")
LATEST_1_1 = V_1_1_1
# 2.0.x versions
V_2_0_0 = KafkaVersion("2.0.0")
V_2_0_1 = KafkaVersion("2.0.1")
LATEST_2_0 = V_2_0_1
# 2.1.x versions
V_2_1_0 = KafkaVersion("2.1.0")
V_2_1_1 = KafkaVersion("2.1.1")
LATEST_2_1 = V_2_1_1
# 2.2.x versions
V_2_2_0 = KafkaVersion("2.2.0")
V_2_2_1 = KafkaVersion("2.2.1")
V_2_2_2 = KafkaVersion("2.2.2")
LATEST_2_2 = V_2_2_2
# 2.3.x versions
V_2_3_0 = KafkaVersion("2.3.0")
V_2_3_1 = KafkaVersion("2.3.1")
LATEST_2_3 = V_2_3_1
# 2.4.x versions
V_2_4_0 = KafkaVersion("2.4.0")
V_2_4_1 = KafkaVersion("2.4.1")
LATEST_2_4 = V_2_4_1
# 2.5.x versions
V_2_5_0 = KafkaVersion("2.5.0")
V_2_5_1 = KafkaVersion("2.5.1")
LATEST_2_5 = V_2_5_1
# 2.6.x versions
V_2_6_0 = KafkaVersion("2.6.0")
V_2_6_1 = KafkaVersion("2.6.1")
V_2_6_2 = KafkaVersion("2.6.2")
V_2_6_3 = KafkaVersion("2.6.3")
LATEST_2_6 = V_2_6_3
# 2.7.x versions
V_2_7_0 = KafkaVersion("2.7.0")
V_2_7_1 = KafkaVersion("2.7.1")
V_2_7_2 = KafkaVersion("2.7.2")
LATEST_2_7 = V_2_7_2
# 2.8.x versions
V_2_8_0 = KafkaVersion("2.8.0")
V_2_8_1 = KafkaVersion("2.8.1")
V_2_8_2 = KafkaVersion("2.8.2")
LATEST_2_8 = V_2_8_2
# 3.0.x versions
V_3_0_0 = KafkaVersion("3.0.0")
V_3_0_1 = KafkaVersion("3.0.1")
V_3_0_2 = KafkaVersion("3.0.2")
LATEST_3_0 = V_3_0_2
# 3.1.x versions
V_3_1_0 = KafkaVersion("3.1.0")
V_3_1_1 = KafkaVersion("3.1.1")
V_3_1_2 = KafkaVersion("3.1.2")
LATEST_3_1 = V_3_1_2
# 3.2.x versions
V_3_2_0 = KafkaVersion("3.2.0")
V_3_2_1 = KafkaVersion("3.2.1")
V_3_2_2 = KafkaVersion("3.2.2")
V_3_2_3 = KafkaVersion("3.2.3")
LATEST_3_2 = V_3_2_3
# 3.3.x versions
V_3_3_0 = KafkaVersion("3.3.0")
V_3_3_1 = KafkaVersion("3.3.1")
V_3_3_2 = KafkaVersion("3.3.2")
LATEST_3_3 = V_3_3_2
# 3.4.x versions
V_3_4_0 = KafkaVersion("3.4.0")
V_3_4_1 = KafkaVersion("3.4.1")
LATEST_3_4 = V_3_4_1
# 3.5.x versions
V_3_5_0 = KafkaVersion("3.5.0")
V_3_5_1 = KafkaVersion("3.5.1")
V_3_5_2 = KafkaVersion("3.5.2")
LATEST_3_5 = V_3_5_2
# 3.6.x versions
V_3_6_0 = KafkaVersion("3.6.0")
V_3_6_1 = KafkaVersion("3.6.1")
V_3_6_2 = KafkaVersion("3.6.2")
LATEST_3_6 = V_3_6_2
# 3.7.x version
V_3_7_0 = KafkaVersion("3.7.0")
LATEST_3_7 = V_3_7_0