@@ -50,7 +50,6 @@ def is_unit_blocked(self) -> bool:
50
50
import pathlib
51
51
import re
52
52
import typing
53
- from typing import Dict , List , Optional , Tuple
54
53
55
54
from charms .data_platform_libs .v0 .s3 import (
56
55
CredentialsChangedEvent ,
@@ -88,17 +87,16 @@ def is_unit_blocked(self) -> bool:
88
87
list_backups_in_s3_path ,
89
88
upload_content_to_s3 ,
90
89
)
91
- from ops .charm import ActionEvent
92
- from ops .framework import Object
93
- from ops .jujuversion import JujuVersion
94
- from ops .model import BlockedStatus , MaintenanceStatus
95
-
96
90
from constants import (
97
91
MYSQL_DATA_DIR ,
98
92
PEER ,
99
93
SERVER_CONFIG_PASSWORD_KEY ,
100
94
SERVER_CONFIG_USERNAME ,
101
95
)
96
+ from ops .charm import ActionEvent
97
+ from ops .framework import Object
98
+ from ops .jujuversion import JujuVersion
99
+ from ops .model import BlockedStatus , MaintenanceStatus
102
100
103
101
logger = logging .getLogger (__name__ )
104
102
@@ -113,7 +111,7 @@ def is_unit_blocked(self) -> bool:
113
111
114
112
# Increment this PATCH version before using `charmcraft publish-lib` or reset
115
113
# to 0 if you are raising the major API version
116
- LIBPATCH = 14
114
+ LIBPATCH = 16
117
115
118
116
ANOTHER_S3_CLUSTER_REPOSITORY_ERROR_MESSAGE = "S3 repository claimed by another cluster"
119
117
MOVE_RESTORED_CLUSTER_TO_ANOTHER_S3_REPOSITORY_ERROR = (
@@ -150,7 +148,7 @@ def _s3_integrator_relation_exists(self) -> bool:
150
148
"""Returns whether a relation with the s3-integrator exists."""
151
149
return bool (self .model .get_relation (S3_INTEGRATOR_RELATION_NAME ))
152
150
153
- def _retrieve_s3_parameters (self ) -> Tuple [ Dict [str , str ], List [str ]]:
151
+ def _retrieve_s3_parameters (self ) -> tuple [ dict [str , str ], list [str ]]:
154
152
"""Retrieve S3 parameters from the S3 integrator relation.
155
153
156
154
Returns: tuple of (s3_parameters, missing_required_parameters)
@@ -196,7 +194,7 @@ def _upload_logs_to_s3(
196
194
stdout : str ,
197
195
stderr : str ,
198
196
log_filename : str ,
199
- s3_parameters : Dict [str , str ],
197
+ s3_parameters : dict [str , str ],
200
198
) -> bool :
201
199
"""Upload logs to S3 at the specified location.
202
200
@@ -219,7 +217,7 @@ def _upload_logs_to_s3(
219
217
# ------------------ List Backups ------------------
220
218
221
219
@staticmethod
222
- def _format_backups_list (backup_list : List [ Tuple [str , str ]]) -> str :
220
+ def _format_backups_list (backup_list : list [ tuple [str , str ]]) -> str :
223
221
"""Formats the provided list of backups as a table."""
224
222
backups = [f"{ 'backup-id' :<21} | { 'backup-type' :<12} | backup-status" ]
225
223
@@ -250,9 +248,7 @@ def _on_list_backups(self, event: ActionEvent) -> None:
250
248
event .set_results ({"backups" : self ._format_backups_list (backups )})
251
249
except Exception as e :
252
250
error_message = (
253
- getattr (e , "message" )
254
- if hasattr (e , "message" )
255
- else "Failed to retrieve backup ids from S3"
251
+ e .message if hasattr (e , "message" ) else "Failed to retrieve backup ids from S3"
256
252
)
257
253
logger .error (error_message )
258
254
event .fail (error_message )
@@ -313,7 +309,7 @@ def _on_create_backup(self, event: ActionEvent) -> None:
313
309
f"Model Name: { self .model .name } \n "
314
310
f"Application Name: { self .model .app .name } \n "
315
311
f"Unit Name: { self .charm .unit .name } \n "
316
- f"Juju Version: { str ( juju_version ) } \n "
312
+ f"Juju Version: { juju_version !s } \n "
317
313
)
318
314
319
315
if not upload_content_to_s3 (metadata , f"{ backup_path } .metadata" , s3_parameters ):
@@ -359,7 +355,7 @@ def _on_create_backup(self, event: ActionEvent) -> None:
359
355
})
360
356
self .charm ._on_update_status (None )
361
357
362
- def _can_unit_perform_backup (self ) -> Tuple [bool , Optional [ str ] ]:
358
+ def _can_unit_perform_backup (self ) -> tuple [bool , str | None ]:
363
359
"""Validates whether this unit can perform a backup.
364
360
365
361
Returns: tuple of (success, error_message)
@@ -390,7 +386,7 @@ def _can_unit_perform_backup(self) -> Tuple[bool, Optional[str]]:
390
386
391
387
return True , None
392
388
393
- def _pre_backup (self ) -> Tuple [bool , Optional [ str ] ]:
389
+ def _pre_backup (self ) -> tuple [bool , str | None ]:
394
390
"""Runs operations required before performing a backup.
395
391
396
392
Returns: tuple of (success, error_message)
@@ -415,7 +411,7 @@ def _pre_backup(self) -> Tuple[bool, Optional[str]]:
415
411
416
412
return True , None
417
413
418
- def _backup (self , backup_path : str , s3_parameters : Dict ) -> Tuple [bool , Optional [ str ] ]:
414
+ def _backup (self , backup_path : str , s3_parameters : dict ) -> tuple [bool , str | None ]:
419
415
"""Runs the backup operations.
420
416
421
417
Args:
@@ -450,7 +446,7 @@ def _backup(self, backup_path: str, s3_parameters: Dict) -> Tuple[bool, Optional
450
446
451
447
return True , None
452
448
453
- def _post_backup (self ) -> Tuple [bool , Optional [ str ] ]:
449
+ def _post_backup (self ) -> tuple [bool , str | None ]:
454
450
"""Runs operations required after performing a backup.
455
451
456
452
Returns: tuple of (success, error_message)
@@ -613,7 +609,7 @@ def _on_restore(self, event: ActionEvent) -> None: # noqa: C901
613
609
# update status as soon as possible
614
610
self .charm ._on_update_status (None )
615
611
616
- def _pre_restore (self ) -> Tuple [bool , str ]:
612
+ def _pre_restore (self ) -> tuple [bool , str ]:
617
613
"""Perform operations that need to be done before performing a restore.
618
614
619
615
Returns: tuple of (success, error_message)
@@ -635,7 +631,7 @@ def _pre_restore(self) -> Tuple[bool, str]:
635
631
636
632
return True , ""
637
633
638
- def _restore (self , backup_id : str , s3_parameters : Dict [str , str ]) -> Tuple [bool , bool , str ]:
634
+ def _restore (self , backup_id : str , s3_parameters : dict [str , str ]) -> tuple [bool , bool , str ]:
639
635
"""Run the restore operations.
640
636
641
637
Args:
@@ -687,7 +683,7 @@ def _restore(self, backup_id: str, s3_parameters: Dict[str, str]) -> Tuple[bool,
687
683
688
684
return True , True , ""
689
685
690
- def _clean_data_dir_and_start_mysqld (self ) -> Tuple [bool , str ]:
686
+ def _clean_data_dir_and_start_mysqld (self ) -> tuple [bool , str ]:
691
687
"""Run idempotent operations run after restoring a backup.
692
688
693
689
Returns tuple of (success, error_message)
@@ -711,8 +707,8 @@ def _clean_data_dir_and_start_mysqld(self) -> Tuple[bool, str]:
711
707
return True , ""
712
708
713
709
def _pitr_restore (
714
- self , restore_to_time : str , s3_parameters : Dict [str , str ]
715
- ) -> Tuple [bool , str ]:
710
+ self , restore_to_time : str , s3_parameters : dict [str , str ]
711
+ ) -> tuple [bool , str ]:
716
712
try :
717
713
logger .info ("Restoring point-in-time-recovery" )
718
714
stdout , stderr = self .charm ._mysql .restore_pitr (
@@ -728,7 +724,7 @@ def _pitr_restore(
728
724
return False , f"Failed to restore point-in-time-recovery to the { restore_to_time } "
729
725
return True , ""
730
726
731
- def _post_restore (self ) -> Tuple [bool , str ]:
727
+ def _post_restore (self ) -> tuple [bool , str ]:
732
728
"""Run operations required after restoring a backup.
733
729
734
730
Returns: tuple of (success, error_message)
@@ -836,7 +832,7 @@ def _on_s3_credentials_gone(self, event: CredentialsGoneEvent) -> None:
836
832
"Exception is occurred when trying to stop binlogs collecting after S3 relation depart. It may be a leader departure"
837
833
)
838
834
839
- def get_binlogs_collector_config (self ) -> Dict [str , str ]:
835
+ def get_binlogs_collector_config (self ) -> dict [str , str ]:
840
836
"""Return binlogs collector service config file.
841
837
842
838
Returns: dict of binlogs collector service config
0 commit comments