provider/scaleway: delay between requests when waiting (#11184)

the CI sees many failing Scaleway tests due to request quotas being exceeded.
this PR aims to address this issue by switching from `resource.Retry`, which
waits 100ms between retries, to `resource.StateChangeConf` with a configured
delay of 5s between retries.

this should help us fixing the quota issue…
This commit is contained in:
Raphael Randschau 2017-01-13 11:49:16 +01:00 committed by Paul Stack
parent 7b168604a1
commit 3954c1ecf0
1 changed files with 30 additions and 27 deletions

View File

@ -48,21 +48,7 @@ func deleteRunningServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer)
return err
}
return resource.Retry(20*time.Minute, func() *resource.RetryError {
_, err := scaleway.GetServer(server.Identifier)
if err == nil {
return resource.RetryableError(fmt.Errorf("Waiting for server %q to be deleted", server.Identifier))
}
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return nil
}
}
return resource.RetryableError(err)
})
return waitForServerState(scaleway, server.Identifier, "stopped")
}
// deleteStoppedServer needs to cleanup attached root volumes. this is not done
@ -83,20 +69,37 @@ func deleteStoppedServer(scaleway *api.ScalewayAPI, server *api.ScalewayServer)
// NOTE copied from github.com/scaleway/scaleway-cli/pkg/api/helpers.go
// the helpers.go file pulls in quite a lot dependencies, and they're just convenience wrappers anyway
func waitForServerState(scaleway *api.ScalewayAPI, serverID, targetState string) error {
return resource.Retry(60*time.Minute, func() *resource.RetryError {
scaleway.ClearCache()
var allStates = []string{"starting", "running", "stopping", "stopped"}
func waitForServerState(scaleway *api.ScalewayAPI, serverID, targetState string) error {
pending := []string{}
for _, state := range allStates {
if state != targetState {
pending = append(pending, state)
}
}
stateConf := &resource.StateChangeConf{
Pending: pending,
Target: []string{targetState},
Refresh: func() (interface{}, string, error) {
s, err := scaleway.GetServer(serverID)
if err != nil {
return resource.NonRetryableError(err)
if err == nil {
return 42, s.State, nil
}
if s.State != targetState {
return resource.RetryableError(fmt.Errorf("Waiting for server to enter %q state", targetState))
if serr, ok := err.(api.ScalewayAPIError); ok {
if serr.StatusCode == 404 {
return 42, "stopped", nil
}
}
return nil
})
return 42, s.State, err
},
Timeout: 60 * time.Minute,
MinTimeout: 5 * time.Second,
Delay: 5 * time.Second,
}
_, err := stateConf.WaitForState()
return err
}