Catch RetriableConnectionFailures from KAuth and retry

Some keystone auth failures are retriable, this patch ensures that when
ironiclient retries are turned on, we also retry on those failures.

Change-Id: I7181b2aa4c8d0cc3b5523cb913562bee2e1955a2
Closes-Bug: #1537076
This commit is contained in:
Sam Betts
2016-06-01 13:51:22 +01:00
parent 7623bc6197
commit 11a3f12c3a
3 changed files with 23 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import textwrap
import time import time
from keystoneauth1 import adapter from keystoneauth1 import adapter
from keystoneauth1 import exceptions as kexc
from oslo_utils import strutils from oslo_utils import strutils
import requests import requests
import six import six
@@ -171,7 +172,7 @@ class VersionNegotiationMixin(object):
_RETRY_EXCEPTIONS = (exc.Conflict, exc.ServiceUnavailable, _RETRY_EXCEPTIONS = (exc.Conflict, exc.ServiceUnavailable,
exc.ConnectionRefused) exc.ConnectionRefused, kexc.RetriableConnectionFailure)
def with_retries(func): def with_retries(func):

View File

@@ -20,6 +20,8 @@ import mock
import six import six
from six.moves import http_client from six.moves import http_client
from keystoneauth1 import exceptions as kexc
from ironicclient.common import filecache from ironicclient.common import filecache
from ironicclient.common import http from ironicclient.common import http
from ironicclient import exc from ironicclient import exc
@@ -727,6 +729,19 @@ class RetriesTestCase(utils.BaseTestCase):
client.json_request('GET', '/v1/resources') client.json_request('GET', '/v1/resources')
self.assertEqual(2, fake_session.request.call_count) self.assertEqual(2, fake_session.request.call_count)
def test_session_retry_retriable_connection_failure(self):
ok_resp = utils.FakeSessionResponse(
{'Content-Type': 'application/json'},
b"OK",
http_client.OK)
fake_session = mock.Mock(spec=utils.FakeSession)
fake_session.request.side_effect = iter(
(kexc.RetriableConnectionFailure(), ok_resp))
client = _session_client(session=fake_session)
client.json_request('GET', '/v1/resources')
self.assertEqual(2, fake_session.request.call_count)
def test_session_retry_fail(self): def test_session_retry_fail(self):
error_body = _get_error_body() error_body = _get_error_body()

View File

@@ -0,0 +1,6 @@
---
fixes:
- The client will now retry on keystoneauth retriable connection failures if
retries are enabled for a particular request. This ensures that on a
temporary network outage to the keystone auth services a request we be
retried the requested number of times before raising an exception.