-
Notifications
You must be signed in to change notification settings - Fork 155
ci: remove any existing vms before running prep steps #2150
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
Conversation
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.
Pull Request Overview
Fixes an issue where prep steps could fail when VMs from previous test runs remain active and hold locks on prepped VHD files. The solution adds VM cleanup logic to remove any existing VMs before running prep steps on Windows platforms.
- Adds VM detection and removal logic using PowerShell commands on Windows
- Introduces a new dependency on the
powershell_builder
crate to handle VM cleanup operations
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
flowey/flowey_lib_hvlite/src/run_prep_steps.rs | Adds Windows-specific VM cleanup logic using PowerShell commands to stop and remove existing VMs |
flowey/flowey_lib_hvlite/Cargo.toml | Adds powershell_builder workspace dependency |
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.
Thanks for doing this work to improve our test pass reliability! Marking as 'request changes' for my question re: if this will delete all the VMs on my test system. Assuming that is taken care of, you can dismiss my review and commit when you get any valid review.
.finish() | ||
.build() | ||
.output()?; | ||
log::info!( |
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.
nit: this could be a warning (since having leftover VMs from a previous run can indicate some other bug)
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.
True, but the way I have it written it will print an empty list if there are none (was trying to avoid parsing the output) but I support I could parse it and only log if there are some vms.
powershell_builder::PowerShellBuilder::new() | ||
.cmdlet("Get-VM") | ||
.pipeline() | ||
.cmdlet("Stop-VM") | ||
.flag("TurnOff") | ||
.finish() | ||
.build() | ||
.output()?; |
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.
Does this run when I run my tests locally? If so, this will delete any VMs not created by VMM tests.
Assuming that's the case, you have a couple options:
- You can create VMs with well known names (or name prefix), or
- You can set some metadata on the test-created VMs.
For (2), you can use the Notes
field:
> set-vm -VMName foo -Notes "vmm-test"
> get-vm foo | fl name,id,notes
Name : foo
Id : e2c55646-ce47-4602-9233-cb258725c0f6
Notes : vmm-test
To further illustrate:
PS C:\Users\mattkur> get-vm | fl name,notes
Name : match
Notes : vmm-test
Name : nomatch
Notes :
PS C:\Users\mattkur> Get-VM | Where-Object { $_.Notes -match "vmm-test" }
Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version
---- ----- ----------- ----------------- ------ ------ -------
match Off 0 0 00:00:00 Operating normally 12.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.
You are right, I intended to make it so this would only run in CI, but I think it would also running in xflowey vmm-tests (although prep-steps doesn't work locally right now, we need to sort that out). That seems like a good idea to use the notes field. We could also maybe enumerate the attached disks and see if any are pointing to file we want to delete. Turning off the VMs might also be sufficient, rather than deleting.
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.
Sure. I'd argue that CI should not delete VMs on my dev box without my explicit permission.
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.
For now I just added a check to only do it in CI. We can do more fancy stuff later.
Fixes an issue where prep_steps could fail if the previous test run left VMs running that were using the prepped VHD from the previous run, since prep_steps tries to remove this in use file. Normal VMM tests don't have this issue, since they remove VMs of the same name before starting.