Commit 716d4719 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #1622 from delitescere/GH-1533-aws-timeout

builder/amazon: Extend timeout and allow user override [GH-1533]
parents 0e856de9 c22eda1e
......@@ -23,6 +23,7 @@ BUG FIXES:
* builder/vmware: Wait some time so that post-VMX update aren't
overwritten. [GH-1504]
* builder/vmware-vmx: Fix issue with order of boot command support [GH-1492]
* builder/amazon: Extend timeout and allow user override [GH-1533]
* builder/parallels: Ignore 'The fdd0 device does not exist' [GH-1501]
* builder/parallels: Rely on Cleanup functions to detach devices [GH-1502]
* builder/parallels: Create VM without hdd and then add it later [GH-1548]
......
......@@ -15,6 +15,9 @@ testrace:
go test -race $(TEST) $(TESTARGS)
updatedeps:
go get -u -v -p 2 ./...
go get -d -v -p 2 ./...
@sh -c "go get -u -v -p 2 ./...; exit 0"
@sh -c "cd ../../rackspace/gophercloud && git checkout release/v0.1.1" # because dependency management
go get -d -v -p 2 ./...
.PHONY: bin default test updatedeps
......@@ -7,6 +7,8 @@ import (
"github.com/mitchellh/multistep"
"log"
"net"
"os"
"strconv"
"time"
)
......@@ -122,6 +124,8 @@ func SpotRequestStateRefreshFunc(conn *ec2.EC2, spotRequestId string) StateRefre
func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
log.Printf("Waiting for state to become: %s", conf.Target)
sleepSeconds := 2
maxTicks := int(TimeoutSeconds() / sleepSeconds) + 1
notfoundTick := 0
for {
......@@ -135,7 +139,7 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
// If we didn't find the resource, check if we have been
// not finding it for awhile, and if so, report an error.
notfoundTick += 1
if notfoundTick > 20 {
if notfoundTick > maxTicks {
return nil, errors.New("couldn't find resource")
}
} else {
......@@ -166,7 +170,7 @@ func WaitForState(conf *StateChangeConf) (i interface{}, err error) {
}
}
time.Sleep(2 * time.Second)
time.Sleep(time.Duration(sleepSeconds) * time.Second)
}
return
......@@ -179,3 +183,23 @@ func isTransientNetworkError(err error) bool {
return false
}
// Returns 300 seconds (5 minutes) by default
// Some AWS operations, like copying an AMI to a distant region, take a very long time
// Allow user to override with AWS_TIMEOUT_SECONDS environment variable
func TimeoutSeconds() (seconds int) {
seconds = 300
override := os.Getenv("AWS_TIMEOUT_SECONDS")
if override != "" {
n, err := strconv.Atoi(override)
if err != nil {
log.Printf("Invalid timeout seconds '%s', using default", override)
} else {
seconds = n
}
}
log.Printf("Allowing %ds to complete (change with AWS_TIMEOUT_SECONDS)", seconds)
return seconds
}
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