Skip to content

Commit 3dba5e3

Browse files
committed
glusterfs: Fix race condition on test_volume_stopped.
Retry sr.plug_pbds after 1s then 2s before proceding with test failure. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
1 parent b6b7676 commit 3dba5e3

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

drivers/LinstorSR.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,16 +1587,15 @@ def database_backup(self, name=""):
15871587
"""
15881588
Generate a new database backup file.
15891589
This operation should not prevent the underlying action to be successful.
1590-
Hence all Exceptions are caught and re-raised only if asked to.
1591-
delay: skip backup if the last one was generated less than delay seconds ago.
1590+
Hence all Exceptions are caught and logged.
15921591
"""
15931592
if not self._linstor:
15941593
self._reconnect()
15951594
try:
15961595
self._linstor.database_backup(name)
15971596
except Exception as e:
15981597
util.SMlog(
1599-
"[database_backup] Error during creation: {}".format(e),
1598+
f"[database_backup] Error during creation: {e}",
16001599
priority=util.LOG_ERR,
16011600
)
16021601

drivers/linstorvolumemanager.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ def database_backup_age(cls):
17801780
If not called on the Controller, since backups are not available,
17811781
returns a huge value (a timestamp of now).
17821782
"""
1783-
return (datetime.now() - cls._get_latest_database_backup()).total_seconds()
1783+
return (datetime.now() - cls._get_latest_database_backup()[1]).total_seconds()
17841784

17851785
def database_backup(self, name=""):
17861786
# Create new backup
@@ -2672,27 +2672,49 @@ def _get_volume_properties(self, volume_uuid):
26722672

26732673
@classmethod
26742674
def _list_database_backup(cls, database_backup_dir):
2675+
"""
2676+
List all visible backup files in database_backup_dir.
2677+
DATABASE_BACKUP_DIR_MAIN is only available on the Linstor Controller.
2678+
DATABASE_BACKUP_DIR_SPARE will list backups previously made when the Host was the Linstor Controller.
2679+
This may not be useful information if it is not the Controller anymore.
2680+
"""
26752681
for path in database_backup_dir.glob(DATABASE_BACKUP_NAME_FORMAT.format(
2676-
"20[0-9][0-9][01][0-9][0-3][0-9]_[0-2][0-9][0-5][0-9][0-5][0-9]", "*") + ".zip"):
2682+
"[0-9]" * 8 + "_" + "[0-9]" * 6, "*") + ".zip"):
26772683
try:
26782684
yield path, datetime.strptime(path.name.split("-")[1], DATABASE_BACKUP_DATE_FORMAT)
26792685
except (ValueError, IndexError):
26802686
continue
26812687

26822688
@classmethod
26832689
def _get_sorted_database_backup(cls, database_backup_dir):
2690+
"""
2691+
Return list of backups in database_backup_dir, alongside their creation date.
2692+
Sorted by date from the more recent to the older one.
2693+
"""
26842694
return sorted(cls._list_database_backup(database_backup_dir),
26852695
reverse=True,
26862696
key=lambda p: p[1])
26872697

26882698
@classmethod
26892699
def _get_latest_database_backup(cls):
2700+
"""
2701+
Return the latest backup in DATABASE_BACKUP_DIR_MAIN, and its creation date.
2702+
Returns (None, timestamp(0)) when none are found.
2703+
None will be found if it is not called on the Linstor Controller.
2704+
(cf _list_database_backup)
2705+
"""
26902706
return max(cls._list_database_backup(DATABASE_BACKUP_DIR_MAIN),
26912707
default=(None, datetime.fromtimestamp(0)),
26922708
key=lambda p: p[1])
26932709

26942710
@classmethod
26952711
def _check_database_backup(cls, database_backup_file):
2712+
"""
2713+
Make some validation of a database backup zip-file.
2714+
Check its a valid zipfile, and CRC-test its content.
2715+
Check it contains a non-empty linstordb.mv.db file.
2716+
Always raises a LinstorDatabaseBackupError if checks failed.
2717+
"""
26962718
try:
26972719
with zipfile.ZipFile(database_backup_file, mode="r") as archive:
26982720
if archive.testzip() is not None:
@@ -2703,8 +2725,6 @@ def _check_database_backup(cls, database_backup_file):
27032725
linstordb = linstordb[0]
27042726
if linstordb.file_size == 0:
27052727
raise LinstorDatabaseBackupError("linstordb.mv.db is empty")
2706-
except LinstorDatabaseBackupError:
2707-
raise
27082728
except (FileNotFoundError, zipfile.BadZipFile, zipfile.LargeZipFile) as e:
27092729
raise LinstorDatabaseBackupError(e) from e
27102730

0 commit comments

Comments
 (0)