Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail seeing a backup refering to non-existent disk #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions diskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,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 getDiskSerialNumber(dev):
# For Multipath nodes return info about 1st slave
Expand Down
33 changes: 26 additions & 7 deletions product.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this raising StopIteration and catching it weird and hard to read. Why not using a try/finally doing the b.umount() in the finally and using continue here?


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