Skip to content

Commit 3a651df

Browse files
authored
DPE-5385 fix/database requested wait container (#500)
* database request needs to wait for container * typos
1 parent a22db5d commit 3a651df

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/relations/mysql_provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
9595
"""Handle the `database-requested` event."""
9696
if not self.charm.unit.is_leader():
9797
return
98+
container = self.charm.unit.get_container(CONTAINER_NAME)
99+
if not container.can_connect():
100+
logger.debug("Container is not ready")
101+
event.defer()
102+
return
98103
# check if cluster is ready and if not, defer
99104
if not self.charm.cluster_initialized:
100105
logger.debug("Waiting cluster to be initialized")

tests/unit/test_charm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,25 @@ def test_pebble_ready_set_data(
208208
mock_write_conf,
209209
mock_conf,
210210
mock_join,
211-
_cluster_intialized,
212-
_unit_intialized,
211+
_cluster_initialized,
212+
_unit_initialized,
213213
):
214214
mock_mysql.is_data_dir_initialised.return_value = False
215215
mock_mysql.get_member_state.return_value = ("online", "primary")
216216
self.harness.set_can_connect("mysql", True)
217217
self.harness.set_leader()
218218

219219
mock_mysql.cluster_metadata_exists.return_value = False
220-
_cluster_intialized.return_value = False
221-
_unit_intialized.return_value = False
220+
_cluster_initialized.return_value = False
221+
_unit_initialized.return_value = False
222222

223223
# test on leader
224224
self.harness.set_leader(is_leader=True)
225225
self.harness.container_pebble_ready("mysql")
226226
self.assertEqual(self.charm.unit_peer_data["member-state"], "online")
227227
self.assertEqual(self.charm.unit_peer_data["member-role"], "primary")
228228

229-
_cluster_intialized.return_value = True
229+
_cluster_initialized.return_value = True
230230

231231
# test on non leader
232232
self.harness.set_leader(is_leader=False)

tests/unit/test_config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,36 @@ def _check_valid_values(_harness, field: str, accepted_values: list, is_long_fie
3636
assert _harness.charm.config[field] == value if not is_long_field else int(value)
3737

3838

39-
def _check_invalid_values(_harness, field: str, erroneus_values: list) -> None:
39+
def _check_invalid_values(_harness, field: str, erroneous_values: list) -> None:
4040
"""Check the incorrectness of the passed values for a field."""
41-
for value in erroneus_values:
41+
for value in erroneous_values:
4242
_harness.update_config({field: value})
4343
with pytest.raises(ValueError):
4444
_ = _harness.charm.config[field]
4545

4646

4747
def test_profile_limit_values(harness) -> None:
4848
"""Check that integer fields are parsed correctly."""
49-
erroneus_values = [599, 10**7, -354343]
50-
_check_invalid_values(harness, "profile-limit-memory", erroneus_values)
49+
erroneous_values = [599, 10**7, -354343]
50+
_check_invalid_values(harness, "profile-limit-memory", erroneous_values)
5151

5252
valid_values = [600, 1000, 35000]
5353
_check_valid_values(harness, "profile-limit-memory", valid_values)
5454

5555

5656
def test_profile_values(harness) -> None:
5757
"""Test profile values."""
58-
erroneus_values = ["prod", "Test", "foo", "bar"]
59-
_check_invalid_values(harness, "profile", erroneus_values)
58+
erroneous_values = ["prod", "Test", "foo", "bar"]
59+
_check_invalid_values(harness, "profile", erroneous_values)
6060

6161
accepted_values = ["production", "testing"]
6262
_check_valid_values(harness, "profile", accepted_values)
6363

6464

6565
def test_cluster_name_values(harness) -> None:
6666
"""Test cluster name values."""
67-
erroneus_values = [64 * "a", "1-cluster", "cluster$"]
68-
_check_invalid_values(harness, "cluster-name", erroneus_values)
67+
erroneous_values = [64 * "a", "1-cluster", "cluster$"]
68+
_check_invalid_values(harness, "cluster-name", erroneous_values)
6969

7070
accepted_values = ["c1", "cluster_name", "cluster.name", "Cluster-name", 63 * "c"]
7171
_check_valid_values(harness, "cluster-name", accepted_values)

tests/unit/test_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_database_requested(
7878
):
7979
# run start-up events to enable usage of the helper class
8080
self.harness.set_leader(True)
81+
self.harness.container_pebble_ready("mysql")
8182
self.charm.on.config_changed.emit()
8283

8384
# confirm that the relation databag is empty

0 commit comments

Comments
 (0)