-
Notifications
You must be signed in to change notification settings - Fork 461
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
Check custom volume size is a multiple of 512 bytes #796
base: main
Are you sure you want to change the base?
Conversation
The error string had a trailing |
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.
thx for this PR and effort!
I don't think we need to error out like this.
Imho we need to have a DIff function which checks for differences accordingly your findings.
https://www.terraform.io/docs/extend/schemas/schema-behaviors.html#diffsuppressfunc
// This is the function we use to detect if the XSLT attribute itself changed |
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.
What about other storage backends different from qcow2?
Alternatively we could try to take advantage that the qemu-img rounds the value:
If we want to avoid erroring, we would need:
This would make the code a bit complicated, but would prevent the user from taking a calculator each time. What is your view on this? |
@dmacvicar yes to me sounds good path. @jamonation do you want to drive this feature and me with Duncan can help you with the needed guidance? What do you think? The rationale of the feature should be #796 (comment) |
Sure, since it sounds like you're up for helping me out, I'm game! I think the real complexity will be in the diff suppression and figuring out the very specific cases where rounding has occurred, as opposed to others where the user intends an actual size change. So I'll focus on that and see what I can come up with. Thanks for getting me on the right track with this! |
d22530e
to
9987012
Compare
I've redone things here taking into account the qcow2 format, and rounding up constraints. I was wrong about the virtual size being multiples of 512 bytes - in my local testing at least, qemu-img shows images are multiples of 1024. I implemented a rounding up function taking that size into account. The real logic then is this one conditional once all the format checking and rounding is done:
Where If those conditions aren't met, then the diff will still get generated. I'm sure there are a ton of naming and formatting conventions that I'm not aware of so please let me know what I should tidy or refactor and I'm happy to do it. |
Looks pretty good. Would you be able to provide a unit test for the rounding function and a integration test for the functionality itself? I am not sure how to specifically test suppression functions. I suspect it to relate to Additionally, the documentation would need to mention this behavior for the attribute. |
closes #741 |
9b39ff0
to
3069b98
Compare
I have rebased and reworked this PR and added an integration test. I could not understand why @jamonation mentioned it is rounded to 1024:
It looks it is always 512. Some review and testing is appreciated. |
3069b98
to
2e5bc30
Compare
…r size Co-authored-by: Duncan Mac-Vicar P <[email protected]> Closes: dmacvicar#741
2e5bc30
to
f0076ba
Compare
@jamonation @bcrisp4 could you test it? I'll try to do it as well |
I have performed basic tests. It is both good and bad:
So I think additional changes to round up to nearest 512 multiplication is needed to fix perpetual diff. |
Ok. I will need to reproduce that with an acceptance test. @scabala can you detail the changes you tried? |
I am having trouble reasoning about this. My testcase has an initial value of 1073742300, which I expect to be rounded by qemu-img to 1073742336:
Interestingly the rounding is done before qemu-img, by libvirt: /* Round capacity as qemu-img resize errors out on sizes which are not
* a multiple of 512 */
capacity = VIR_ROUND_UP(capacity, 512); Which is:
However:
Which is the rounding to 1024! 🤔 |
Hi @dmacvicar sure, I first created volume and if I then changed it by less than 512 - no diff, as expected. Then I tried to change it by something more than 512 but not a multiply of it, 700 in my example. As expected, diff was shown and applied successfully. But every next apply showed diff when actual size was rounded to nearest 512 multiplication. |
Wow this is a blast from the past! I don't have a local setup here to test with but will see what I can do to reproduce. I definitely recall the 512 vs. 1024 thing throwing me off. If I can get the provider going locally in debug mode, I guess we'll want to validate and add tests for the following qcow2 sizes/changes:
I think these all cover behaviour where we see things working as expected. Next to narrow things down, what happen when we try:
Do we know if case 5. behaves the same way when shrinking a volume? Part of me thinks this is a completely different code path since the volume won't get sized down by libvirt, whereas sizing up means a volume resize and different set of functions in the provider, terraform, and libvirt. |
This is a naive attempt at working around? #741 - Size of created volume differs from the resource definition. The issue is that qcow2 uses sector sizes of 512 bytes, so any custom size is rounded up to align to a sector boundary, which leads to the resource destroy/create cycle in the issue.
The approach I've taken here is rather naive (just bail if custom size modulo 512 is non-zero), but it keeps things simple as opposed to fudging tfstate or reported values from qemu.
Here's an example setup:
And a demonstration of rejecting outright an invalid size:
I had a look through the test cases for volumes, but the testing framework seems too advanced for my novice level. I'll happily add one though if it makes sense!