Skip to content

Commit

Permalink
ensure cluster metadata node addresses consistency (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomach authored Oct 20, 2023
1 parent efe048b commit 67bc953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from charms.mysql.v0.mysql import (
MySQLGetMySQLVersionError,
MySQLRescanClusterError,
MySQLSetClusterPrimaryError,
MySQLSetVariableError,
)
Expand Down Expand Up @@ -88,6 +89,17 @@ def _count_online_instances(status_dict: dict) -> int:
if not item.get("instanceerrors", [])
].count("online")

try:
# ensure cluster node addresses are consistent in cluster metadata
# https://github.com/canonical/mysql-k8s-operator/issues/327
self.charm._mysql.rescan_cluster()
except MySQLRescanClusterError:
raise ClusterNotReadyError(
message=fail_message,
cause="Failed to rescan cluster",
resolution="Check the cluster status",
)

if cluster_status := self.charm._mysql.get_cluster_status(extended=True):
if _count_online_instances(cluster_status) < self.charm.app.planned_units():
# case any not fully online unit is found
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ def test_highest_ordinal(self):
"""Test the highest ordinal."""
self.assertEqual(1, self.charm.upgrade.highest_ordinal)

@patch("mysql_k8s_helpers.MySQL.rescan_cluster")
@patch("upgrade.MySQLK8sUpgrade._pre_upgrade_prepare")
@patch("mysql_k8s_helpers.MySQL.get_cluster_status", return_value=MOCK_STATUS_ONLINE)
def test_pre_upgrade_check(self, mock_get_cluster_status, mock_pre_upgrade_prepare):
def test_pre_upgrade_check(
self, mock_get_cluster_status, mock_pre_upgrade_prepare, mock_rescan_cluster
):
"""Test the pre upgrade check."""
self.harness.set_leader(True)
self.charm.on.config_changed.emit()

self.charm.upgrade.pre_upgrade_check()
mock_rescan_cluster.assert_called_once()
mock_pre_upgrade_prepare.assert_called_once()
mock_get_cluster_status.assert_called_once()

Expand Down

0 comments on commit 67bc953

Please sign in to comment.