Merge "glance:check the num_retries option"

This commit is contained in:
Jenkins 2015-07-03 10:34:11 +00:00 committed by Gerrit Code Review
commit d1cba6f9d5
2 changed files with 35 additions and 2 deletions

View File

@ -35,7 +35,7 @@ from six.moves import range
import six.moves.urllib.parse as urlparse
from nova import exception
from nova.i18n import _, _LE
from nova.i18n import _, _LE, _LW
import nova.image.download as image_xfers
@ -212,7 +212,13 @@ class GlanceClientWrapper(object):
retry_excs = (glanceclient.exc.ServiceUnavailable,
glanceclient.exc.InvalidEndpoint,
glanceclient.exc.CommunicationError)
num_attempts = 1 + CONF.glance.num_retries
retries = CONF.glance.num_retries
if retries < 0:
LOG.warning(_LW("Treating negative config value (%(retries)s) for "
"'glance.num_retries' as 0."),
{'retries': retries})
retries = 0
num_attempts = retries + 1
for attempt in range(1, num_attempts + 1):
client = self.client or self._create_onetime_client(context,

View File

@ -286,6 +286,33 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
client.call, ctx, 1, 'get', 'meow')
self.assertFalse(sleep_mock.called)
@mock.patch('nova.image.glance.LOG')
@mock.patch('time.sleep')
@mock.patch('nova.image.glance._create_glance_client')
def test_static_client_with_retries_negative(self, create_client_mock,
sleep_mock, mock_log):
client_mock = mock.Mock(spec=glanceclient.Client)
images_mock = mock.Mock()
images_mock.get.side_effect = glanceclient.exc.ServiceUnavailable
client_mock.images = images_mock
create_client_mock.return_value = client_mock
self.flags(num_retries=-1, group='glance')
ctx = context.RequestContext('fake', 'fake')
host = 'host4'
port = 9295
use_ssl = False
client = glance.GlanceClientWrapper(context=ctx, host=host, port=port,
use_ssl=use_ssl)
create_client_mock.assert_called_once_with(ctx, host, port, use_ssl, 1)
self.assertRaises(exception.GlanceConnectionFailed,
client.call, ctx, 1, 'get', 'meow')
self.assertTrue(mock_log.warning.called)
msg = mock_log.warning.call_args_list[0]
self.assertIn('Treating negative config value', msg[0][0])
self.assertFalse(sleep_mock.called)
@mock.patch('time.sleep')
@mock.patch('nova.image.glance._create_glance_client')
def test_static_client_with_retries(self, create_client_mock,