Skip to content

Conversation

tjones60
Copy link
Contributor

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.

@tjones60 tjones60 requested a review from a team as a code owner October 11, 2025 00:22
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 00:22
@tjones60 tjones60 requested a review from a team as a code owner October 11, 2025 00:22
Copy link
Contributor

@Copilot Copilot AI left a 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

Copy link
Contributor

@mattkur mattkur left a 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!(
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Comment on lines +57 to +64
powershell_builder::PowerShellBuilder::new()
.cmdlet("Get-VM")
.pipeline()
.cmdlet("Stop-VM")
.flag("TurnOff")
.finish()
.build()
.output()?;
Copy link
Contributor

@mattkur mattkur Oct 11, 2025

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:

  1. You can create VMs with well known names (or name prefix), or
  2. 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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link

@tjones60 tjones60 dismissed mattkur’s stale review October 14, 2025 18:34

made it only in ci

@tjones60 tjones60 merged commit 6375d9f into microsoft:main Oct 14, 2025
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants