Merge "Fix ClientException handling in Container Sync"

This commit is contained in:
Jenkins 2016-01-13 14:44:00 +00:00 committed by Gerrit Code Review
commit dd405d9dd4
3 changed files with 15 additions and 11 deletions

View File

@ -23,7 +23,6 @@ from time import time
from eventlet import GreenPool, hubs, patcher, Timeout from eventlet import GreenPool, hubs, patcher, Timeout
from eventlet.pools import Pool from eventlet.pools import Pool
from eventlet.green import urllib2
from swift.common import direct_client from swift.common import direct_client
try: try:
@ -174,8 +173,8 @@ def object_dispersion_report(coropool, connpool, account, object_ring,
try: try:
objects = [o['name'] for o in conn.get_container( objects = [o['name'] for o in conn.get_container(
container, prefix='dispersion_', full_listing=True)[1]] container, prefix='dispersion_', full_listing=True)[1]]
except urllib2.HTTPError as err: except ClientException as err:
if err.getcode() != 404: if err.http_status != 404:
raise raise
print >>stderr, 'No objects to query. Has ' \ print >>stderr, 'No objects to query. Has ' \

View File

@ -26,9 +26,10 @@ from swift import gettext_ as _
from time import gmtime, strftime, time from time import gmtime, strftime, time
from zlib import compressobj from zlib import compressobj
from swift.common.utils import quote from swift.common.exceptions import ClientException
from swift.common.http import HTTP_NOT_FOUND, HTTP_MULTIPLE_CHOICES from swift.common.http import HTTP_NOT_FOUND, HTTP_MULTIPLE_CHOICES
from swift.common.swob import Request from swift.common.swob import Request
from swift.common.utils import quote
from swift.common.wsgi import loadapp, pipeline_property from swift.common.wsgi import loadapp, pipeline_property
@ -807,9 +808,14 @@ class SimpleClient(object):
self.attempts += 1 self.attempts += 1
try: try:
return self.base_request(method, **kwargs) return self.base_request(method, **kwargs)
except (socket.error, httplib.HTTPException, urllib2.URLError): except (socket.error, httplib.HTTPException, urllib2.URLError) \
as err:
if self.attempts > retries: if self.attempts > retries:
raise if isinstance(err, urllib2.HTTPError):
raise ClientException('Raise too many retries',
http_status=err.getcode())
else:
raise
sleep(backoff) sleep(backoff)
backoff = min(backoff * 2, self.max_backoff) backoff = min(backoff * 2, self.max_backoff)

View File

@ -26,8 +26,7 @@ from six.moves import range
from six.moves.urllib.parse import quote from six.moves.urllib.parse import quote
from test.unit import FakeLogger from test.unit import FakeLogger
from eventlet.green import urllib2 from eventlet.green import urllib2
from swift.common import internal_client from swift.common import exceptions, internal_client, swob
from swift.common import swob
from swift.common.storage_policy import StoragePolicy from swift.common.storage_policy import StoragePolicy
from test.unit import with_tempdir, write_fake_ring, patch_policies from test.unit import with_tempdir, write_fake_ring, patch_policies
@ -1329,7 +1328,7 @@ class TestSimpleClient(unittest.TestCase):
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5) mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
with mock.patch('swift.common.internal_client.sleep') \ with mock.patch('swift.common.internal_client.sleep') \
as mock_sleep: as mock_sleep:
self.assertRaises(urllib2.HTTPError, self.assertRaises(exceptions.ClientException,
c.retry_request, request_method, retries=1) c.retry_request, request_method, retries=1)
self.assertEqual(mock_sleep.call_count, 1) self.assertEqual(mock_sleep.call_count, 1)
self.assertEqual(mock_urlopen.call_count, 2) self.assertEqual(mock_urlopen.call_count, 2)
@ -1347,7 +1346,7 @@ class TestSimpleClient(unittest.TestCase):
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5) mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
with mock.patch('swift.common.internal_client.sleep') \ with mock.patch('swift.common.internal_client.sleep') \
as mock_sleep: as mock_sleep:
self.assertRaises(urllib2.HTTPError, self.assertRaises(exceptions.ClientException,
c.retry_request, request_method, c.retry_request, request_method,
container='con', retries=1) container='con', retries=1)
self.assertEqual(mock_sleep.call_count, 1) self.assertEqual(mock_sleep.call_count, 1)
@ -1366,7 +1365,7 @@ class TestSimpleClient(unittest.TestCase):
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5) mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
with mock.patch('swift.common.internal_client.sleep') \ with mock.patch('swift.common.internal_client.sleep') \
as mock_sleep: as mock_sleep:
self.assertRaises(urllib2.HTTPError, self.assertRaises(exceptions.ClientException,
c.retry_request, request_method, c.retry_request, request_method,
container='con', name='obj', retries=1) container='con', name='obj', retries=1)
self.assertEqual(mock_sleep.call_count, 1) self.assertEqual(mock_sleep.call_count, 1)