Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def _on_get_password(self, event: ActionEvent) -> None:
f" {', '.join(SYSTEM_USERS)} not {username}"
)
return
event.set_results({f"{username}-password": self.get_secret("app", f"{username}-password")})
event.set_results({"password": self.get_secret("app", f"{username}-password")})

def _on_set_password(self, event: ActionEvent) -> None:
"""Set the password for the specified user."""
Expand All @@ -572,7 +572,7 @@ def _on_set_password(self, event: ActionEvent) -> None:

if password == self.get_secret("app", f"{username}-password"):
event.log("The old and new passwords are equal.")
event.set_results({f"{username}-password": password})
event.set_results({"password": password})
return

# Ensure all members are ready before trying to reload Patroni
Expand Down Expand Up @@ -601,7 +601,7 @@ def _on_set_password(self, event: ActionEvent) -> None:
# Other units Patroni configuration will be reloaded in the peer relation changed event.
self.update_config()

event.set_results({f"{username}-password": password})
event.set_results({"password": password})

def _on_get_primary(self, event: ActionEvent) -> None:
"""Get primary instance."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ async def get_password(
if unit.name != down_unit:
action = await unit.run_action("get-password", **{"username": username})
result = await action.wait()
return result.results[f"{username}-password"]
return result.results["password"]


@retry(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_password_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ async def test_password_rotation(ops_test: OpsTest):

# Change both passwords.
result = await set_password(ops_test, unit_name=leader)
assert "operator-password" in result.keys()
assert "password" in result.keys()
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)

# For replication, generate a specific password and pass it to the action.
new_replication_password = "test-password"
result = await set_password(
ops_test, unit_name=leader, username="replication", password=new_replication_password
)
assert "replication-password" in result.keys()
assert "password" in result.keys()
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)

new_superuser_password = await get_password(ops_test)
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,13 @@ def test_on_get_password(self):
mock_event.reset_mock()
del mock_event.params["username"]
self.charm._on_get_password(mock_event)
mock_event.set_results.assert_called_once_with({"operator-password": "test-password"})
mock_event.set_results.assert_called_once_with({"password": "test-password"})

# Also test providing the username option.
mock_event.reset_mock()
mock_event.params["username"] = "replication"
self.charm._on_get_password(mock_event)
mock_event.set_results.assert_called_once_with(
{"replication-password": "replication-test-password"}
)
mock_event.set_results.assert_called_once_with({"password": "replication-test-password"})

@patch("charm.Patroni.reload_patroni_configuration")
@patch("charm.PostgresqlOperatorCharm.update_config")
Expand Down