builder/amazon/common: error if WaitForState can't find resource
repeatably
This commit is contained in:
parent
f9feeac355
commit
7c56148f95
|
@ -7,6 +7,8 @@ IMPROVEMENTS:
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
||||||
* builder/amazon/*: While waiting for AMI, will detect "failed" state.
|
* builder/amazon/*: While waiting for AMI, will detect "failed" state.
|
||||||
|
* builder/amazon/*: Waiting for state will detect if the resource (AMI,
|
||||||
|
instance, etc.) disappears from under it.
|
||||||
* provisioner/puppet-masterless: Fix failure case when both facter vars
|
* provisioner/puppet-masterless: Fix failure case when both facter vars
|
||||||
are used and prevent_sudo. [GH-415]
|
are used and prevent_sudo. [GH-415]
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,8 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc {
|
||||||
func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
|
func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
|
||||||
log.Printf("Waiting for state to become: %s", conf.Target)
|
log.Printf("Waiting for state to become: %s", conf.Target)
|
||||||
|
|
||||||
|
notfoundTick := 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var currentState string
|
var currentState string
|
||||||
i, currentState, err = conf.Refresh()
|
i, currentState, err = conf.Refresh()
|
||||||
|
@ -89,9 +91,17 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check states only if we were able to refresh to an instance
|
if i == nil {
|
||||||
// that exists.
|
// If we didn't find the resource, check if we have been
|
||||||
if i != nil {
|
// not finding it for awhile, and if so, report an error.
|
||||||
|
notfoundTick += 1
|
||||||
|
if notfoundTick > 20 {
|
||||||
|
return nil, errors.New("couldn't find resource")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reset the counter for when a resource isn't found
|
||||||
|
notfoundTick = 0
|
||||||
|
|
||||||
if currentState == conf.Target {
|
if currentState == conf.Target {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue