Merge pull request #2061 from duftler/google-cleanup-disk-on-sigint
Delete GCE disk on SIGINT.
This commit is contained in:
commit
3bdf80a7e9
|
@ -125,6 +125,29 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) {
|
||||||
"Error: %s", name, err))
|
"Error: %s", name, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.Message("Instance has been deleted!")
|
||||||
state.Put("instance_name", "")
|
state.Put("instance_name", "")
|
||||||
|
|
||||||
|
// Deleting the instance does not remove the boot disk. This cleanup removes
|
||||||
|
// the disk.
|
||||||
|
ui.Say("Deleting disk...")
|
||||||
|
errCh, err = driver.DeleteDisk(config.Zone, config.DiskName)
|
||||||
|
if err == nil {
|
||||||
|
select {
|
||||||
|
case err = <-errCh:
|
||||||
|
case <-time.After(config.stateTimeout):
|
||||||
|
err = errors.New("time out while waiting for disk to delete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ui.Error(fmt.Sprintf(
|
||||||
|
"Error deleting disk. Please delete it manually.\n\n"+
|
||||||
|
"Name: %s\n"+
|
||||||
|
"Error: %s", config.InstanceName, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.Message("Disk has been deleted!")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,14 @@ func TestStepCreateInstance(t *testing.T) {
|
||||||
t.Fatal("should've deleted instance")
|
t.Fatal("should've deleted instance")
|
||||||
}
|
}
|
||||||
if driver.DeleteInstanceZone != config.Zone {
|
if driver.DeleteInstanceZone != config.Zone {
|
||||||
t.Fatalf("bad zone: %#v", driver.DeleteInstanceZone)
|
t.Fatalf("bad instance zone: %#v", driver.DeleteInstanceZone)
|
||||||
|
}
|
||||||
|
|
||||||
|
if driver.DeleteDiskName != config.InstanceName {
|
||||||
|
t.Fatal("should've deleted disk")
|
||||||
|
}
|
||||||
|
if driver.DeleteDiskZone != config.Zone {
|
||||||
|
t.Fatalf("bad disk zone: %#v", driver.DeleteDiskZone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue