Skip to content

Commit a310bcb

Browse files
MINOR: system-tests: fix KafkaServer#leader (#22168)
PR #7136 standardised the output format for TopicCommand to print `none` when the leader for a TP is unknown. `KafkaServer#leader` in system-tests however fails to account for this change and possibly panics trying to type cast `none` to an integer. This change fixes the regression so that we parse the value correctly and return None if the leader is undefined. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>, Federico Valeri <fedevaleri@gmail.com>
1 parent ebd7cd3 commit a310bcb

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tests/kafkatest/services/kafka/kafka.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,10 +1657,11 @@ def leader(self, topic, partition=0):
16571657
# e.g. Topic: test_topic Partition: 0 Leader: 3 Replicas: 3,2 Isr: 3,2
16581658
if not requested_partition_line:
16591659
raise Exception("Error finding partition state for topic %s and partition %d." % (topic, partition))
1660-
leader_idx = int(requested_partition_line.split()[5]) # 6th column from above
1660+
leader_idx_str = requested_partition_line.split()[5] # 6th column from above
1661+
leader_idx = int(leader_idx_str) if leader_idx_str != "none" else None
16611662

1662-
self.logger.info("Leader for topic %s and partition %d is now: %d" % (topic, partition, leader_idx))
1663-
return self.get_node(leader_idx)
1663+
self.logger.info("Leader for topic %s and partition %d is now: %s" % (topic, partition, leader_idx))
1664+
return self.get_node(leader_idx) if leader_idx is not None and leader_idx != -1 else None
16641665

16651666
def cluster_id(self):
16661667
""" Get the current cluster id

0 commit comments

Comments
 (0)