From 04109fc522021a3be8829ae73a18f6bd6b13e99f Mon Sep 17 00:00:00 2001 From: yatinkarel Date: Thu, 19 Sep 2024 18:32:11 +0530 Subject: [PATCH] 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 (cherry picked from commit 7d1a20ed4d458c6682a52679b71b6bc8dea20d07) --- neutron/notifiers/nova.py | 3 +++ neutron/tests/unit/notifiers/test_nova.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 1269187ec98..9cb6c3880e2 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -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) diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 4456dd393c4..3567476549b 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -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