Handle EndpointNotFound in nova notifier

Currently if the nova endpoint do not exist
exception is raised. Even the endpoint gets created
notification keeps on failing until the session
expires.
If the endpoint not exist the session is not useful
so marking it as invalid, this will ensure if endpoint is
created later the notification do not fail.

Closes-Bug: #2081174
Change-Id: I1f7fd1d1371ca0a3c4edb409cffd2177d44a1f23
This commit is contained in:
yatinkarel 2024-09-19 18:32:11 +05:30
parent 08fff4087d
commit 7d1a20ed4d
2 changed files with 13 additions and 0 deletions

View File

@ -281,6 +281,9 @@ class Notifier(object):
try:
response = novaclient.server_external_events.create(
batched_events)
except ks_exceptions.EndpointNotFound:
LOG.exception("Nova endpoint not found, invalidating the session")
self.session.invalidate()
except nova_exceptions.NotFound:
LOG.debug("Nova returned NotFound for event: %s",
batched_events)

View File

@ -237,6 +237,16 @@ class TestNovaNotify(base.BaseTestCase):
{}, {})
self.assertFalse(send_events.called)
@mock.patch('novaclient.client.Client')
def test_nova_send_events_noendpoint_invalidate_session(self, mock_client):
create = mock_client().server_external_events.create
create.side_effect = ks_exc.EndpointNotFound
with mock.patch.object(self.nova_notifier.session,
'invalidate', return_value=True) as mock_sess:
self.nova_notifier.send_events([])
create.assert_called()
mock_sess.assert_called()
@mock.patch('novaclient.client.Client')
def test_nova_send_events_returns_bad_list(self, mock_client):
create = mock_client().server_external_events.create