Fix dispersion-reports error message
This patch fixes Swift to show message "No objects to query. Has swift-dispersion-populate been run?" for "swift-dispersion-report —object-only” with no container for object dispersion. Change-Id: I82da56709cfc296a27f5180681709bc56adbc13d Closes-Bug: #1468120
This commit is contained in:
parent
a2c0e6f687
commit
c690bcb683
@ -26,6 +26,7 @@ except ImportError:
|
||||
|
||||
from eventlet import GreenPool, hubs, patcher, Timeout
|
||||
from eventlet.pools import Pool
|
||||
from eventlet.green import urllib2
|
||||
|
||||
from swift.common import direct_client
|
||||
try:
|
||||
@ -176,9 +177,10 @@ def object_dispersion_report(coropool, connpool, account, object_ring,
|
||||
try:
|
||||
objects = [o['name'] for o in conn.get_container(
|
||||
container, prefix='dispersion_', full_listing=True)[1]]
|
||||
except ClientException as err:
|
||||
if err.http_status != 404:
|
||||
raise
|
||||
except urllib2.HTTPError as err:
|
||||
if err.getcode() != 404:
|
||||
raise err
|
||||
|
||||
print >>stderr, 'No objects to query. Has ' \
|
||||
'swift-dispersion-populate been run?'
|
||||
stderr.flush()
|
||||
|
@ -1264,6 +1264,61 @@ class TestSimpleClient(unittest.TestCase):
|
||||
self.assertEqual(mock_urlopen.call_count, 2)
|
||||
self.assertEqual([None, None], retval)
|
||||
|
||||
@mock.patch('eventlet.green.urllib2.urlopen')
|
||||
def test_request_with_retries_with_HTTPError(self, mock_urlopen):
|
||||
mock_response = mock.MagicMock()
|
||||
mock_response.read.return_value = ''
|
||||
c = internal_client.SimpleClient(url='http://127.0.0.1', token='token')
|
||||
self.assertEqual(c.retries, 5)
|
||||
|
||||
for request_method in 'GET PUT POST DELETE HEAD COPY'.split():
|
||||
mock_urlopen.reset_mock()
|
||||
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
|
||||
with mock.patch('swift.common.internal_client.sleep') \
|
||||
as mock_sleep:
|
||||
self.assertRaises(urllib2.HTTPError,
|
||||
c.retry_request, request_method, retries=1)
|
||||
self.assertEqual(mock_sleep.call_count, 1)
|
||||
self.assertEqual(mock_urlopen.call_count, 2)
|
||||
|
||||
@mock.patch('eventlet.green.urllib2.urlopen')
|
||||
def test_request_container_with_retries_with_HTTPError(self,
|
||||
mock_urlopen):
|
||||
mock_response = mock.MagicMock()
|
||||
mock_response.read.return_value = ''
|
||||
c = internal_client.SimpleClient(url='http://127.0.0.1', token='token')
|
||||
self.assertEqual(c.retries, 5)
|
||||
|
||||
for request_method in 'GET PUT POST DELETE HEAD COPY'.split():
|
||||
mock_urlopen.reset_mock()
|
||||
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
|
||||
with mock.patch('swift.common.internal_client.sleep') \
|
||||
as mock_sleep:
|
||||
self.assertRaises(urllib2.HTTPError,
|
||||
c.retry_request, request_method,
|
||||
container='con', retries=1)
|
||||
self.assertEqual(mock_sleep.call_count, 1)
|
||||
self.assertEqual(mock_urlopen.call_count, 2)
|
||||
|
||||
@mock.patch('eventlet.green.urllib2.urlopen')
|
||||
def test_request_object_with_retries_with_HTTPError(self,
|
||||
mock_urlopen):
|
||||
mock_response = mock.MagicMock()
|
||||
mock_response.read.return_value = ''
|
||||
c = internal_client.SimpleClient(url='http://127.0.0.1', token='token')
|
||||
self.assertEqual(c.retries, 5)
|
||||
|
||||
for request_method in 'GET PUT POST DELETE HEAD COPY'.split():
|
||||
mock_urlopen.reset_mock()
|
||||
mock_urlopen.side_effect = urllib2.HTTPError(*[None] * 5)
|
||||
with mock.patch('swift.common.internal_client.sleep') \
|
||||
as mock_sleep:
|
||||
self.assertRaises(urllib2.HTTPError,
|
||||
c.retry_request, request_method,
|
||||
container='con', name='obj', retries=1)
|
||||
self.assertEqual(mock_sleep.call_count, 1)
|
||||
self.assertEqual(mock_urlopen.call_count, 2)
|
||||
|
||||
def test_proxy(self):
|
||||
# check that proxy arg is passed through to the urllib Request
|
||||
scheme = 'http'
|
||||
|
Loading…
Reference in New Issue
Block a user