Skip to content

Commit a94a385

Browse files
committed
add missing action for mysql charm test compatibility
1 parent 587e7a8 commit a94a385

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

actions.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ get-session-ssl-cipher:
2727
get-server-certificate:
2828
description: Retrieve server certificate in pem format
2929

30+
get-legacy-mysql-credentials:
31+
description: Get the credentials for the legacy mysql user

src/relations/legacy_mysql.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from literals import DATABASE_NAME, LEGACY_MYSQL_RELATION
99
from ops.framework import Object
10-
from ops.model import ActiveStatus, BlockedStatus
10+
from ops.model import BlockedStatus
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -25,6 +25,9 @@ def __init__(self, charm):
2525
self.framework.observe(
2626
charm.on[LEGACY_MYSQL_RELATION].relation_broken, self._on_relation_broken
2727
)
28+
self.framework.observe(
29+
charm.on.get_legacy_mysql_credentials_action, self._get_legacy_mysql_credentials
30+
)
2831

2932
def _on_relation_joined(self, event):
3033
if not self.charm.unit.is_leader():
@@ -71,3 +74,14 @@ def _on_relation_broken(self, _):
7174
self.charm.app_peer_data.pop(f"{LEGACY_MYSQL_RELATION}-password", None)
7275
self.charm.app_peer_data.pop(f"{LEGACY_MYSQL_RELATION}-host", None)
7376
self.charm.app_peer_data.pop(f"{LEGACY_MYSQL_RELATION}-database", None)
77+
78+
def _get_legacy_mysql_credentials(self, event) -> None:
79+
"""Retrieve legacy mariadb credentials."""
80+
event.set_results(
81+
{
82+
"username": self.charm.app_peer_data[f"{LEGACY_MYSQL_RELATION}-user"],
83+
"password": self.charm.app_peer_data[f"{LEGACY_MYSQL_RELATION}-password"],
84+
"host": self.charm.app_peer_data[f"{LEGACY_MYSQL_RELATION}-host"],
85+
"database": self.charm.app_peer_data[f"{LEGACY_MYSQL_RELATION}-database"],
86+
}
87+
)

0 commit comments

Comments
 (0)