From f52a2ad0fa1e1062e3200f019153a0cb6e8348a0 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 11 Nov 2020 15:52:06 -0800 Subject: [PATCH] move retry function that is only used by osc builder into that builder's common dir instead of the global common dir. Fix bug in quemu where the wrong retry value is checked against. --- {common => builder/osc/common/retry}/retry.go | 2 +- {common => builder/osc/common/retry}/retry_test.go | 2 +- builder/osc/common/state.go | 4 ++-- builder/osc/common/step_create_tags.go | 2 +- builder/osc/common/step_run_source_vm.go | 2 +- builder/osc/common/step_stop_bsu_backed_vm.go | 4 ++-- builder/qemu/step_convert_disk.go | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) rename {common => builder/osc/common/retry}/retry.go (99%) rename {common => builder/osc/common/retry}/retry_test.go (99%) diff --git a/common/retry.go b/builder/osc/common/retry/retry.go similarity index 99% rename from common/retry.go rename to builder/osc/common/retry/retry.go index b820cf817..628a86a69 100644 --- a/common/retry.go +++ b/builder/osc/common/retry/retry.go @@ -1,4 +1,4 @@ -package common +package retry import ( "fmt" diff --git a/common/retry_test.go b/builder/osc/common/retry/retry_test.go similarity index 99% rename from common/retry_test.go rename to builder/osc/common/retry/retry_test.go index 364f31a5c..bd59cb459 100644 --- a/common/retry_test.go +++ b/builder/osc/common/retry/retry_test.go @@ -1,4 +1,4 @@ -package common +package retry import ( "fmt" diff --git a/builder/osc/common/state.go b/builder/osc/common/state.go index a2e0e53a7..50afe4cce 100644 --- a/builder/osc/common/state.go +++ b/builder/osc/common/state.go @@ -6,7 +6,7 @@ import ( "log" "github.com/antihax/optional" - "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/builder/osc/common/retry" "github.com/outscale/osc-sdk-go/osc" ) @@ -68,7 +68,7 @@ func WaitUntilOscSnapshotDone(conn *osc.APIClient, snapshotID string) error { } func waitForState(errCh chan<- error, target string, refresh stateRefreshFunc) { - err := common.Retry(2, 2, 0, func(_ uint) (bool, error) { + err := retry.Retry(2, 2, 0, func(_ uint) (bool, error) { state, err := refresh() if err != nil { return false, err diff --git a/builder/osc/common/step_create_tags.go b/builder/osc/common/step_create_tags.go index f0382f560..2a2c60961 100644 --- a/builder/osc/common/step_create_tags.go +++ b/builder/osc/common/step_create_tags.go @@ -6,7 +6,7 @@ import ( "github.com/antihax/optional" "github.com/aws/aws-sdk-go/aws/awserr" - retry "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/builder/osc/common/retry" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate" diff --git a/builder/osc/common/step_run_source_vm.go b/builder/osc/common/step_run_source_vm.go index 2eb251c47..0d0cb6054 100644 --- a/builder/osc/common/step_run_source_vm.go +++ b/builder/osc/common/step_run_source_vm.go @@ -12,7 +12,7 @@ import ( "github.com/aws/aws-sdk-go/aws/awserr" "github.com/outscale/osc-sdk-go/osc" - retry "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/builder/osc/common/retry" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/osc/common/step_stop_bsu_backed_vm.go b/builder/osc/common/step_stop_bsu_backed_vm.go index 9c31a3c8b..62cd830ac 100644 --- a/builder/osc/common/step_stop_bsu_backed_vm.go +++ b/builder/osc/common/step_stop_bsu_backed_vm.go @@ -6,7 +6,7 @@ import ( "github.com/antihax/optional" "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/builder/osc/common/retry" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "github.com/outscale/osc-sdk-go/osc" @@ -41,7 +41,7 @@ func (s *StepStopBSUBackedVm) Run(ctx context.Context, state multistep.StateBag) // does not exist. // Work around this by retrying a few times, up to about 5 minutes. - err := common.Retry(10, 60, 6, func(i uint) (bool, error) { + err := retry.Retry(10, 60, 6, func(i uint) (bool, error) { ui.Message(fmt.Sprintf("Stopping vm, attempt %d", i+1)) _, _, err = oscconn.VmApi.StopVms(context.Background(), &osc.StopVmsOpts{ diff --git a/builder/qemu/step_convert_disk.go b/builder/qemu/step_convert_disk.go index 8e06cc821..a97343264 100644 --- a/builder/qemu/step_convert_disk.go +++ b/builder/qemu/step_convert_disk.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common/retry" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -62,12 +61,13 @@ func (s *stepConvertDisk) Run(ctx context.Context, state multistep.StateBag) mul }) if err != nil { - if err == common.RetryExhaustedError { + switch err.(type) { + case *retry.RetryExhaustedError: err = fmt.Errorf("Exhausted retries for getting file lock: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt - } else { + default: err := fmt.Errorf("Error converting hard drive: %s", err) state.Put("error", err) ui.Error(err.Error())