Skip to content

Commit 61b6dcf

Browse files
Remove unused key/values from the databag (#484)
* Remove unused key/values from the databag * Update libpatch * Execute network cut lxc commands on the default project * Catch exceptions to see what may be going wrong on CI with network cut * Attempt downgrade of lxd snap to avoid websocket close error * Revert unnecessary modifications in the integration test helpers
1 parent afb2a0d commit 61b6dcf

File tree

9 files changed

+3
-42
lines changed

9 files changed

+3
-42
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
cloud: lxd
9090
juju-agent-version: ${{ matrix.juju.agent }}
9191
libjuju-version-constraint: ${{ matrix.juju.libjuju }}
92+
lxd-snap-channel: 5.21/stable
9293
_beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }}
9394
secrets:
9495
# GitHub appears to redact each line of a multi-line secret

lib/charms/mysql/v0/async_replication.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# The unique Charmhub library identifier, never change it
5555
LIBID = "4de21f1a022c4e2c87ac8e672ec16f6a"
5656
LIBAPI = 0
57-
LIBPATCH = 4
57+
LIBPATCH = 5
5858

5959
RELATION_OFFER = "replication-offer"
6060
RELATION_CONSUMER = "replication"
@@ -248,8 +248,6 @@ def on_async_relation_broken(self, event: RelationBrokenEvent): # noqa: C901
248248
"\tThe cluster can be recreated with the `recreate-cluster` action.\n"
249249
"\tAlternatively the cluster can be rejoined to the cluster set."
250250
)
251-
# reset the cluster node count flag
252-
del self._charm.app_peer_data["units-added-to-cluster"]
253251
# set flag to persist removed from cluster-set state
254252
self._charm.app_peer_data["removed-from-cluster-set"] = "true"
255253

@@ -834,8 +832,6 @@ def _on_consumer_changed(self, event): # noqa: C901
834832
self._charm.unit.status = MaintenanceStatus("Dissolving replica cluster")
835833
logger.info("Dissolving replica cluster")
836834
self._charm._mysql.dissolve_cluster()
837-
# reset the cluster node count flag
838-
del self._charm.app_peer_data["units-added-to-cluster"]
839835
# reset force rejoin-secondaries flag
840836
del self._charm.app_peer_data["rejoin-secondaries"]
841837

@@ -869,11 +865,6 @@ def _on_consumer_changed(self, event): # noqa: C901
869865
if cluster_set_domain_name := self._charm._mysql.get_cluster_set_name():
870866
self._charm.app_peer_data["cluster-set-domain-name"] = cluster_set_domain_name
871867

872-
# set the number of units added to the cluster for a single unit replica cluster
873-
# needed here since it will skip the `RECOVERING` state
874-
if self._charm.app.planned_units() == 1:
875-
self._charm.app_peer_data["units-added-to-cluster"] = "1"
876-
877868
self._charm._on_update_status(None)
878869
elif state == States.RECOVERING:
879870
# recovering cluster (copying data and/or joining units)
@@ -882,10 +873,6 @@ def _on_consumer_changed(self, event): # noqa: C901
882873
"Waiting for recovery to complete on other units"
883874
)
884875
logger.debug("Awaiting other units to join the cluster")
885-
# reset the number of units added to the cluster
886-
# this will trigger secondaries to join the cluster
887-
node_count = self._charm._mysql.get_cluster_node_count()
888-
self._charm.app_peer_data["units-added-to-cluster"] = str(node_count)
889876
# set state flags to allow secondaries to join the cluster
890877
self._charm.unit_peer_data["member-state"] = "online"
891878
self._charm.unit_peer_data["member-role"] = "primary"

lib/charms/mysql/v0/mysql.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def wait_until_mysql_connection(self) -> None:
128128
# Increment this major API version when introducing breaking changes
129129
LIBAPI = 0
130130

131-
LIBPATCH = 62
131+
LIBPATCH = 63
132132

133133
UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
134134
UNIT_ADD_LOCKNAME = "unit-add"
@@ -589,7 +589,6 @@ def create_cluster(self) -> None:
589589
# rescan cluster for cleanup of unused
590590
# recovery users
591591
self._mysql.rescan_cluster()
592-
self.app_peer_data["units-added-to-cluster"] = "1"
593592

594593
state, role = self._mysql.get_member_state()
595594

src/charm.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,6 @@ def _on_update_status(self, _) -> None: # noqa: C901
508508
self._handle_non_online_instance_status(state)
509509

510510
if self.unit.is_leader():
511-
nodes = self._mysql.get_cluster_node_count()
512-
if nodes > 0:
513-
self.app_peer_data["units-added-to-cluster"] = str(nodes)
514511
try:
515512
primary_address = self._mysql.get_cluster_primary_address()
516513
except MySQLGetClusterPrimaryAddressError:
@@ -818,7 +815,6 @@ def join_unit_to_cluster(self) -> None:
818815
self.unit.status = WaitingStatus("waiting to join the cluster")
819816
logger.debug("Waiting to joing the cluster, failed to acquire lock.")
820817
return
821-
# Update 'units-added-to-cluster' counter in the peer relation databag
822818
self.unit_peer_data["member-state"] = "online"
823819
self.unit.status = ActiveStatus(self.active_status_message)
824820
logger.debug(f"Instance {instance_label} is cluster member")

tests/unit/test_async_replication.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ def test_async_relation_broken_consumer(self, _mysql, _, _cluster_initialized):
100100
self.harness.remove_relation(async_primary_relation_id)
101101

102102
self.assertEqual(self.charm.app_peer_data["removed-from-cluster-set"], "true")
103-
self.assertNotIn("unit-initialized", self.charm.unit_peer_data)
104-
self.assertNotIn("units-added-to-cluster", self.charm.app_peer_data)
105103

106104
@patch("charm.MySQLOperatorCharm._mysql")
107105
def test_get_state(self, _mysql, _):
@@ -150,13 +148,6 @@ def test_create_replication(self, _mysql, _, _cluster_initialized):
150148
_mysql.get_mysql_version.return_value = "8.0.36-0ubuntu0.22.04.1"
151149
_mysql.get_member_state.return_value = ("online", "primary")
152150

153-
self.harness.update_relation_data(
154-
self.peers_relation_id, self.charm.unit.name, {"unit-initialized": "True"}
155-
)
156-
self.harness.update_relation_data(
157-
self.peers_relation_id, self.charm.app.name, {"units-added-to-cluster": "1"}
158-
)
159-
160151
async_primary_relation_id = self.harness.add_relation(
161152
RELATION_OFFER, "db2", app_data={"is-replica": "true"}
162153
)
@@ -317,9 +308,6 @@ def test_consumer_changed_syncing(self, _mysql, _state, _returning_cluster, _def
317308
self.harness.set_leader(True)
318309
self.charm.on.config_changed.emit()
319310

320-
self.harness.update_relation_data(
321-
self.peers_relation_id, self.charm.unit.name, {"unit-initialized": "True"}
322-
)
323311
async_relation_id = self.harness.add_relation(RELATION_CONSUMER, "db1")
324312

325313
# 1. returning cluster
@@ -409,7 +397,6 @@ def test_consumer_changed_ready(self, _mysql, _state, _update_status, _, _unit_i
409397

410398
_update_status.assert_called_once()
411399
self.assertEqual(self.charm.app_peer_data["cluster-set-domain-name"], "cluster-set-test")
412-
self.assertEqual(self.charm.app_peer_data["units-added-to-cluster"], "1")
413400

414401
@patch("ops.framework.EventBase.defer")
415402
@patch(
@@ -432,7 +419,6 @@ def test_consumer_changed_recovering(self, _mysql, _state, _defer, _):
432419
{"some": "data3"},
433420
)
434421

435-
self.assertEqual(self.charm.app_peer_data["units-added-to-cluster"], "2")
436422
_defer.assert_called_once()
437423

438424
def test_consumer_created_non_leader(self, _):

tests/unit/test_charm.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ def test_on_start_exceptions(
259259
"charm.MySQLOperatorCharm.unit_initialized", new_callable=PropertyMock(return_value=True)
260260
)
261261
@patch("charms.mysql.v0.mysql.MySQLCharmBase.active_status_message", return_value="")
262-
@patch("mysql_vm_helpers.MySQL.get_cluster_node_count", return_value=1)
263262
@patch("mysql_vm_helpers.MySQL.get_member_state")
264263
@patch("mysql_vm_helpers.MySQL.get_cluster_primary_address")
265264
@patch("charm.is_volume_mounted", return_value=True)
@@ -274,7 +273,6 @@ def test_on_update(
274273
_is_volume_mounted,
275274
_get_cluster_primary_address,
276275
_get_member_state,
277-
_get_cluster_node_count,
278276
_active_status_message,
279277
_unit_initialized,
280278
_cluster_initialized,
@@ -297,7 +295,6 @@ def test_on_update(
297295
_reboot_from_complete_outage.assert_not_called()
298296
_snap_service_operation.assert_not_called()
299297
_is_volume_mounted.assert_called_once()
300-
_get_cluster_node_count.assert_called_once()
301298
_get_cluster_primary_address.assert_called_once()
302299

303300
self.assertTrue(isinstance(self.harness.model.unit.status, ActiveStatus))

tests/unit/test_db_router.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def test_db_router_relation_changed(
5151
# run start-up events to enable usage of the helper class
5252
self.harness.set_leader(True)
5353
self.charm.on.config_changed.emit()
54-
self.charm.unit_peer_data["unit-initialized"] = "True"
5554

5655
# confirm that the relation databag is empty
5756
db_router_relation_databag = self.harness.get_relation_data(
@@ -143,7 +142,6 @@ def test_db_router_relation_changed_exceptions(
143142
# run start-up events to enable usage of the helper class
144143
self.harness.set_leader(True)
145144
self.charm.on.config_changed.emit()
146-
self.charm.unit_peer_data["unit-initialized"] = "True"
147145

148146
# confirm that the relation databag is empty
149147
db_router_relation_databag = self.harness.get_relation_data(

tests/unit/test_relation_mysql_legacy.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def test_maria_db_relation_created(
4545
# run start-up events to enable usage of the helper class
4646
self.harness.set_leader(True)
4747
self.charm.on.config_changed.emit()
48-
self.charm.unit_peer_data["unit-initialized"] = "True"
4948
self.harness.update_config(
5049
{"mysql-interface-user": "mysql", "mysql-interface-database": "default_database"}
5150
)
@@ -103,7 +102,6 @@ def test_maria_db_relation_created_with_secrets(
103102
# run start-up events to enable usage of the helper class
104103
self.harness.set_leader(True)
105104
self.charm.on.config_changed.emit()
106-
self.charm.unit_peer_data["unit-initialized"] = "True"
107105
self.harness.update_config(
108106
{"mysql-interface-user": "mysql", "mysql-interface-database": "default_database"}
109107
)

tests/unit/test_shared_db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def test_shared_db_relation_changed(
4242
# run start-up events to enable usage of the helper class
4343
self.harness.set_leader(True)
4444
self.charm.on.config_changed.emit()
45-
self.charm.unit_peer_data["unit-initialized"] = "True"
4645

4746
# confirm that the relation databag is empty
4847
shared_db_relation_databag = self.harness.get_relation_data(

0 commit comments

Comments
 (0)