-
Notifications
You must be signed in to change notification settings - Fork 23
Don't fail seeing a backup refering to non-existent disk #70
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
base: master
Are you sure you want to change the base?
Conversation
diskutil.py
Outdated
| 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will end up raising as e.g. sda not found as /sys/block/%s/device/block/size or /sys/block/%s/size, i.e. the %s characters will come out in the exception text, which doesn't seem quite what you'd expect?
If we don't need this for xs8 (i.e. we can rely on py3 functionality), could we use a format string to make it easier, at which point you'd just have e.g. raise Exception(f"{dev} not found as /sys/block/{dev}/device/block/size or /sys/block/{dev}/size")?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to keep Python 2/3 compatibility, or at least have master and release/xs8 branches as similar as possible. Maybe a more generic and easier "Unable to get block size of %s device" % dev would be enough, also not requiring to be updated as new potential virtual files are needed to be checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving the full paths inside the format string should be good for now. At least using str.format and {0} will allow to avoid repeating dev
|
BTW... got the error too this morning. Pretty boring indeed. |
7a99335 to
44624db
Compare
product.py
Outdated
| backups.append(backup) | ||
| except: | ||
| if not os.path.exists(os.path.join(b.mount_point, '.xen-backup-partition')): | ||
| raise StopIteration() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lack of break equivalent for try blocks is a problem. I guess return [] here would be suitable enough if we did not have a loop.
I'm quite unsure how to make that more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are inside a for loop, why not using break and/or continue ? Also, you can put the b.unmount() inside a finally section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
44624db to
4897a5f
Compare
|
Rebased, and improved the exception logging in patch 2 |
4897a5f to
561a17b
Compare
- it is bad practice to "catch any" - not logging anything just hides information, which can be especially important here as the reason for a try/catch is not obvious (exceptions thrown by XenServerBackup.__init__?) Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
Previous code structure was that of 2 nested if's, with nominal code path being in the positive branch of each if. Adding another condition will bring a need for logging the reason to ignore a backup, but doing that by converting inner `if` to an `elif` chain (arguably the simplest modification) would bring the nominal code path to switch to the negative/last branch of the inner `elif` chain. At the same time, the outer `if` would not seem special enough to deserve it special place (and the cyclomatic complexity). This commit leverages the existing `try:except:` block to switch to an "error out the loop" pattern, where the nominal code path is just linear. Using `StopIteration` may feel like an abuse, but: - it is the only standard `Exception` that is not a `StandardError` or a `Warning`, and defining a new one could seem overkill - the closest alternative would be a `while True` loop and breaking out in both exceptional code paths and at the end of nominal path, where the `break` statements would "stop the iteration" as well Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
…rver#66) Signed-off-by: Yann Dirson <yann.dirson@vates.fr>
|
Dropped the first commit, made unnecessary by #237 |
This fixes the various problems seen as part of #66, and then some.
This is a continuation of #67 which got closed when
xs8was destroyed and cannot be reopened (thx github).