Commit 3bdf80a7 authored by Eric Johnson's avatar Eric Johnson

Merge pull request #2061 from duftler/google-cleanup-disk-on-sigint

Delete GCE disk on SIGINT.
parents 419f3271 6d28ee93
...@@ -125,6 +125,29 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) { ...@@ -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) { ...@@ -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)
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment