Merge pull request #5654 from tstromberg/delete-anyways

Ensure that delete succeeds even if cluster is unavailable
pull/5662/head
Thomas Strömberg 2019-10-18 16:06:12 -07:00 committed by GitHub
commit 56a23cab4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -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})

View File

@ -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}
}

View File

@ -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)
}
})
})
}