From 27d86ed6301e3083ac75304d1946b1049be3cddb Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 28 Mar 2024 18:04:11 +0000 Subject: [PATCH] Add extended attribute to get-cluster-status This changes from the default boolean that was being used internally to what mysql expects. The values between 0 and 3 are valid. --- actions.yaml | 6 ++++++ lib/charms/mysql/v0/mysql.py | 12 +++++++++--- src/upgrade.py | 2 +- tests/unit/test_mysql.py | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/actions.yaml b/actions.yaml index 59fbaa582..3ab85bcd0 100644 --- a/actions.yaml +++ b/actions.yaml @@ -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. diff --git a/lib/charms/mysql/v0/mysql.py b/lib/charms/mysql/v0/mysql.py index f14d0adba..280f0111c 100644 --- a/lib/charms/mysql/v0/mysql.py +++ b/lib/charms/mysql/v0/mysql.py @@ -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" @@ -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, @@ -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. diff --git a/src/upgrade.py b/src/upgrade.py index 5b9c86104..a139c23b7 100644 --- a/src/upgrade.py +++ b/src/upgrade.py @@ -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( diff --git a/tests/unit/test_mysql.py b/tests/unit/test_mysql.py index dcb19ca4e..4eab8432d 100644 --- a/tests/unit/test_mysql.py +++ b/tests/unit/test_mysql.py @@ -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)