Skip to content

Commit 0894bc7

Browse files
Decrement mysql libpatch from 59 to 58 to match published version on charmhub (#449)
* Decrement mysql libpatch from 59 to 58 to match published version on charmhub * Update rollingops charmlib to v0.7
1 parent 410fd19 commit 0894bc7

File tree

9 files changed

+43
-28
lines changed

9 files changed

+43
-28
lines changed

lib/charms/mysql/v0/mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def wait_until_mysql_connection(self) -> None:
116116

117117
# Increment this PATCH version before using `charmcraft publish-lib` or reset
118118
# to 0 if you are raising the major API version
119-
LIBPATCH = 59
119+
LIBPATCH = 58
120120

121121
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
122122
UNIT_ADD_LOCKNAME = "unit-add"

lib/charms/rolling_ops/v0/rollingops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _on_trigger_restart(self, event):
8888

8989
# Increment this PATCH version before using `charmcraft publish-lib` or reset
9090
# to 0 if you are raising the major API version
91-
LIBPATCH = 6
91+
LIBPATCH = 7
9292

9393

9494
class LockNoRelationError(Exception):
@@ -318,6 +318,7 @@ def __init__(self, charm: CharmBase, relation: AnyStr, callback: Callable):
318318
self.framework.observe(charm.on[self.name].acquire_lock, self._on_acquire_lock)
319319
self.framework.observe(charm.on[self.name].run_with_lock, self._on_run_with_lock)
320320
self.framework.observe(charm.on[self.name].process_locks, self._on_process_locks)
321+
self.framework.observe(charm.on.leader_elected, self._on_process_locks)
321322

322323
def _callback(self: CharmBase, event: EventBase) -> None:
323324
"""Placeholder for the function that actually runs our event.

tests/unit/test_async_replication.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .helpers import patch_network_get
2727

2828

29+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
2930
class TestAsyncRelation(unittest.TestCase):
3031
def setUp(self) -> None:
3132
self.harness = Harness(MySQLOperatorCharm)
@@ -37,7 +38,7 @@ def setUp(self) -> None:
3738
self.async_replica = self.charm.async_replica
3839

3940
@patch("charm.MySQLOperatorCharm._mysql")
40-
def test_role(self, _mysql):
41+
def test_role(self, _mysql, _):
4142
_mysql.is_cluster_replica.return_value = True
4243
_mysql.get_member_state.return_value = (None, "primary")
4344
self.async_primary_relation_id = self.harness.add_relation(PRIMARY_RELATION, "db2")
@@ -55,7 +56,7 @@ def test_role(self, _mysql):
5556
del self.async_primary.role
5657

5758
@patch("charm.MySQLOperatorCharm._mysql")
58-
def test_async_relation_broken_primary(self, _mysql):
59+
def test_async_relation_broken_primary(self, _mysql, _):
5960
self.harness.set_leader(True)
6061
self.charm.on.config_changed.emit()
6162
self.async_primary_relation_id = self.harness.add_relation(PRIMARY_RELATION, "db2")
@@ -77,7 +78,7 @@ def test_async_relation_broken_primary(self, _mysql):
7778
)
7879

7980
@patch("charm.MySQLOperatorCharm._mysql")
80-
def test_async_relation_broken_replica(self, _mysql):
81+
def test_async_relation_broken_replica(self, _mysql, _):
8182
self.harness.set_leader(True)
8283
self.charm.on.config_changed.emit()
8384
async_primary_relation_id = self.harness.add_relation(PRIMARY_RELATION, "db2")
@@ -93,7 +94,7 @@ def test_async_relation_broken_replica(self, _mysql):
9394
self.assertNotIn("units-added-to-cluster", self.charm.app_peer_data)
9495

9596
@patch("charm.MySQLOperatorCharm._mysql")
96-
def test_get_state(self, _mysql):
97+
def test_get_state(self, _mysql, _):
9798
async_primary_relation_id = self.harness.add_relation(PRIMARY_RELATION, "db2")
9899
relation = self.harness.model.get_relation(PRIMARY_RELATION, async_primary_relation_id)
99100
assert relation
@@ -127,7 +128,7 @@ def test_get_state(self, _mysql):
127128

128129
@pytest.mark.usefixtures("with_juju_secrets")
129130
@patch("charm.MySQLOperatorCharm._mysql")
130-
def test_primary_created(self, _mysql):
131+
def test_primary_created(self, _mysql, _):
131132
self.harness.set_leader(True)
132133
self.charm.on.config_changed.emit()
133134

@@ -150,7 +151,7 @@ def test_primary_created(self, _mysql):
150151

151152
@patch("charms.mysql.v0.async_replication.MySQLAsyncReplicationPrimary.get_state")
152153
@patch("charm.MySQLOperatorCharm._mysql")
153-
def test_primary_relation_changed(self, _mysql, _get_state):
154+
def test_primary_relation_changed(self, _mysql, _get_state, _):
154155
self.harness.set_leader(True)
155156
async_primary_relation_id = self.harness.add_relation(PRIMARY_RELATION, "db2")
156157

@@ -203,7 +204,7 @@ def test_primary_relation_changed(self, _mysql, _get_state):
203204
self.assertTrue(isinstance(self.charm.unit.status, MaintenanceStatus))
204205

205206
@patch("charm.MySQLOperatorCharm._mysql")
206-
def test_state(self, _mysql):
207+
def test_state(self, _mysql, _):
207208
"""Test async replica state property."""
208209
self.assertIsNone(self.async_replica.state)
209210

@@ -239,7 +240,7 @@ def test_state(self, _mysql):
239240
self.assertEqual(self.async_replica.state, States.FAILED)
240241

241242
@patch("charm.MySQLOperatorCharm._mysql")
242-
def test_replica_created(self, _mysql):
243+
def test_replica_created(self, _mysql, _):
243244
"""Test replica creation."""
244245
self.harness.set_leader(True)
245246
self.charm.on.config_changed.emit()
@@ -255,7 +256,7 @@ def test_replica_created(self, _mysql):
255256
self.assertTrue(isinstance(self.charm.unit.status, WaitingStatus))
256257

257258
@patch("charm.MySQLOperatorCharm._mysql")
258-
def test_replica_created_user_data(self, _mysql):
259+
def test_replica_created_user_data(self, _mysql, _):
259260
"""Test replica creation."""
260261
self.harness.set_leader(True)
261262
self.charm.on.config_changed.emit()
@@ -284,7 +285,7 @@ def test_replica_created_user_data(self, _mysql):
284285
new_callable=PropertyMock,
285286
)
286287
@patch("charm.MySQLOperatorCharm._mysql")
287-
def test_replica_changed_syncing(self, _mysql, _state, _returning_cluster, _defer):
288+
def test_replica_changed_syncing(self, _mysql, _state, _returning_cluster, _defer, _):
288289
"""Test replica changed for syncing state."""
289290
self.harness.set_leader(True)
290291
self.charm.on.config_changed.emit()
@@ -361,7 +362,7 @@ def test_replica_changed_syncing(self, _mysql, _state, _returning_cluster, _defe
361362
new_callable=PropertyMock,
362363
)
363364
@patch("charm.MySQLOperatorCharm._mysql")
364-
def test_replica_changed_ready(self, _mysql, _state, _update_status):
365+
def test_replica_changed_ready(self, _mysql, _state, _update_status, _):
365366
"""Test replica changed for ready state."""
366367
self.harness.set_leader(True)
367368
self.charm.on.config_changed.emit()
@@ -385,7 +386,7 @@ def test_replica_changed_ready(self, _mysql, _state, _update_status):
385386
new_callable=PropertyMock,
386387
)
387388
@patch("charm.MySQLOperatorCharm._mysql")
388-
def test_replica_changed_recovering(self, _mysql, _state, _defer):
389+
def test_replica_changed_recovering(self, _mysql, _state, _defer, _):
389390
"""Test replica changed for ready state."""
390391
self.harness.set_leader(True)
391392
self.charm.on.config_changed.emit()
@@ -403,7 +404,7 @@ def test_replica_changed_recovering(self, _mysql, _state, _defer):
403404
self.assertEqual(self.charm.app_peer_data["units-added-to-cluster"], "2")
404405
_defer.assert_called_once()
405406

406-
def test_replica_created_non_leader(self):
407+
def test_replica_created_non_leader(self, _):
407408
"""Test replica changed for non-leader unit."""
408409
self.harness.set_leader(False)
409410
self.charm.unit_peer_data["member-state"] = "online"
@@ -412,7 +413,7 @@ def test_replica_created_non_leader(self):
412413
self.assertEqual(self.charm.unit_peer_data["member-state"], "waiting")
413414

414415
@patch("charm.MySQLOperatorCharm._mysql")
415-
def test_replica_changed_non_leader(self, _mysql):
416+
def test_replica_changed_non_leader(self, _mysql, _):
416417
"""Test replica changed for non-leader unit."""
417418
self.harness.set_leader(False)
418419
with self.harness.hooks_disabled():
@@ -430,7 +431,7 @@ def test_replica_changed_non_leader(self, _mysql):
430431

431432
# actions
432433
@patch("charm.MySQLOperatorCharm._mysql")
433-
def test_promote_standby_cluster(self, _mysql):
434+
def test_promote_standby_cluster(self, _mysql, _):
434435
self.harness.set_leader(True)
435436

436437
_mysql.is_cluster_replica.return_value = True
@@ -460,7 +461,7 @@ def test_promote_standby_cluster(self, _mysql):
460461

461462
@patch("charm.MySQLOperatorCharm._on_update_status")
462463
@patch("charm.MySQLOperatorCharm._mysql")
463-
def test_fence_cluster(self, _mysql, _update_status):
464+
def test_fence_cluster(self, _mysql, _update_status, _):
464465
self.harness.set_leader(True)
465466
# fail on wrong cluster set name
466467
with self.assertRaises(ActionFailed):
@@ -504,7 +505,7 @@ def test_fence_cluster(self, _mysql, _update_status):
504505

505506
@patch("charm.MySQLOperatorCharm._on_update_status")
506507
@patch("charm.MySQLOperatorCharm._mysql")
507-
def test_unfence_cluster(self, _mysql, _update_status):
508+
def test_unfence_cluster(self, _mysql, _update_status, _):
508509
self.harness.set_leader(True)
509510

510511
_mysql.is_cluster_replica.return_value = False
@@ -523,7 +524,7 @@ def test_unfence_cluster(self, _mysql, _update_status):
523524
_update_status.assert_called_once()
524525

525526
@patch("charm.MySQLOperatorCharm._mysql")
526-
def test_rejoin_cluster_action(self, _mysql):
527+
def test_rejoin_cluster_action(self, _mysql, _):
527528
with self.assertRaises(ActionFailed):
528529
self.harness.run_action("rejoin-cluster")
529530

tests/unit/test_backups.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def setUp(self):
3939
self.addCleanup(self.harness.cleanup)
4040
self.harness.begin()
4141
self.peer_relation_id = self.harness.add_relation("database-peers", "database-peers")
42-
self.harness.set_leader(True)
42+
with patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks") as _:
43+
self.harness.set_leader(True)
4344
self.harness.charm.on.config_changed.emit()
4445
self.charm = self.harness.charm
4546
self.s3_integrator_id = self.harness.add_relation(
@@ -319,9 +320,6 @@ def test_can_unit_perform_backup(
319320
_offline_mode_and_hidden_instance_exists,
320321
):
321322
"""Test _can_unit_perform_backup()."""
322-
self.harness.set_leader(True)
323-
self.charm.on.config_changed.emit()
324-
325323
success, error_message = self.mysql_backups._can_unit_perform_backup()
326324
self.assertTrue(success)
327325
self.assertIsNone(error_message)

tests/unit/test_database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def test_database_requested(
4141
_get_mysql_version,
4242
):
4343
# run start-up events to enable usage of the helper class
44-
self.harness.set_leader(True)
44+
with patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks") as _:
45+
self.harness.set_leader(True)
4546
self.charm.on.config_changed.emit()
4647

4748
# confirm that the relation databag is empty

tests/unit/test_db_router.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .helpers import patch_network_get
1818

1919

20+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
2021
class TestDBRouter(unittest.TestCase):
2122
def setUp(self):
2223
self.harness = Harness(MySQLOperatorCharm)
@@ -41,6 +42,7 @@ def test_db_router_relation_changed(
4142
_does_mysql_user_exist,
4243
_get_cluster_primary_address,
4344
_generate_random_password,
45+
_,
4446
):
4547
# run start-up events to enable usage of the helper class
4648
self.harness.set_leader(True)
@@ -128,6 +130,7 @@ def test_db_router_relation_changed_exceptions(
128130
_configure_mysqlrouter_user,
129131
_does_mysql_user_exist,
130132
_generate_random_password,
133+
_,
131134
):
132135
# run start-up events to enable usage of the helper class
133136
self.harness.set_leader(True)

tests/unit/test_relation_mysql_legacy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .helpers import patch_network_get
1414

1515

16+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
1617
class TestMariaDBRelation(unittest.TestCase):
1718
def setUp(self):
1819
self.harness = Harness(MySQLOperatorCharm)
@@ -37,6 +38,7 @@ def test_maria_db_relation_created(
3738
_get_or_set_password_in_peer_secrets,
3839
_get_cluster_primary_address,
3940
_does_mysql_user_exist,
41+
_,
4042
):
4143
# run start-up events to enable usage of the helper class
4244
self.harness.set_leader(True)
@@ -92,6 +94,7 @@ def test_maria_db_relation_created_with_secrets(
9294
_get_or_set_password_in_peer_secrets,
9395
_get_cluster_primary_address,
9496
_does_mysql_user_exist,
97+
_,
9598
):
9699
# run start-up events to enable usage of the helper class
97100
self.harness.set_leader(True)
@@ -151,6 +154,7 @@ def test_maria_db_relation_departed(
151154
_delete_users_for_unit,
152155
_get_cluster_primary_address,
153156
_does_mysql_user_exist,
157+
_,
154158
):
155159
# run start-up events to enable usage of the helper class
156160
self.harness.set_leader(True)

tests/unit/test_shared_db.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .helpers import patch_network_get
1515

1616

17+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
1718
class TestSharedDBRelation(unittest.TestCase):
1819
def setUp(self):
1920
self.harness = Harness(MySQLOperatorCharm)
@@ -34,6 +35,7 @@ def test_shared_db_relation_changed(
3435
_create_application_database_and_scoped_user,
3536
_generate_random_password,
3637
_get_cluster_primary_address,
38+
_,
3739
):
3840
# run start-up events to enable usage of the helper class
3941
self.harness.set_leader(True)
@@ -89,7 +91,7 @@ def test_shared_db_relation_changed(
8991
@patch("utils.generate_random_password", return_value="super_secure_password")
9092
@patch("mysql_vm_helpers.MySQL.create_application_database_and_scoped_user")
9193
def test_shared_db_relation_changed_error_on_user_creation(
92-
self, _create_application_database_and_scoped_user, _generate_random_password
94+
self, _create_application_database_and_scoped_user, _generate_random_password, _
9395
):
9496
# run start-up events to enable usage of the helper class
9597
self.harness.set_leader(True)
@@ -123,6 +125,7 @@ def test_shared_db_relation_departed(
123125
_generate_random_password,
124126
_delete_users_for_unit,
125127
_get_cluster_primary_address,
128+
_,
126129
):
127130
# run start-up events to enable usage of the helper class
128131
self.harness.set_leader(True)

tests/unit/test_upgrade.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def test_build_upgrade_stack(self):
6060
self.assertTrue(len(us) == 3)
6161
self.assertEqual(us, [0, 1, 2])
6262

63+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
6364
@patch("charm.MySQLOperatorCharm.get_unit_ip", return_value="10.0.1.1")
6465
@patch("upgrade.MySQLVMUpgrade._pre_upgrade_prepare")
6566
@patch("mysql_vm_helpers.MySQL.get_cluster_status", return_value=MOCK_STATUS_ONLINE)
6667
def test_pre_upgrade_check(
67-
self, mock_get_cluster_status, mock_pre_upgrade_prepare, mock_get_unit_ip
68+
self, mock_get_cluster_status, mock_pre_upgrade_prepare, mock_get_unit_ip, _
6869
):
6970
"""Test the pre upgrade check."""
7071
self.harness.set_leader(True)
@@ -107,6 +108,7 @@ def test_log_rollback(self, mock_logging):
107108
]
108109
mock_logging.assert_has_calls(calls)
109110

111+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
110112
@patch("charm.MySQLOperatorCharm.get_unit_ip", return_value="10.0.1.1")
111113
@patch("mysql_vm_helpers.MySQL.set_dynamic_variable")
112114
@patch("mysql_vm_helpers.MySQL.get_primary_label", return_value="mysql-1")
@@ -117,6 +119,7 @@ def test_pre_upgrade_prepare(
117119
mock_get_primary_label,
118120
mock_set_dynamic_variable,
119121
mock_get_unit_ip,
122+
_,
120123
):
121124
"""Test the pre upgrade prepare."""
122125
self.harness.set_leader(True)
@@ -261,8 +264,9 @@ def test_reset_on_unsupported_downgrade(
261264
self.assertEqual(self.charm.unit_peer_data["member-role"], "secondary")
262265
self.assertEqual(self.charm.unit_peer_data["member-state"], "waiting")
263266

267+
@patch("charms.rolling_ops.v0.rollingops.RollingOpsManager._on_process_locks")
264268
@patch("upgrade.MySQLVMUpgrade._prepare_upgrade_from_legacy")
265-
def test_upgrade_charm_legacy(self, mock_prepare_upgrade_from_legacy):
269+
def test_upgrade_charm_legacy(self, mock_prepare_upgrade_from_legacy, _):
266270
self.harness.update_relation_data(self.upgrade_relation_id, "mysql/0", {"state": ""})
267271

268272
# non leader

0 commit comments

Comments
 (0)