Skip to content

Commit 93e598f

Browse files
authored
DPE-3865 misc test fixes (#480)
* increased timeout on clear * wait app be active * mistakenly removed flag * fixes for rollback from incompatible data_dir
1 parent 61b6dcf commit 93e598f

File tree

7 files changed

+21
-9
lines changed

7 files changed

+21
-9
lines changed

src/mysql_vm_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from constants import (
3737
CHARMED_MYSQL,
3838
CHARMED_MYSQL_COMMON_DIRECTORY,
39+
CHARMED_MYSQL_DATA_DIRECTORY,
3940
CHARMED_MYSQL_SNAP_NAME,
4041
CHARMED_MYSQL_XBCLOUD_LOCATION,
4142
CHARMED_MYSQL_XBSTREAM_LOCATION,
@@ -217,8 +218,9 @@ def uninstall_mysql() -> None:
217218
# uninstalls fail due to SNAP_DATA_DIR fails to umount
218219
# try umount it, without check
219220
subprocess.run(["umount", CHARMED_MYSQL_COMMON_DIRECTORY])
221+
shutil.rmtree(f"{CHARMED_MYSQL_DATA_DIRECTORY}/etc", ignore_errors=True)
220222
logger.exception(f"Failed to uninstall MySQL on {attempt=}")
221-
raise MySQLUninstallError
223+
raise MySQLUninstallError from None
222224

223225
@override
224226
def get_available_memory(self) -> int:

src/upgrade.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import logging
99
import pathlib
10+
import subprocess
1011
from typing import TYPE_CHECKING
1112

1213
from charms.data_platform_libs.v0.upgrade import (
@@ -55,6 +56,12 @@ def get_mysql_dependencies_model() -> MySQLVMDependenciesModel:
5556
return MySQLVMDependenciesModel(**_deps)
5657

5758

59+
def set_cron_daemon(action: str) -> None:
60+
"""Start/stop the cron daemon."""
61+
logger.debug(f"{action}ing cron daemon")
62+
subprocess.run(["systemctl", action, "cron"], check=True)
63+
64+
5865
class MySQLVMUpgrade(DataUpgrade):
5966
"""MySQL upgrade class."""
6067

@@ -189,6 +196,8 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None: # noqa: C901
189196
memory_limit=self.charm.config.profile_limit_memory,
190197
)
191198
self.charm.unit.status = MaintenanceStatus("starting services...")
199+
# stop cron daemon to be able to query `error.log`
200+
set_cron_daemon("stop")
192201
self.charm._mysql.start_mysqld()
193202
self.charm._mysql.setup_logrotate_and_cron()
194203
except VersionError:
@@ -215,6 +224,8 @@ def _on_upgrade_granted(self, event: UpgradeGrantedEvent) -> None: # noqa: C901
215224
logger.exception("Failed to stop MySQL server")
216225
self.set_unit_failed()
217226
return
227+
finally:
228+
set_cron_daemon("start")
218229

219230
try:
220231
self.charm.unit.set_workload_version(self.charm._mysql.get_mysql_version() or "unset")

tests/integration/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def is_relation_broken(ops_test: OpsTest, endpoint_one: str, endpoint_two: str)
266266
return False
267267

268268

269-
@retry(stop=stop_after_attempt(8), wait=wait_fixed(15), reraise=True)
269+
@retry(stop=stop_after_attempt(30), wait=wait_fixed(5), reraise=True)
270270
def is_connection_possible(
271271
credentials: Dict, *, retry_if_not_possible=False, **extra_opts
272272
) -> bool:

tests/integration/high_availability/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def continuous_writes(ops_test: OpsTest):
2121
application_unit = ops_test.model.applications[application_name].units[0]
2222

2323
logger.info("Clearing continuous writes")
24-
await juju_.run_action(application_unit, "clear-continuous-writes")
24+
await juju_.run_action(application_unit, "clear-continuous-writes", **{"timeout": 120})
2525

2626
logger.info("Starting continuous writes")
2727
await juju_.run_action(application_unit, "start-continuous-writes")

tests/integration/high_availability/test_async_replication.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ async def test_deploy_router_and_app(first_model: Model) -> None:
198198
logger.info("Relate router and db")
199199
await first_model.integrate(MYSQL_ROUTER_APP_NAME, MYSQL_APP1)
200200

201-
await first_model.wait_for_idle(
202-
apps=[MYSQL_ROUTER_APP_NAME, APPLICATION_APP_NAME],
203-
timeout=10 * MINUTE,
204-
raise_on_error=False,
201+
await first_model.block_until(
202+
lambda: first_model.applications[APPLICATION_APP_NAME].units[0].workload_status == "active"
205203
)
206204

207205

tests/integration/high_availability/test_upgrade_rollback_incompat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ async def test_upgrade_to_failling(
140140
# (details: https://github.com/canonical/mysql-operator/pull/472#discussion_r1659300069)
141141
@markers.amd64_only
142142
@pytest.mark.abort_on_fail
143-
@pytest.mark.unstable
144143
async def test_rollback(ops_test, continuous_writes) -> None:
145144
application = ops_test.model.applications[MYSQL_APP_NAME]
146145

@@ -152,7 +151,7 @@ async def test_rollback(ops_test, continuous_writes) -> None:
152151
new_revisions["x86_64"] = "69"
153152
with snap_revisions.open("w") as file:
154153
json.dump(new_revisions, file)
155-
charm = await charm_local_build(ops_test)
154+
charm = await charm_local_build(ops_test, refresh=True)
156155

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

tests/unit/test_upgrade.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_pre_upgrade_prepare(
131131
mock_get_primary_label.assert_called_once()
132132
assert mock_set_dynamic_variable.call_count == 2
133133

134+
@patch("upgrade.set_cron_daemon")
134135
@patch("mysql_vm_helpers.MySQL.write_mysqld_config")
135136
@patch("upgrade.MySQLVMUpgrade._check_server_unsupported_downgrade")
136137
@patch("upgrade.MySQLVMUpgrade._reset_on_unsupported_downgrade")
@@ -160,6 +161,7 @@ def test_upgrade_granted(
160161
mock_reset_on_unsupported_downgrade,
161162
mock_check_server_unsupported_downgrade,
162163
mock_write_mysqld_config,
164+
mock_set_cron_daemon,
163165
):
164166
"""Test upgrade-granted hook."""
165167
self.charm.on.config_changed.emit()

0 commit comments

Comments
 (0)