Skip to content

Commit b60ee97

Browse files
committed
remove unused method
1 parent a513b99 commit b60ee97

File tree

2 files changed

+1
-74
lines changed

2 files changed

+1
-74
lines changed

src/relations/mysql_provider.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from ops.charm import RelationBrokenEvent, RelationDepartedEvent, RelationJoinedEvent
2222
from ops.framework import Object
23-
from ops.model import BlockedStatus, Relation, Unit
23+
from ops.model import BlockedStatus, Relation
2424

2525
from constants import DB_RELATION_NAME, PASSWORD_LENGTH, PEER
2626
from utils import generate_random_password
@@ -311,45 +311,3 @@ def _on_database_provides_relation_departed(self, event: RelationDepartedEvent)
311311
logger.info(f"Removed router from metadata {user.router_id}")
312312
except MySQLRemoveRouterFromMetadataError:
313313
logger.error(f"Failed to remove router from metadata with ID {user.router_id}")
314-
315-
def remove_unit_from_endpoints(self, unit: Unit) -> None:
316-
"""Remove a unit from the endpoints for related applications.
317-
318-
Args:
319-
unit (ops.Unit): The the unit to be removed.
320-
"""
321-
if not self.charm.unit.is_leader():
322-
return
323-
324-
if not self.charm.cluster_initialized:
325-
logger.debug("Waiting cluster to be initialized")
326-
return
327-
328-
unit_address = self.charm.get_unit_ip(unit)
329-
330-
# filter out the unit address from the (ro)endpoints
331-
for relation in self.active_relations:
332-
# rw endpoints
333-
endpoints = (
334-
self.database.fetch_my_relation_field(relation.id, "endpoints", DB_RELATION_NAME)
335-
or ""
336-
)
337-
if unit_address in endpoints:
338-
self.database.set_endpoints(
339-
relation.id,
340-
",".join([e for e in endpoints.split(",") if unit_address not in e]),
341-
)
342-
continue
343-
344-
# ro endpoints
345-
ro_endpoints = (
346-
self.database.fetch_my_relation_field(
347-
relation.id, "read-only-endpoints", DB_RELATION_NAME
348-
)
349-
or ""
350-
)
351-
if unit_address in ro_endpoints:
352-
self.database.set_read_only_endpoints(
353-
relation.id,
354-
",".join([e for e in ro_endpoints.split(",") if unit_address not in e]),
355-
)

tests/unit/test_database.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,3 @@ def test_relation_departed(
103103
self.harness.remove_relation(self.database_relation_id)
104104
_delete_user.assert_called_once_with("user1")
105105
_remove_router.assert_called_once_with("router_id")
106-
107-
def test_remove_unit_from_endpoints(self):
108-
self.harness.set_leader(True)
109-
self.charm.on.config_changed.emit()
110-
self.harness.update_relation_data(
111-
self.peer_relation_id, self.charm.app.name, {"units-added-to-cluster": "1"}
112-
)
113-
114-
self.harness.update_relation_data(
115-
self.database_relation_id,
116-
self.charm.app.name,
117-
{
118-
"data": '{"database": "test_db"}',
119-
"password": "super_secure_password",
120-
"username": f"relation-{self.database_relation_id}",
121-
"endpoints": "2.2.2.2:3306",
122-
"version": "8.0.36-0ubuntu0.22.04.3",
123-
"database": "test_db",
124-
"read-only-endpoints": "2.2.2.1:3306",
125-
},
126-
)
127-
128-
remove_unit = self.harness.model.get_unit("mysql/1")
129-
with patch("charm.MySQLOperatorCharm.get_unit_ip", return_value="2.2.2.1"):
130-
self.charm.database_relation.remove_unit_from_endpoints(remove_unit)
131-
132-
relation_data = self.harness.get_relation_data(
133-
self.database_relation_id, self.charm.app.name
134-
)
135-
136-
self.assertNotIn("read-only-endpoints", relation_data.keys())

0 commit comments

Comments
 (0)