Merge "swift-recon fails with socket.timeout exception"

This commit is contained in:
Jenkins 2015-10-13 07:11:53 +00:00 committed by Gerrit Code Review
commit 70a52e6149
2 changed files with 22 additions and 4 deletions

View File

@ -18,7 +18,7 @@
from __future__ import print_function
from eventlet.green import urllib2
from eventlet.green import urllib2, socket
from six.moves.urllib.parse import urlparse
from swift.common.utils import SWIFT_CONF_FILE
from swift.common.ring import Ring
@ -88,7 +88,7 @@ class Scout(object):
print("-> %s: %s" % (url, err))
content = err
status = err.code
except urllib2.URLError as err:
except (urllib2.URLError, socket.timeout) as err:
if not self.suppress_errors or self.verbose:
print("-> %s: %s" % (url, err))
content = err
@ -130,7 +130,7 @@ class Scout(object):
print("-> %s: %s" % (url, err))
content = err
status = err.code
except urllib2.URLError as err:
except (urllib2.URLError, socket.timeout) as err:
if not self.suppress_errors or self.verbose:
print("-> %s: %s" % (url, err))
content = err

View File

@ -24,7 +24,7 @@ import tempfile
import time
import unittest
from eventlet.green import urllib2
from eventlet.green import urllib2, socket
from six import StringIO
from six.moves import urllib
@ -86,6 +86,15 @@ class TestScout(unittest.TestCase):
self.assertTrue(isinstance(content, urllib2.HTTPError))
self.assertEqual(status, 404)
@mock.patch('eventlet.green.urllib2.urlopen')
def test_scout_socket_timeout(self, mock_urlopen):
mock_urlopen.side_effect = socket.timeout("timeout")
url, content, status, ts_start, ts_end = self.scout_instance.scout(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, socket.timeout))
self.assertEqual(url, self.url)
self.assertEqual(status, -1)
@mock.patch('eventlet.green.urllib2.urlopen')
def test_scout_server_type_ok(self, mock_urlopen):
def getheader(name):
@ -117,6 +126,15 @@ class TestScout(unittest.TestCase):
self.assertTrue(isinstance(content, urllib2.HTTPError))
self.assertEqual(status, 404)
@mock.patch('eventlet.green.urllib2.urlopen')
def test_scout_server_type_socket_timeout(self, mock_urlopen):
mock_urlopen.side_effect = socket.timeout("timeout")
url, content, status = self.scout_instance.scout_server_type(
("127.0.0.1", "8080"))
self.assertTrue(isinstance(content, socket.timeout))
self.assertEqual(url, self.server_type_url)
self.assertEqual(status, -1)
class TestRecon(unittest.TestCase):
def setUp(self, *_args, **_kwargs):