Skip to content

Commit e60184b

Browse files
Szymon Wroblewskislawqo
authored andcommitted
Retry connections to Nova
Sometimes Neutron is failing to send notification to Nova due to timeout, refused connection or another HTTP error. Retry send in those cases. Closes-Bug: #1987780 Change-Id: Iaaccec770484234b704f70f3c144efac4d8ffba0 (cherry picked from commit cd475f9)
1 parent b11fb88 commit e60184b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

neutron/notifiers/nova.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import contextlib
1717

1818
from eventlet.green import threading
19+
from keystoneauth1 import exceptions as ks_exceptions
1920
from keystoneauth1 import loading as ks_loading
2021
from neutron_lib.callbacks import events
2122
from neutron_lib.callbacks import registry
@@ -32,6 +33,7 @@
3233
from oslo_log import log as logging
3334
from oslo_utils import uuidutils
3435
from sqlalchemy.orm import attributes as sql_attr
36+
import tenacity
3537

3638
from neutron.notifiers import batch_notifier
3739

@@ -267,6 +269,12 @@ def notify_port_active_direct(self, port):
267269
'tag': port.id})
268270
self.send_port_status(None, None, port)
269271

272+
@tenacity.retry(
273+
retry=tenacity.retry_if_exception_type(
274+
ks_exceptions.RetriableConnectionFailure),
275+
wait=tenacity.wait_exponential(multiplier=0.01, max=1),
276+
stop=tenacity.stop_after_delay(1),
277+
after=tenacity.after_log(LOG, logging.DEBUG))
270278
def send_events(self, batched_events):
271279
LOG.debug("Sending events: %s", batched_events)
272280
novaclient = self._get_nova_client()
@@ -276,6 +284,10 @@ def send_events(self, batched_events):
276284
except nova_exceptions.NotFound:
277285
LOG.debug("Nova returned NotFound for event: %s",
278286
batched_events)
287+
except ks_exceptions.RetriableConnectionFailure:
288+
raise
289+
# next clause handles all exceptions
290+
# so reraise for retry decorator
279291
except Exception:
280292
LOG.exception("Failed to notify nova on events: %s",
281293
batched_events)

neutron/tests/unit/notifiers/test_nova.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from unittest import mock
1818

1919
import eventlet
20+
from keystoneauth1 import exceptions as ks_exc
2021
from neutron_lib import constants as n_const
2122
from neutron_lib import context as n_ctx
2223
from neutron_lib import exceptions as n_exc
@@ -248,6 +249,14 @@ def test_nova_send_event_rasies_404(self, mock_client):
248249
nova_exceptions.NotFound)
249250
self.nova_notifier.send_events([])
250251

252+
@mock.patch('novaclient.client.Client')
253+
def test_nova_send_events_raises_connect_exc(self, mock_client):
254+
create = mock_client().server_external_events.create
255+
create.side_effect = (
256+
ks_exc.ConnectFailure, ks_exc.ConnectTimeout, [])
257+
self.nova_notifier.send_events([])
258+
self.assertEqual(3, create.call_count)
259+
251260
@mock.patch('novaclient.client.Client')
252261
def test_nova_send_events_raises(self, mock_client):
253262
mock_client.server_external_events.create.return_value = Exception

0 commit comments

Comments
 (0)