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 Apr 19, 2024
2 parents 343c639 + 7a99335 commit 61a23be
Show file tree
Hide file tree
Showing 2 changed files with 28 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("%s not found as %s or %s" % (dev, "/sys/block/%s/device/block/size",
"/sys/block/%s/size"))

def getDiskBlockSize(dev):
if not dev.startswith("/dev/"):
Expand Down
32 changes: 25 additions & 7 deletions product.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,31 @@ 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: %s" % (p, ex))
pass
if b:
b.unmount()
Expand Down

0 comments on commit 61a23be

Please sign in to comment.