90
90
USER ,
91
91
USER_PASSWORD_KEY ,
92
92
)
93
- from relations .async_replication import PostgreSQLAsyncReplication
93
+ from relations .async_replication import (
94
+ REPLICATION_CONSUMER_RELATION ,
95
+ REPLICATION_OFFER_RELATION ,
96
+ PostgreSQLAsyncReplication ,
97
+ )
94
98
from relations .db import EXTENSIONS_BLOCKING_MESSAGE , DbProvides
95
99
from relations .postgresql_provider import PostgreSQLProvider
96
100
from upgrade import PostgreSQLUpgrade , get_postgresql_dependencies_model
@@ -1222,15 +1226,42 @@ def _on_set_password(self, event: ActionEvent) -> None:
1222
1226
)
1223
1227
return
1224
1228
1225
- # Update the password in the PostgreSQL instance.
1226
- try :
1227
- self .postgresql .update_user_password (username , password )
1228
- except PostgreSQLUpdateUserPasswordError as e :
1229
- logger .exception (e )
1229
+ replication_offer_relation = self .model .get_relation (REPLICATION_OFFER_RELATION )
1230
+ if (
1231
+ replication_offer_relation is not None
1232
+ and not self .async_replication .is_primary_cluster ()
1233
+ ):
1234
+ # Update the password in the other cluster PostgreSQL primary instance.
1235
+ other_cluster_endpoints = self .async_replication .get_all_primary_cluster_endpoints ()
1236
+ other_cluster_primary = self ._patroni .get_primary (
1237
+ alternative_endpoints = other_cluster_endpoints
1238
+ )
1239
+ other_cluster_primary_ip = [
1240
+ replication_offer_relation .data [unit ].get ("private-address" )
1241
+ for unit in replication_offer_relation .units
1242
+ if unit .name .replace ("/" , "-" ) == other_cluster_primary
1243
+ ][0 ]
1244
+ try :
1245
+ self .postgresql .update_user_password (
1246
+ username , password , database_host = other_cluster_primary_ip
1247
+ )
1248
+ except PostgreSQLUpdateUserPasswordError as e :
1249
+ logger .exception (e )
1250
+ event .fail ("Failed changing the password." )
1251
+ return
1252
+ elif self .model .get_relation (REPLICATION_CONSUMER_RELATION ) is not None :
1230
1253
event .fail (
1231
- "Failed changing the password: Not all members healthy or finished initial sync ."
1254
+ "Failed changing the password: This action can be ran only in the cluster from the offer side ."
1232
1255
)
1233
1256
return
1257
+ else :
1258
+ # Update the password in this cluster PostgreSQL primary instance.
1259
+ try :
1260
+ self .postgresql .update_user_password (username , password )
1261
+ except PostgreSQLUpdateUserPasswordError as e :
1262
+ logger .exception (e )
1263
+ event .fail ("Failed changing the password." )
1264
+ return
1234
1265
1235
1266
# Update the password in the secret store.
1236
1267
self .set_secret (APP_SCOPE , f"{ username } -password" , password )
@@ -1239,9 +1270,6 @@ def _on_set_password(self, event: ActionEvent) -> None:
1239
1270
# Other units Patroni configuration will be reloaded in the peer relation changed event.
1240
1271
self .update_config ()
1241
1272
1242
- # Update the password in the async replication data.
1243
- self .async_replication .update_async_replication_data ()
1244
-
1245
1273
event .set_results ({"password" : password })
1246
1274
1247
1275
def _on_update_status (self , _ ) -> None :
@@ -1357,7 +1385,7 @@ def _set_primary_status_message(self) -> None:
1357
1385
if self ._patroni .get_primary (unit_name_pattern = True ) == self .unit .name :
1358
1386
self .unit .status = ActiveStatus ("Primary" )
1359
1387
elif self .is_standby_leader :
1360
- self .unit .status = ActiveStatus ("Standby Leader " )
1388
+ self .unit .status = ActiveStatus ("Standby" )
1361
1389
elif self ._patroni .member_started :
1362
1390
self .unit .status = ActiveStatus ()
1363
1391
except (RetryError , ConnectionError ) as e :
0 commit comments