Skip to content

Commit

Permalink
Merge pull request #20 from xcp-ng/inexistant-disks
Browse files Browse the repository at this point in the history
Don't fail seeing a backup refering to non-existent disk
  • Loading branch information
ydirson committed Jul 2, 2024
2 parents add6c45 + 44624db commit 330ca1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
3 changes: 3 additions & 0 deletions diskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ def getDiskDeviceSize(dev):
return int(__readOneLineFile__("/sys/block/%s/device/block/size" % dev))
elif os.path.exists("/sys/block/%s/size" % dev):
return int(__readOneLineFile__("/sys/block/%s/size" % dev))
else:
raise Exception("{0} not found as /sys/block/{0}/device/block/size or /sys/block/{0}/size"
.format(dev))

def getDiskBlockSize(dev):
if not dev.startswith("/dev/"):
Expand Down
33 changes: 26 additions & 7 deletions product.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,32 @@ def findXenSourceBackups():
b = None
try:
b = util.TempMount(p, 'backup-', ['ro'], 'ext3')
if os.path.exists(os.path.join(b.mount_point, '.xen-backup-partition')):
backup = XenServerBackup(p, b.mount_point)
logger.log("Found a backup: %s" % (repr(backup),))
if backup.version >= XENSERVER_MIN_VERSION and \
backup.version <= THIS_PLATFORM_VERSION:
backups.append(backup)
except:
if not os.path.exists(os.path.join(b.mount_point, '.xen-backup-partition')):
raise StopIteration()

backup = XenServerBackup(p, b.mount_point)
logger.log("Found a backup: %s" % (repr(backup),))

if backup.version < XENSERVER_MIN_VERSION:
logger.log("findXenSourceBackups: ignoring, platform too old: %s < %s" %
(backup.version, XENSERVER_MIN_VERSION))
raise StopIteration()
if backup.version > THIS_PLATFORM_VERSION:
logger.log("findXenSourceBackups: ignoring later platform: %s > %s" %
(backup.version, THIS_PLATFORM_VERSION))
raise StopIteration()
if not os.path.exists(backup.root_disk):
logger.error("findXenSourceBackups: PRIMARY_DISK=%r does not exist" %
(backup.root_disk,))
raise StopIteration()

backups.append(backup)

except StopIteration:
pass
except Exception as ex:
logger.log("findXenSourceBackups caught exception for partition %s" % (p,))
logger.logException(ex)
pass
if b:
b.unmount()
Expand Down

0 comments on commit 330ca1f

Please sign in to comment.