Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extended attribute to get-cluster-status #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 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
arif-ali marked this conversation as resolved.
Show resolved Hide resolved
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)
arif-ali marked this conversation as resolved.
Show resolved Hide resolved

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

arif-ali marked this conversation as resolved.
Show resolved Hide resolved
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
Loading