14
14
MySQLPromoteClusterToPrimaryError ,
15
15
MySQLRejoinClusterError ,
16
16
)
17
+ from constants import (
18
+ BACKUPS_PASSWORD_KEY ,
19
+ BACKUPS_USERNAME ,
20
+ CLUSTER_ADMIN_PASSWORD_KEY ,
21
+ CLUSTER_ADMIN_USERNAME ,
22
+ MONITORING_PASSWORD_KEY ,
23
+ MONITORING_USERNAME ,
24
+ PEER ,
25
+ ROOT_PASSWORD_KEY ,
26
+ ROOT_USERNAME ,
27
+ SERVER_CONFIG_PASSWORD_KEY ,
28
+ SERVER_CONFIG_USERNAME ,
29
+ )
17
30
from ops import (
18
31
ActionEvent ,
19
32
ActiveStatus ,
31
44
from ops .framework import Object
32
45
from tenacity import RetryError , Retrying , stop_after_attempt , wait_fixed
33
46
34
- from constants import (
35
- BACKUPS_PASSWORD_KEY ,
36
- BACKUPS_USERNAME ,
37
- CLUSTER_ADMIN_PASSWORD_KEY ,
38
- CLUSTER_ADMIN_USERNAME ,
39
- MONITORING_PASSWORD_KEY ,
40
- MONITORING_USERNAME ,
41
- PEER ,
42
- ROOT_PASSWORD_KEY ,
43
- ROOT_USERNAME ,
44
- SERVER_CONFIG_PASSWORD_KEY ,
45
- SERVER_CONFIG_USERNAME ,
46
- )
47
-
48
47
if typing .TYPE_CHECKING :
49
48
from charm import MySQLOperatorCharm
50
49
53
52
# The unique Charmhub library identifier, never change it
54
53
LIBID = "4de21f1a022c4e2c87ac8e672ec16f6a"
55
54
LIBAPI = 0
56
- LIBPATCH = 9
55
+ LIBPATCH = 10
57
56
58
57
RELATION_OFFER = "replication-offer"
59
58
RELATION_CONSUMER = "replication"
@@ -407,9 +406,7 @@ def idle(self) -> bool:
407
406
# transitional state between relation created and setup_action
408
407
return False
409
408
410
- if self .state not in [States .READY , States .UNINITIALIZED ]:
411
- return False
412
- return True
409
+ return self .state in [States .READY , States .UNINITIALIZED ]
413
410
414
411
@property
415
412
def secret (self ) -> Secret | None :
@@ -430,7 +427,7 @@ def _get_secret(self) -> Secret:
430
427
431
428
def _on_create_replication (self , event : ActionEvent ):
432
429
"""Promote the offer side to primary on initial setup."""
433
- if not self ._charm .app_peer_data .get ("async-ready" ) = = "true" :
430
+ if self ._charm .app_peer_data .get ("async-ready" ) ! = "true" :
434
431
event .fail ("Relation created but not ready" )
435
432
return
436
433
@@ -491,10 +488,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
491
488
):
492
489
# Test for a broken relation on the primary side
493
490
logger .error (
494
- (
495
- "Cannot setup async relation with primary cluster in blocked/read-only state\n "
496
- "Remove the relation."
497
- )
491
+ "Cannot setup async relation with primary cluster in blocked/read-only state\n "
492
+ "Remove the relation."
498
493
)
499
494
message = f"Cluster is in a blocked state. Remove { RELATION_OFFER } relation"
500
495
self ._charm .unit .status = BlockedStatus (message )
@@ -503,10 +498,8 @@ def _on_offer_created(self, event: RelationCreatedEvent):
503
498
if not self .model .get_relation (RELATION_OFFER ):
504
499
# safeguard against a deferred event a previous relation.
505
500
logger .error (
506
- (
507
- "Relation created running against removed relation.\n "
508
- f"Remove { RELATION_OFFER } relation and retry."
509
- )
501
+ "Relation created running against removed relation.\n "
502
+ f"Remove { RELATION_OFFER } relation and retry."
510
503
)
511
504
self ._charm .unit .status = BlockedStatus (f"Remove { RELATION_OFFER } relation and retry" )
512
505
return
@@ -887,7 +880,7 @@ def _on_consumer_non_leader_created(self, _):
887
880
# set waiting state to inhibit auto recovery, only when not already set
888
881
if self ._charm .unit .is_leader ():
889
882
return
890
- if not self ._charm .unit_peer_data .get ("member-state" ) = = "waiting" :
883
+ if self ._charm .unit_peer_data .get ("member-state" ) ! = "waiting" :
891
884
self ._charm .unit_peer_data ["member-state" ] = "waiting"
892
885
self ._charm .unit .status = WaitingStatus ("waiting replica cluster be configured" )
893
886
0 commit comments