Skip to content

Commit

Permalink
Remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Jun 25, 2024
1 parent 842b6b2 commit 1b589c8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 96 deletions.
2 changes: 0 additions & 2 deletions actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,3 @@ set-tls-private-key:
private-key:
type: string
description: The content of private key for communications with clients. Content will be auto-generated if this option is not specified.
reenable-oversee-users:
description: Reenable purging of managed credentials after a standby cluster is promoted.
15 changes: 0 additions & 15 deletions src/relations/async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def __init__(self, charm):
self.framework.observe(
self.charm.on.promote_to_primary_action, self._on_promote_to_primary
)
self.framework.observe(
self.charm.on.reenable_oversee_users_action, self._on_reenable_oversee_users
)

self.framework.observe(self.charm.on.secret_changed, self._on_secret_changed)

Expand Down Expand Up @@ -603,18 +600,6 @@ def _on_promote_to_primary(self, event: ActionEvent) -> None:
# Set the status.
self.charm.unit.status = MaintenanceStatus("Creating replication...")

def _on_reenable_oversee_users(self, event: ActionEvent) -> None:
"""Re-enable oversee users after cluster was promoted."""
if not self.charm.unit.is_leader():
event.fail("Unit is not leader")
return

if "suppress-oversee-users" not in self.charm.app_peer_data:
event.fail("Oversee users is not suppressed")
return

del self.charm.app_peer_data["suppress-oversee-users"]

def _on_secret_changed(self, event: SecretChangedEvent) -> None:
"""Update the internal secret when the relation secret changes."""
relation = self._relation
Expand Down
21 changes: 11 additions & 10 deletions src/relations/postgresql_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def oversee_users(self) -> None:
if not self.charm.unit.is_leader():
return

if "suppress-oversee-users" in self.charm.app_peer_data:
logger.debug("Oversee users is suppressed by peer data")
return
delete_user = "suppress-oversee-users" not in self.charm.app_peer_data

# Retrieve database users.
try:
Expand All @@ -163,13 +161,16 @@ def oversee_users(self) -> None:

# Delete that users that exist in the database but not in the active relations.
for user in database_users - relation_users:
try:
logger.info("Remove relation user: %s", user)
self.charm.set_secret(APP_SCOPE, user, None)
self.charm.set_secret(APP_SCOPE, f"{user}-database", None)
self.charm.postgresql.delete_user(user)
except PostgreSQLDeleteUserError:
logger.error(f"Failed to delete user {user}")
if delete_user:
try:
logger.info("Remove relation user: %s", user)
self.charm.set_secret(APP_SCOPE, user, None)
self.charm.set_secret(APP_SCOPE, f"{user}-database", None)
self.charm.postgresql.delete_user(user)
except PostgreSQLDeleteUserError:
logger.error("Failed to delete user %s", user)
else:
logger.info("Stale relation user detected: %s", user)

def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None:
"""Set the read/write and read-only endpoints."""
Expand Down
22 changes: 1 addition & 21 deletions tests/integration/ha_tests/test_async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import contextlib
import logging
import subprocess
from asyncio import gather, sleep
from asyncio import gather
from typing import Optional

import psycopg2
Expand Down Expand Up @@ -318,26 +318,6 @@ async def test_data_integrator_creds_keep_on_working(
finally:
connection.close()

logger.info("Re-enable oversee users")
leader_unit = await get_leader_unit(ops_test, DATABASE_APP_NAME, model=second_model)
action = await leader_unit.run_action(action_name="reenable-oversee-users")
await action.wait()

async with fast_forward(second_model, FAST_INTERVAL):
await sleep(20)
await second_model.wait_for_idle(
apps=[DATABASE_APP_NAME],
status="active",
timeout=TIMEOUT,
)
try:
with psycopg2.connect(connstr) as connection:
assert False
except psycopg2.OperationalError:
logger.info("Data integrator creds purged")
finally:
connection.close()


@pytest.mark.group(1)
@markers.juju3
Expand Down
48 changes: 0 additions & 48 deletions tests/unit/test_async_replication.py

This file was deleted.

0 comments on commit 1b589c8

Please sign in to comment.