Skip to content

Commit

Permalink
fix: Fix endpoints getter for older zk versions
Browse files Browse the repository at this point in the history
Used in upgrade integration test
  • Loading branch information
Batalex committed Dec 3, 2024
1 parent 5a18cae commit 451432a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
from functools import cached_property
from typing import MutableMapping, TypeAlias, TypedDict
from operator import itemgetter

import requests
from charms.data_platform_libs.v0.data_interfaces import (
Expand Down Expand Up @@ -741,9 +742,15 @@ def zookeeper_connected(self) -> bool:
def zookeeper_version(self) -> str:
"""Get running zookeeper version."""
hosts = [host.split(":")[0] for host in self.endpoints.split(",")]
port = next(
iter([int(host.split(":")[1]) for host in reversed(self.endpoints.split(","))]), 2181
)
try:
port = next(
iter([int(host.split(":")[1]) for host in reversed(self.endpoints.split(","))]),
2181,
)
except IndexError:
# compatibility with older zk versions
port = 2181

zk = ZooKeeperManager(
hosts=hosts,
client_port=port,
Expand All @@ -766,9 +773,15 @@ def broker_active(self) -> bool:
broker_id = self.data_interface.local_unit.name.split("/")[1]
path = f"{self.database}/brokers/ids/"
hosts = [host.split(":")[0] for host in self.endpoints.split(",")]
port = next(
iter([int(host.split(":")[1]) for host in reversed(self.endpoints.split(","))]), 2181
)
try:
port = next(
iter([int(host.split(":")[1]) for host in reversed(self.endpoints.split(","))]),
2181,
)
except IndexError:
# compatibility with older zk versions
port = 2181

zk = ZooKeeperManager(
hosts=hosts,
client_port=port,
Expand Down

0 comments on commit 451432a

Please sign in to comment.