Skip to content

Commit

Permalink
Wait for detach optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmey committed Jun 3, 2019
1 parent 0f17804 commit fa07992
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 deletions builder/azure/chroot/diskattacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (

type DiskAttacher interface {
AttachDisk(ctx context.Context, disk string) (lun int32, err error)
DetachDisk(ctx context.Context, disk string) (err error)
WaitForDevice(ctx context.Context, i int32) (device string, err error)
DiskPathForLun(lun int32) string
WaitForDevice(ctx context.Context, i int32) (device string, err error)
DetachDisk(ctx context.Context, disk string) (err error)
WaitForDetach(ctx context.Context, diskID string) error
}

func NewDiskAttacher(azureClient client.AzureClientSet) DiskAttacher {
Expand Down Expand Up @@ -87,7 +88,10 @@ func (da *diskAttacher) DetachDisk(ctx context.Context, diskID string) error {
return err
}

// waiting for VM update to finish takes way to long
return nil
}

func (da *diskAttacher) WaitForDetach(ctx context.Context, diskID string) error {
for { // loop until disk is not attached, timeout or error
list, err := da.getDisks(ctx)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions builder/azure/chroot/step_create_new_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ func (s StepCreateNewDisk) Run(ctx context.Context, state multistep.StateBag) mu
func (s StepCreateNewDisk) Cleanup(state multistep.StateBag) {
azcli := state.Get("azureclient").(client.AzureClientSet)
ui := state.Get("ui").(packer.Ui)
diskResourceID := state.Get("os_disk_resource_id")
diskResourceID := state.Get("os_disk_resource_id").(string)

ui.Say(fmt.Sprintf("Deleting disk '%s'", diskResourceID))
ui.Say(fmt.Sprintf("Waiting for disk %q detach to complete", diskResourceID))
err := NewDiskAttacher(azcli).WaitForDetach(context.Background(), diskResourceID)

ui.Say(fmt.Sprintf("Deleting disk %q", diskResourceID))

f, err := azcli.DisksClient().Delete(context.TODO(), s.ResourceGroup, s.DiskName)
if err == nil {
Expand Down

0 comments on commit fa07992

Please sign in to comment.