Skip to content

Commit

Permalink
[DPE-2317] Small upgrade fixes (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
deusebio authored Feb 23, 2024
1 parent 9b9b3b2 commit 336cd2e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
10 changes: 0 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/events/password_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def _set_password_action(self, event: ActionEvent) -> None:
event.fail(msg)
return

if not self.charm.upgrade.idle:
msg = f"Cannot set password while upgrading (upgrade_stack: {self.charm.upgrade.upgrade_stack})"
logger.error(msg)
event.fail(msg)
return

if not self.charm.healthy:
msg = "Unit is not healthy"
logger.error(msg)
Expand Down
9 changes: 9 additions & 0 deletions src/events/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ def __init__(self, charm: "KafkaCharm", **kwargs):
super().__init__(charm, **kwargs)
self.charm = charm

@property
def idle(self) -> bool:
"""Checks if cluster state is idle.
Returns:
True if cluster state is idle. Otherwise False
"""
return not bool(self.upgrade_stack)

@property
def current_version(self) -> str:
"""Get current Kafka version."""
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ def test_build_upgrade_stack(harness: Harness):
assert len(stack) == len(set(stack))


@pytest.mark.parametrize("upgrade_stack", ([], [0]))
def test_run_password_rotation_while_upgrading(harness, upgrade_stack):
harness.charm.upgrade.upgrade_stack = upgrade_stack
harness.set_leader(True)

mock_event = MagicMock()
mock_event.params = {"username": "admin"}

with (
patch("charm.KafkaCharm.healthy", new_callable=PropertyMock, return_value=True),
patch("managers.auth.AuthManager.add_user"),
):
harness.charm.password_action_events._set_password_action(mock_event)

if not upgrade_stack:
mock_event.set_results.assert_called()
else:
mock_event.fail.assert_called_with(
f"Cannot set password while upgrading (upgrade_stack: {upgrade_stack})"
)


def test_kafka_dependency_model():
assert sorted(KafkaDependencyModel.__fields__.keys()) == sorted(DEPENDENCIES.keys())

Expand Down

0 comments on commit 336cd2e

Please sign in to comment.