Skip to content

Commit

Permalink
Avoid any actions when a unit is offline and allow mysql GR to recover (
Browse files Browse the repository at this point in the history
#334)

* Avoid any actions when a unit is offline and allow mysql GR to recover

* Port over fixes for test_upgrade_from_stable from profile limits option branch
  • Loading branch information
shayancanonical authored Oct 6, 2023
1 parent e4532cf commit 2e9e55e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
5 changes: 0 additions & 5 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ def _handle_non_online_instance_status(self, state) -> None:
except MySQLRebootFromCompleteOutageError:
logger.error("Failed to reboot cluster from complete outage.")
self.unit.status = BlockedStatus("failed to recover cluster.")
primary = self._get_primary_from_online_peer()
if primary:
# Reset variables to allow unit join the cluster
self.unit_peer_data["member-state"] = "waiting"
del self.unit_peer_data["unit-initialized"]

if state == "unreachable":
try:
Expand Down
35 changes: 32 additions & 3 deletions tests/integration/high_availability/test_upgrade_from_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import logging

import pytest
from integration.helpers import (
get_leader_unit,
get_primary_unit_wrapper,
retrieve_database_variable_value,
)
from integration.high_availability.high_availability_helpers import (
ensure_all_units_continuous_writes_incrementing,
relate_mysql_and_application,
Expand All @@ -21,17 +26,16 @@

@pytest.mark.group(1)
@pytest.mark.abort_on_fail
async def test_deploy_latest(ops_test: OpsTest, mysql_charm_series: str) -> None:
async def test_deploy_stable(ops_test: OpsTest, mysql_charm_series: str) -> None:
"""Simple test to ensure that the mysql and application charms get deployed."""
await asyncio.gather(
ops_test.model.deploy(
MYSQL_APP_NAME,
application_name=MYSQL_APP_NAME,
num_units=3,
channel="8.0/stable",
constraints="mem=2G",
series=mysql_charm_series,
# config={"profile": "testing"}, # config not available in 8.0/stable@r151
config={"profile": "testing"},
),
ops_test.model.deploy(
TEST_APP_NAME,
Expand All @@ -50,6 +54,31 @@ async def test_deploy_latest(ops_test: OpsTest, mysql_charm_series: str) -> None
assert len(ops_test.model.applications[MYSQL_APP_NAME].units) == 3


@pytest.mark.group(1)
@pytest.mark.abort_on_fail
async def test_pre_upgrade_check(ops_test: OpsTest) -> None:
"""Test that the pre-upgrade-check action runs successfully."""
mysql_units = ops_test.model.applications[MYSQL_APP_NAME].units

logger.info("Get leader unit")
leader_unit = await get_leader_unit(ops_test, MYSQL_APP_NAME)

assert leader_unit is not None, "No leader unit found"
logger.info("Run pre-upgrade-check action")
action = await leader_unit.run_action("pre-upgrade-check")
await action.wait()

logger.info("Assert slow shutdown is enabled")
for unit in mysql_units:
value = await retrieve_database_variable_value(ops_test, unit, "innodb_fast_shutdown")
assert value == 0, f"innodb_fast_shutdown not 0 at {unit.name}"

primary_unit = await get_primary_unit_wrapper(ops_test, MYSQL_APP_NAME)

logger.info("Assert primary is set to leader")
assert await primary_unit.is_leader_from_status(), "Primary unit not set to leader"


@pytest.mark.group(1)
async def test_upgrade_from_stable(ops_test: OpsTest):
"""Test updating from stable channel."""
Expand Down

0 comments on commit 2e9e55e

Please sign in to comment.