Merge pull request #8104 from medyagh/unit_test_machine

make deleting orphaned kics optional
pull/8107/head
Medya Ghazizadeh 2020-05-12 23:36:17 +00:00 committed by GitHub
commit 8a4e2610f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -339,7 +339,7 @@ func TestDeleteHost(t *testing.T) {
cc := defaultClusterConfig
cc.Name = viper.GetString("profile")
if err := DeleteHost(api, driver.MachineName(cc, config.Node{Name: "minikube"})); err != nil {
if err := DeleteHost(api, driver.MachineName(cc, config.Node{Name: "minikube"}), false); err != nil {
t.Fatalf("Unexpected error deleting host: %v", err)
}
}
@ -355,7 +355,7 @@ func TestDeleteHostErrorDeletingVM(t *testing.T) {
d := &tests.MockDriver{RemoveError: true, T: t}
h.Driver = d
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil {
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil {
t.Fatal("Expected error deleting host.")
}
}
@ -368,7 +368,7 @@ func TestDeleteHostErrorDeletingFiles(t *testing.T) {
t.Errorf("createHost failed: %v", err)
}
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil {
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil {
t.Fatal("Expected error deleting host.")
}
}
@ -383,7 +383,7 @@ func TestDeleteHostErrMachineNotExist(t *testing.T) {
t.Errorf("createHost failed: %v", err)
}
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"})); err == nil {
if err := DeleteHost(api, driver.MachineName(defaultClusterConfig, config.Node{Name: "minikube"}), false); err == nil {
t.Fatal("Expected error deleting host.")
}
}

View File

@ -60,9 +60,15 @@ func deleteOrphanedKIC(ociBin string, name string) {
}
// DeleteHost deletes the host VM.
func DeleteHost(api libmachine.API, machineName string) error {
// deleteAbandoned will will try to delete the machine even if there is no minikube config for it.
func DeleteHost(api libmachine.API, machineName string, deleteAbandoned ...bool) error {
delAbandoned := true
if len(deleteAbandoned) > 0 {
delAbandoned = deleteAbandoned[0]
}
host, err := api.Load(machineName)
if err != nil && host == nil {
if err != nil && host == nil && delAbandoned {
deleteOrphanedKIC(oci.Docker, machineName)
deleteOrphanedKIC(oci.Podman, machineName)
// Keep going even if minikube does not know about the host