Skip to content

Commit

Permalink
Add extended attribute to get-cluster-status
Browse files Browse the repository at this point in the history
This changes from the default boolean that was being used internally
to what mysql expects. The values between 0 and 3 are valid.
  • Loading branch information
arif-ali committed Apr 4, 2024
1 parent 2bd2bcc commit 27d86ed
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

get-cluster-status:
description: Get cluster status information
params:
extended:
type: integer
default: 0
description: The extended attribute for cluster-status, the default value 0.
possible values - 0, 1, 2, 3

get-password:
description: Fetch the system user's password, which is used by charm.
Expand Down
12 changes: 9 additions & 3 deletions lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def wait_until_mysql_connection(self) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 56
LIBPATCH = 57

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -494,7 +494,13 @@ def _on_set_password(self, event: ActionEvent) -> None:

def _get_cluster_status(self, event: ActionEvent) -> None:
"""Action used to retrieve the cluster status."""
if status := self._mysql.get_cluster_status():
extended = event.params.get("extended", 0)

if not 0 <= extended < 4:
event.fail("Extended parameter outside valid range")
return

if status := self._mysql.get_cluster_status(extended):
event.set_results(
{
"success": True,
Expand Down Expand Up @@ -1422,7 +1428,7 @@ def is_instance_in_cluster(self, unit_label: str) -> bool:
stop=stop_after_attempt(3),
retry=retry_if_exception_type(TimeoutError),
)
def get_cluster_status(self, extended: Optional[bool] = False) -> Optional[dict]:
def get_cluster_status(self, extended: Optional[int] = 0) -> Optional[dict]:
"""Get the cluster status.
Executes script to retrieve cluster status.
Expand Down
2 changes: 1 addition & 1 deletion src/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _online_instances(status_dict: dict) -> int:
if not item.get("instanceerrors", [])
].count("online")

if cluster_status := self.charm._mysql.get_cluster_status(extended=True):
if cluster_status := self.charm._mysql.get_cluster_status(extended=1):
if _online_instances(cluster_status) < self.charm.app.planned_units():
# case any not fully online unit is found
raise ClusterNotReadyError(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def test_get_cluster_status(self, _run_mysqlsh_script):
(
"shell.connect('clusteradmin:clusteradminpassword@127.0.0.1')",
"cluster = dba.get_cluster('test_cluster')",
"print(cluster.status({'extended': False}))",
"print(cluster.status({'extended': 0}))",
)
)
_run_mysqlsh_script.assert_called_once_with(expected_commands, timeout=30)
Expand Down

0 comments on commit 27d86ed

Please sign in to comment.