-
Notifications
You must be signed in to change notification settings - Fork 90
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
refactor: only add / remove minimul number of cdroms #355
refactor: only add / remove minimul number of cdroms #355
Conversation
dedd2d5
to
017f49a
Compare
I don't have any preference here. On one hand, I presume the code that is already in the repo has probably seen more testing than the new one, so regressions are less likely. On the other hand, this refactor reduces a bit calls which (per my understanding) communicate to ESXi via network, which is slow. So if you decide to wait for it to land, the new functional might be a tiny bit faster. |
@Hi-Angel that's a good call out on the testing part. We release every week, or shoot for it when we have pending changes. I think we can focus on getting this PR reviewed and merged for the next release to give the new feature time to setting. |
Any news here? |
8eff8a9
to
19cfa45
Compare
I've rebased from |
reattach_cdroms
to only remove/add amount of CDroms that is necessary
Why have you squashed the commits before review? 😅 I mean, I know the project squashes them on merge for some reason, but don't you want for review purposes to see each functional change separated? |
It's all good - I've read through them already. |
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.
Hi @Hi-Angel I finally got a chance to get back to you on this. I was heads down on a few other Packer related changes. I left a few nits and a suggestion to your RemoveCdroms function change. The code looks good overall but I found a few things hard to wrap my head around.
Give the suggestions a look over and let me know if you have any questions.
The `range` body is skipped anyway when len(ISOPaths) == 0.
This simplifies the code a bit, and it will also be useful later when we add support for reusing a VM
19cfa45
to
05e1a98
Compare
Everything seems addressed |
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.
@Hi-Angel then updated changes look good to me. After your explanation dropping Virtual
from the function name makes senses. Thanks for responding so quickly to the review.
@tenthirtyam would you like to give this another set of eyes before I merge?
Will review and test as well and update you. |
// Bug in govmomi: can't batch-create cdroms and then mount ISO files, that | ||
// resuls in wrong UnitNumber. So do that one-by-one. |
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.
If calling out a bug (or is it actually a limitation) in vmware/govmomi
, it would be ideal to include a reference so that this can be reviewed in the future.
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.
Well… I currently don't have resources for creating a minimal testcase for this, so let's just rename this to a "limitation" if that's okay with you
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.
Renamed per comment above
// resuls in wrong UnitNumber. So do that one-by-one. | ||
for _, path := range s.Config.ISOPaths { | ||
if path == "" { | ||
state.Put("error", fmt.Errorf("Invalid path: empty string")) |
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.
state.Put("error", fmt.Errorf("Invalid path: empty string")) | |
state.Put("error", fmt.Errorf("invalid path: empty string")) |
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.
Done!
state.Put("error", fmt.Errorf("error adding sata controller: %v", err)) | ||
return multistep.ActionHalt | ||
} | ||
nActableCdroms := ReattachCDRom - len(s.CDRomConfig.ISOPaths) |
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.
nAttachableCdroms
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.
Done!
return multistep.ActionHalt | ||
} | ||
nActableCdroms := ReattachCDRom - len(s.CDRomConfig.ISOPaths) | ||
if nActableCdroms < 0 { |
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.
nAttachableCdroms
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.
Done!
// Add the CD-ROM devices to the image based on the value of `reattach_cdroms`. | ||
// A valid ISO path is required for this step. The media will subsequently be ejected. |
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.
Isn't this still useful information?
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.
Hmm, well, I suppose I can put it before nAttachableCdroms
calculation… I initially removed it because the whole point of the class and its method is to process reattach_cdroms
option. I.e. if you are inside this function, then you already know what this code supposed to do.
But I suppose the comment wouldn't hurt either, so I put it back.
return multistep.ActionHalt | ||
} | ||
} else { | ||
// Eject media from pre-existing CD-ROM devices. |
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.
// Eject media from pre-existing CD-ROM devices. | |
// Eject media from the existing CD-ROM devices. |
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.
Done!
if err != nil { | ||
state.Put("error", fmt.Errorf("error ejecting cdrom media: %v", err)) | ||
return multistep.ActionHalt | ||
// create more CD-ROMs if required |
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.
// create more CD-ROMs if required | |
// Add CD-ROMs, if required. |
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.
Done!
state.Put("error", fmt.Errorf("error ejecting cdrom media: %v", err)) | ||
return multistep.ActionHalt | ||
// create more CD-ROMs if required | ||
if nActableCdroms > 0 { |
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.
nAttachableCdroms
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.
Done!
} | ||
|
||
ui.Say("Adding CD-ROM devices...") | ||
for i := 0; i < nActableCdroms; i++ { |
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.
nAttachableCdroms
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.
Done!
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.
Minor changes requested.
This commit changes the "reattach" logic so that instead of removing all CDroms and recreating everything anew, we only remove the number of CDroms that are excess, and only add new CDroms when there was not enough pre-existing ones.
05e1a98
to
860f710
Compare
I'm dismissing in order to merge. All requested changes have been made
Hi Folks, apologies I've been out sick. Given that @Hi-Angel has addressed all of your request @tenthirtyam I dismissed your last review in order to unblock the merge and pending rebase. We can revisit anything if needed but this looks good to go. |
This fixes regression introduced by the commit "common: deduplicate AddCdrom call by appending path to ISOPaths" that was squashed into: "refactor: only add / remove minimul number of cdroms (hashicorp#355)" It assumed that the order is not guaranteed and does not matter, however the documentation says: > If the "iso_url" is defined in addition to the "iso_paths", the > "iso_url" is added to the VM first. This keeps the "iso_url" first > in the boot order by default allowing the boot iso being defined by > the iso_url and the vmware tools iso added from the datastore. So fix the regression. Fixes: hashicorp#386
This fixes regression introduced by the commit "common: deduplicate AddCdrom call by appending path to ISOPaths" that was squashed into: "refactor: only add / remove minimul number of cdroms (hashicorp#355)" It assumed that the order is not guaranteed and does not matter, however the documentation says: > If the "iso_url" is defined in addition to the "iso_paths", the > "iso_url" is added to the VM first. This keeps the "iso_url" first > in the boot order by default allowing the boot iso being defined by > the iso_url and the vmware tools iso added from the datastore. So fix the regression. Fixes: hashicorp#386 Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
This fixes regression introduced by the commit "common: deduplicate AddCdrom call by appending path to ISOPaths" that was squashed into: "refactor: only add / remove minimul number of cdroms (hashicorp#355)" It assumed that the order is not guaranteed and does not matter, however the documentation says: > If the "iso_url" is defined in addition to the "iso_paths", the > "iso_url" is added to the VM first. This keeps the "iso_url" first > in the boot order by default allowing the boot iso being defined by > the iso_url and the vmware tools iso added from the datastore. So fix the regression. Fixes: hashicorp#386 Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
This fixes regression introduced by the commit "common: deduplicate AddCdrom call by appending path to ISOPaths" that was squashed into: "refactor: only add / remove minimul number of cdroms (#355)" It assumed that the order is not guaranteed and does not matter, however the documentation says: > If the "iso_url" is defined in addition to the "iso_paths", the > "iso_url" is added to the VM first. This keeps the "iso_url" first > in the boot order by default allowing the boot iso being defined by > the iso_url and the vmware tools iso added from the datastore. So fix the regression. Fixes: #386 Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
In PR #344 a feature to reuse an existing VM is being added. As part of that feature I had to factor out from
AddCdrom
the logic of creating a CD-rom as opposed to just mounting an image. Recently merged featurereattach_cdroms
turned out to be a new user of the older logic, which made rebasing #344 non-trivial.In this PR I refactor the
reattach_cdroms
logic to avoid unnecessarily callingEjectCdroms
,RemoveCdroms
andAddCdrom
by calculating amount of CDroms that we want to have added/removed, and only calling the mentioned functions for that amount (see the last commit).This is a useful change in itself, disregarding whether #344 exists, so I'm sending it separately from the other PR. And it should simplify rebasing #344 later.