Add num_retries configuration option

The boto library is designed for retrying failed actions automatically.

Bug #1089764

Change-Id: I4a42a87286e7d86e6569fa82c7309f2ea5fbfed9
This commit is contained in:
Attila Fazekas 2012-12-13 09:14:38 +01:00
parent 4949439ce3
commit f7f2d93039
3 changed files with 12 additions and 2 deletions

View File

@ -257,6 +257,9 @@ instance_type = m1.tiny
#TCP/IP connection timeout
http_socket_timeout = 5
#Number of retries actions on connection or 5xx error
num_retries = 1
# Status change wait timout
build_timeout = 120

View File

@ -469,6 +469,11 @@ class BotoConfig(BaseConfig):
"""boto Http socket timeout"""
return self.get("http_socket_timeout", "3")
@property
def num_retries(self):
"""boto num_retries on error"""
return self.get("num_retries", "1")
@property
def build_timeout(self):
"""status change timeout"""

View File

@ -36,6 +36,7 @@ class BotoClientBase(object):
*args, **kwargs):
self.connection_timeout = config.boto.http_socket_timeout
self.num_retries = config.boto.num_retries
self.build_timeout = config.boto.build_timeout
# We do not need the "path": "/token" part
if auth_url:
@ -63,12 +64,13 @@ class BotoClientBase(object):
raise NotFound("Unable to get access and secret keys")
return ec2_cred
def _config_boto_timeout(self, timeout):
def _config_boto_timeout(self, timeout, retries):
try:
boto.config.add_section("Boto")
except DuplicateSectionError:
pass
boto.config.set("Boto", "http_socket_timeout", timeout)
boto.config.set("Boto", "num_retries", retries)
def __getattr__(self, name):
"""Automatically creates methods for the allowed methods set"""
@ -86,7 +88,7 @@ class BotoClientBase(object):
raise AttributeError(name)
def get_connection(self):
self._config_boto_timeout(self.connection_timeout)
self._config_boto_timeout(self.connection_timeout, self.num_retries)
if not all((self.connection_data["aws_access_key_id"],
self.connection_data["aws_secret_access_key"])):
if all(self.ks_cred.itervalues()):