Skip to content

Commit fa6a934

Browse files
authored
Setting workload version to snap in rock version (#128)
1 parent 1b7f8dc commit fa6a934

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/charm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ def _on_postgresql_pebble_ready(self, event: WorkloadEvent) -> None:
413413
# Create a new config layer.
414414
new_layer = self._postgresql_layer()
415415

416+
self.unit.set_workload_version(self._patroni.rock_postgresql_version)
417+
416418
# Defer the initialization of the workload in the replicas
417419
# if the cluster hasn't been bootstrap on the primary yet.
418420
# Otherwise, each unit will create a different cluster and

tests/unit/test_charm.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_on_leader_elected(self, _, __, _render_postgresql_conf_file, ___):
9797
replication_password,
9898
)
9999

100+
@patch("charm.Patroni.rock_postgresql_version", new_callable=PropertyMock)
100101
@patch("charm.Patroni.primary_endpoint_ready", new_callable=PropertyMock)
101102
@patch("charm.PostgresqlOperatorCharm.update_config")
102103
@patch("charm.PostgresqlOperatorCharm.postgresql")
@@ -120,7 +121,10 @@ def test_on_postgresql_pebble_ready(
120121
_postgresql,
121122
___,
122123
_primary_endpoint_ready,
124+
_rock_postgresql_version,
123125
):
126+
_rock_postgresql_version.return_value = "14.7"
127+
124128
# Mock the primary endpoint ready property values.
125129
_primary_endpoint_ready.side_effect = [False, True]
126130

@@ -157,10 +161,13 @@ def test_on_postgresql_pebble_ready(
157161
self.assertEqual(container.get_service(self._postgresql_service).is_running(), True)
158162
_push_tls_files_to_workload.assert_called_once()
159163

164+
@patch("charm.Patroni.rock_postgresql_version", new_callable=PropertyMock)
160165
@patch("charm.PostgresqlOperatorCharm._create_pgdata")
161-
def test_on_postgresql_pebble_ready_no_connection(self, _):
166+
def test_on_postgresql_pebble_ready_no_connection(self, _, _rock_postgresql_version):
162167
mock_event = MagicMock()
163168
mock_event.workload = self.harness.model.unit.get_container(self._postgresql_container)
169+
_rock_postgresql_version.return_value = "14.7"
170+
164171
self.charm._on_postgresql_pebble_ready(mock_event)
165172

166173
# Event was deferred and status is still maintenance

0 commit comments

Comments
 (0)