Merge pull request #3938 from mitchellh/retrycreatetags
builder/amazon: add retry login when creating tags.
This commit is contained in:
commit
e14bce7f9f
|
@ -4,9 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
retry "github.com/mitchellh/packer/common"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -71,9 +73,22 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = regionconn.CreateTags(&ec2.CreateTagsInput{
|
// Retry creating tags for about 2.5 minutes
|
||||||
Resources: resourceIds,
|
err = retry.Retry(0.2, 30, 11, func() (bool, error) {
|
||||||
Tags: ec2Tags,
|
_, err := regionconn.CreateTags(&ec2.CreateTagsInput{
|
||||||
|
Resources: resourceIds,
|
||||||
|
Tags: ec2Tags,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if awsErr, ok := err.(awserr.Error); ok {
|
||||||
|
if awsErr.Code() == "InvalidAMIID.NotFound" ||
|
||||||
|
awsErr.Code() == "InvalidSnapshot.NotFound" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, err
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mitchellh/packer/common"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"github.com/mitchellh/packer/version"
|
"github.com/mitchellh/packer/version"
|
||||||
|
|
||||||
|
@ -458,7 +459,7 @@ type stateRefreshFunc func() (string, error)
|
||||||
// waitForState will spin in a loop forever waiting for state to
|
// waitForState will spin in a loop forever waiting for state to
|
||||||
// reach a certain target.
|
// reach a certain target.
|
||||||
func waitForState(errCh chan<- error, target string, refresh stateRefreshFunc) error {
|
func waitForState(errCh chan<- error, target string, refresh stateRefreshFunc) error {
|
||||||
err := Retry(2, 2, 0, func() (bool, error) {
|
err := common.Retry(2, 2, 0, func() (bool, error) {
|
||||||
state, err := refresh()
|
state, err := refresh()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package googlecompute
|
package googlecompute
|
||||||
|
|
||||||
import(
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/common"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ func (s *StepWaitInstanceStartup) Run(state multistep.StateBag) multistep.StepAc
|
||||||
ui.Say("Waiting for any running startup script to finish...")
|
ui.Say("Waiting for any running startup script to finish...")
|
||||||
|
|
||||||
// Keep checking the serial port output to see if the startup script is done.
|
// Keep checking the serial port output to see if the startup script is done.
|
||||||
err := Retry(10, 60, 0, func() (bool, error) {
|
err := common.Retry(10, 60, 0, func() (bool, error) {
|
||||||
status, err := driver.GetInstanceMetadata(config.Zone,
|
status, err := driver.GetInstanceMetadata(config.Zone,
|
||||||
instanceName, StartupScriptStatusKey)
|
instanceName, StartupScriptStatusKey)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package googlecompute
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -25,7 +25,7 @@ func Retry(initialInterval float64, maxInterval float64, numTries uint, function
|
||||||
done := false
|
done := false
|
||||||
interval := initialInterval
|
interval := initialInterval
|
||||||
for i := uint(0); !done && (numTries == 0 || i < numTries); i++ {
|
for i := uint(0); !done && (numTries == 0 || i < numTries); i++ {
|
||||||
done, err = function()
|
done, err = function()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -33,12 +33,12 @@ func Retry(initialInterval float64, maxInterval float64, numTries uint, function
|
||||||
if !done {
|
if !done {
|
||||||
// Retry after delay. Calculate next delay.
|
// Retry after delay. Calculate next delay.
|
||||||
time.Sleep(time.Duration(interval) * time.Second)
|
time.Sleep(time.Duration(interval) * time.Second)
|
||||||
interval = math.Min(interval * 2, maxInterval)
|
interval = math.Min(interval*2, maxInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !done {
|
if !done {
|
||||||
return RetryExhaustedError
|
return RetryExhaustedError
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package googlecompute
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue