From 2bef573f348a0dbc6e35f5b87a7eb9c9629dea9e Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Sun, 24 Sep 2023 09:47:27 -0500 Subject: [PATCH] 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 --- pkg/machine/hyperv/config.go | 5 +---- pkg/machine/hyperv/machine.go | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/machine/hyperv/config.go b/pkg/machine/hyperv/config.go index 9f92e59b65..763117d710 100644 --- a/pkg/machine/hyperv/config.go +++ b/pkg/machine/hyperv/config.go @@ -212,11 +212,8 @@ func (v HyperVVirtualization) RemoveAndCleanMachines() error { 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 err := vm.Stop(); err != nil { + if err := vm.StopWithForce(); err != nil { prevErr = handlePrevError(err, prevErr) } } diff --git a/pkg/machine/hyperv/machine.go b/pkg/machine/hyperv/machine.go index eb7a55cd7c..260babdf7e 100644 --- a/pkg/machine/hyperv/machine.go +++ b/pkg/machine/hyperv/machine.go @@ -359,7 +359,8 @@ func (m *HyperVMachine) Remove(_ string, opts machine.RemoveOptions) (string, fu if !opts.Force { 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 } }