diff --git a/src/charm.py b/src/charm.py index cc2a486df8..2ada3f0730 100755 --- a/src/charm.py +++ b/src/charm.py @@ -92,6 +92,7 @@ PRIMARY_NOT_REACHABLE_MESSAGE = "waiting for primary to be reachable from this unit" EXTENSIONS_DEPENDENCY_MESSAGE = "Unsatisfied plugin dependencies. Please check the logs" +DIFFERENT_VERSIONS_PSQL_BLOCKING_MESSAGE = "Please select the correct version of postgresql to use. No need to use different versions of postgresql." Scopes = Literal[APP_SCOPE, UNIT_SCOPE] @@ -519,6 +520,8 @@ def _on_peer_relation_changed(self, event: HookEvent): self._update_new_unit_status() + self._validate_database_version() + # Split off into separate function, because of complexity _on_peer_relation_changed def _start_stop_pgbackrest_service(self, event: HookEvent) -> None: # Start or stop the pgBackRest TLS server service when TLS certificate change. @@ -1577,6 +1580,18 @@ def client_relations(self) -> List[Relation]: relations.append(relation) return relations + def _validate_database_version(self): + """Checking that only one version of Postgres is used.""" + peer_db_version = self.app_peer_data.get("database-version") + + if self.unit.is_leader() and peer_db_version is None: + self.app_peer_data.update({"database-version": self._patroni.get_postgresql_version()}) + return + + if peer_db_version != self._patroni.get_postgresql_version(): + self.unit.status = BlockedStatus(DIFFERENT_VERSIONS_PSQL_BLOCKING_MESSAGE) + return + if __name__ == "__main__": main(PostgresqlOperatorCharm) diff --git a/tests/integration/ha_tests/test_self_healing.py b/tests/integration/ha_tests/test_self_healing.py index d862071ae3..cd5aa60a8a 100644 --- a/tests/integration/ha_tests/test_self_healing.py +++ b/tests/integration/ha_tests/test_self_healing.py @@ -578,6 +578,8 @@ async def test_deploy_zero_units(ops_test: OpsTest, charm): logger.info("connect to DB and create test table") await create_test_data(connection_string) + # TODO: implement a test using the store with a different version of Postgres + unit_ip_addresses = [] primary_storage = "" for unit in ops_test.model.applications[app].units: