@@ -1795,7 +1795,7 @@ def is_controller(cls):
17951795 return cls ._is_mounted (DATABASE_PATH )
17961796
17971797 @classmethod
1798- def database_backup_age (cls ):
1798+ def get_database_backup_age (cls ):
17991799 """
18001800 Return the latest backup age in seconds.
18011801 If not called on the Controller, since backups are not available,
@@ -1823,17 +1823,17 @@ def database_invalidation(cls):
18231823 for directory in (DATABASE_BACKUP_DIR_MAIN , DATABASE_BACKUP_DIR_SPARE ):
18241824 valid_backup_count = 0
18251825 # Validate file and apply retention
1826- for database_backup_file , _ in cls ._get_sorted_database_backup (directory ):
1826+ for database_backup_path , _ in cls ._get_sorted_database_backup (directory ):
18271827 try :
1828- cls ._check_database_backup (database_backup_file )
1828+ cls ._check_database_backup (database_backup_path )
18291829 valid_backup_count += 1
18301830 if valid_backup_count < DATABASE_BACKUP_RETENTION :
18311831 continue
18321832 except LinstorDatabaseBackupError as error :
1833- util .SMlog (f"[database_backup] Check failed `{ error } ` [{ database_backup_file } ]" ,
1833+ util .SMlog (f"[database_backup] Check failed `{ error } ` [{ database_backup_path } ]" ,
18341834 priority = util .LOG_ERR )
18351835 with contextlib .suppress (OSError ):
1836- os .unlink (database_backup_file )
1836+ os .unlink (database_backup_path )
18371837
18381838 @classmethod
18391839 def get_all_group_names (cls , base_name ):
@@ -2713,7 +2713,7 @@ def _get_volume_properties(self, volume_uuid):
27132713 return properties
27142714
27152715 @classmethod
2716- def _list_database_backup (cls , database_backup_dir ):
2716+ def _list_database_backups (cls , database_backup_dir ):
27172717 """
27182718 List all visible backup files in database_backup_dir.
27192719 DATABASE_BACKUP_DIR_MAIN is only available on the Linstor Controller.
@@ -2733,7 +2733,7 @@ def _get_sorted_database_backup(cls, database_backup_dir):
27332733 Return list of backups in database_backup_dir, alongside their creation date.
27342734 Sorted by date from the more recent to the older one.
27352735 """
2736- return sorted (cls ._list_database_backup (database_backup_dir ),
2736+ return sorted (cls ._list_database_backups (database_backup_dir ),
27372737 reverse = True ,
27382738 key = lambda p : p [1 ])
27392739
@@ -2743,28 +2743,31 @@ def _get_latest_database_backup(cls):
27432743 Return the latest backup in DATABASE_BACKUP_DIR_MAIN, and its creation date.
27442744 Returns (None, timestamp(0)) when none are found.
27452745 None will be found if it is not called on the Linstor Controller.
2746- (cf _list_database_backup )
2746+ (cf _list_database_backups )
27472747 """
2748- return max (cls ._list_database_backup (DATABASE_BACKUP_DIR_MAIN ),
2748+ return max (cls ._list_database_backups (DATABASE_BACKUP_DIR_MAIN ),
27492749 default = (None , datetime .fromtimestamp (0 )),
27502750 key = lambda p : p [1 ])
27512751
27522752 @classmethod
2753- def _check_database_backup (cls , database_backup_file ):
2753+ def _check_database_backup (cls , database_backup_path ):
27542754 """
27552755 Make some validation of a database backup zip-file.
27562756 Check its a valid zipfile, and CRC-test its content.
27572757 Check it contains a non-empty linstordb.mv.db file.
27582758 Always raises a LinstorDatabaseBackupError if checks failed.
27592759 """
27602760 try :
2761- with zipfile .ZipFile (database_backup_file , mode = "r" ) as archive :
2761+ with zipfile .ZipFile (database_backup_path , mode = "r" ) as archive :
27622762 if archive .testzip () is not None :
27632763 raise LinstorDatabaseBackupError ("zip archive CRC failed" )
2764- linstordb = [f for f in archive .filelist if f .filename == "linstordb.mv.db" ]
2764+ linstordb = next ((
2765+ f
2766+ for f in archive .filelist
2767+ if f .filename == "linstordb.mv.db"
2768+ ), None )
27652769 if not linstordb :
27662770 raise LinstorDatabaseBackupError ("cannot find linstordb.mv.db" )
2767- linstordb = linstordb [0 ]
27682771 if linstordb .file_size == 0 :
27692772 raise LinstorDatabaseBackupError ("linstordb.mv.db is empty" )
27702773 except (FileNotFoundError , zipfile .BadZipFile , zipfile .LargeZipFile ) as e :
0 commit comments