Fix swift-dispersion-populate bug when using SimpleClient class

Commit 7fcbbebb changed the internal client a little bit and removed the
class variable self.attempts in SimpleClient. This is currently still
needed in swift-dispersion-populate to track the number of retries, thus
re-adding it again.

Closes-Bug: 1351323
Change-Id: I98ba6441607158b34708b2dbb2d1a63788681d63
This commit is contained in:
Christian Schwede 2014-08-01 13:55:21 +00:00
parent 9bc3b0ebd8
commit 8ad37b2217
2 changed files with 6 additions and 4 deletions

View File

@ -728,6 +728,7 @@ class SimpleClient(object):
max_backoff=5, retries=5):
self.url = url
self.token = token
self.attempts = 0 # needed in swif-dispersion-populate
self.starting_backoff = starting_backoff
self.max_backoff = max_backoff
self.retries = retries
@ -796,14 +797,14 @@ class SimpleClient(object):
def retry_request(self, method, **kwargs):
retries = kwargs.pop('retries', self.retries)
attempts = 0
self.attempts = 0
backoff = self.starting_backoff
while attempts <= retries:
attempts += 1
while self.attempts <= retries:
self.attempts += 1
try:
return self.base_request(method, **kwargs)
except (socket.error, httplib.HTTPException, urllib2.URLError):
if attempts > retries:
if self.attempts > retries:
raise
sleep(backoff)
backoff = min(backoff * 2, self.max_backoff)

View File

@ -1211,6 +1211,7 @@ class TestSimpleClient(unittest.TestCase):
request.assert_called_with('http://127.0.0.1?format=json', data=None,
headers={'X-Auth-Token': 'token'})
self.assertEqual([None, None], retval)
self.assertEqual(sc.attempts, 2)
@mock.patch('eventlet.green.urllib2.urlopen')
def test_get_with_retries_param(self, mock_urlopen):