21
21
PostgreSQLGetPostgreSQLVersionError ,
22
22
PostgreSQLListUsersError ,
23
23
)
24
- from ops .charm import RelationBrokenEvent , RelationChangedEvent
24
+ from ops .charm import RelationBrokenEvent
25
25
from ops .framework import Object
26
26
from ops .model import ActiveStatus , BlockedStatus , Relation
27
27
from tenacity import RetryError , Retrying , stop_after_attempt , wait_fixed
30
30
ALL_CLIENT_RELATIONS ,
31
31
APP_SCOPE ,
32
32
DATABASE_PORT ,
33
- ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE ,
34
33
)
35
34
from utils import label2name , new_password
36
35
@@ -62,10 +61,6 @@ def __init__(self, charm: "PostgresqlOperatorCharm", relation_name: str = "datab
62
61
self .framework .observe (
63
62
charm .on [self .relation_name ].relation_broken , self ._on_relation_broken
64
63
)
65
- self .framework .observe (
66
- charm .on [self .relation_name ].relation_changed ,
67
- self ._on_relation_changed_event ,
68
- )
69
64
self .charm = charm
70
65
71
66
# Charm events defined in the database provides charm library.
@@ -151,12 +146,14 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:
151
146
else f"Failed to initialize relation { self .relation_name } "
152
147
)
153
148
)
149
+ return
154
150
155
151
# Try to wait for pg_hba trigger
156
152
try :
157
153
for attempt in Retrying (stop = stop_after_attempt (3 ), wait = wait_fixed (1 )):
158
154
with attempt :
159
- self .charm .postgresql .is_user_in_hba (user )
155
+ if not self .charm .postgresql .is_user_in_hba (user ):
156
+ raise Exception ("pg_hba not ready" )
160
157
self .charm .unit_peer_data .update ({
161
158
"pg_hba_needs_update_timestamp" : str (datetime .now ())
162
159
})
@@ -299,11 +296,6 @@ def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None: # noq
299
296
self .database_provides .set_tls (relation_id , tls )
300
297
self .database_provides .set_tls_ca (relation_id , ca )
301
298
302
- def _check_multiple_endpoints (self ) -> bool :
303
- """Checks if there are relations with other endpoints."""
304
- relation_names = {relation .name for relation in self .charm .client_relations }
305
- return "database" in relation_names and len (relation_names ) > 1
306
-
307
299
def _update_unit_status (self , relation : Relation ) -> None :
308
300
"""# Clean up Blocked status if it's due to extensions request."""
309
301
if (
@@ -317,27 +309,6 @@ def _update_unit_status(self, relation: Relation) -> None:
317
309
):
318
310
self .charm .set_unit_status (ActiveStatus ())
319
311
320
- self ._update_unit_status_on_blocking_endpoint_simultaneously ()
321
-
322
- def _on_relation_changed_event (self , event : RelationChangedEvent ) -> None :
323
- """Event emitted when the relation has changed."""
324
- # Leader only
325
- if not self .charm .unit .is_leader ():
326
- return
327
-
328
- if self ._check_multiple_endpoints ():
329
- self .charm .set_unit_status (BlockedStatus (ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE ))
330
- return
331
-
332
- def _update_unit_status_on_blocking_endpoint_simultaneously (self ):
333
- """Clean up Blocked status if this is due related of multiple endpoints."""
334
- if (
335
- self .charm .is_blocked
336
- and self .charm .unit .status .message == ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE
337
- and not self ._check_multiple_endpoints ()
338
- ):
339
- self .charm .set_unit_status (ActiveStatus ())
340
-
341
312
def check_for_invalid_extra_user_roles (self , relation_id : int ) -> bool :
342
313
"""Checks if there are relations with invalid extra user roles.
343
314
0 commit comments