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