hyperv: use StopWithForce with remove

When doing a machine rm -f (force removal of a machine) or a machine
reset (force removal of all machines), there is no need to use a
"polite/soft" stop.

this will also speed up pkg/machine/e2e tests.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2023-09-24 09:47:27 -05:00
parent 2f7c2508ca
commit 2bef573f34
2 changed files with 3 additions and 5 deletions

View File

@ -212,11 +212,8 @@ func (v HyperVVirtualization) RemoveAndCleanMachines() error {
prevErr = handlePrevError(err, prevErr) prevErr = handlePrevError(err, prevErr)
} }
// If the VM is not stopped, we need to stop it
// TODO stop might not be enough if the state is dorked. we may need
// something like forceoff hard switch
if vm.State() != hypervctl.Disabled { if vm.State() != hypervctl.Disabled {
if err := vm.Stop(); err != nil { if err := vm.StopWithForce(); err != nil {
prevErr = handlePrevError(err, prevErr) prevErr = handlePrevError(err, prevErr)
} }
} }

View File

@ -359,7 +359,8 @@ func (m *HyperVMachine) Remove(_ string, opts machine.RemoveOptions) (string, fu
if !opts.Force { if !opts.Force {
return "", nil, &machine.ErrVMRunningCannotDestroyed{Name: m.Name} return "", nil, &machine.ErrVMRunningCannotDestroyed{Name: m.Name}
} }
if err := vm.Stop(); err != nil { // force stop bc we are destroying
if err := vm.StopWithForce(); err != nil {
return "", nil, err return "", nil, err
} }
} }