Merge pull request #5654 from tstromberg/delete-anyways
Ensure that delete succeeds even if cluster is unavailablepull/5662/head
commit
56a23cab4a
|
@ -177,7 +177,7 @@ func deleteProfile(profile *pkg_config.Profile) error {
|
|||
if err = cluster.DeleteHost(api); err != nil {
|
||||
switch errors.Cause(err).(type) {
|
||||
case mcnerror.ErrHostDoesNotExist:
|
||||
out.T(out.Meh, `"{{.name}}" cluster does not exist. Proceeding ahead with cleanup.`, out.V{"name": profile})
|
||||
out.T(out.Meh, `"{{.name}}" cluster does not exist. Proceeding ahead with cleanup.`, out.V{"name": profile.Name})
|
||||
default:
|
||||
out.T(out.FailureType, "Failed to delete cluster: {{.error}}", out.V{"error": err})
|
||||
out.T(out.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": profile.Name})
|
||||
|
|
|
@ -270,16 +270,18 @@ func StopHost(api libmachine.API) error {
|
|||
|
||||
// DeleteHost deletes the host VM.
|
||||
func DeleteHost(api libmachine.API) error {
|
||||
host, err := api.Load(cfg.GetMachineName())
|
||||
name := cfg.GetMachineName()
|
||||
host, err := api.Load(name)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "load")
|
||||
}
|
||||
|
||||
// Get the status of the host. Ensure that it exists before proceeding ahead.
|
||||
status, err := GetHostStatus(api)
|
||||
if err != nil {
|
||||
exit.WithCodeT(exit.Failure, "Unable to get the status of the cluster.")
|
||||
// Warn, but proceed
|
||||
out.WarningT("Unable to get the status of the {{.name}} cluster.", out.V{"name": name})
|
||||
}
|
||||
|
||||
if status == state.None.String() {
|
||||
return mcnerror.ErrHostDoesNotExist{Name: host.Name}
|
||||
}
|
||||
|
|
|
@ -82,6 +82,13 @@ func TestDownloadAndDeleteAll(t *testing.T) {
|
|||
t.Errorf("%s failed: %v", rr.Args, err)
|
||||
}
|
||||
})
|
||||
// Delete should always succeed, even if previously partially or fully deleted.
|
||||
t.Run("DeleteAlwaysSucceeds", func(t *testing.T) {
|
||||
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
|
||||
if err != nil {
|
||||
t.Errorf("%s failed: %v", rr.Args, err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue