From efc77163faf65060d74fcb48ca15a98af534d4a4 Mon Sep 17 00:00:00 2001 From: Kiran Pawar Date: Wed, 12 Feb 2025 09:59:41 +0000 Subject: [PATCH] Ignore not found exception during port delete On neutron port delete, manila raise exception when API call goes wrong. But if port is deleted already, we can simply ignore it and mention warning log. Closes-bug: #2098083 Co-authored-by: Maurice Escher Change-Id: I3f660258f5e24a7ec7a6e7a1fdf464dc6c374a45 (cherry picked from commit 7cde91fcc821275f02333b7fc003983f636255bd) --- manila/network/neutron/api.py | 3 ++ .../tests/network/neutron/test_neutron_api.py | 29 +++++++++++++++++++ ...lete-not-found-error-5acafa7a7810a210.yaml | 7 +++++ 3 files changed, 39 insertions(+) create mode 100644 releasenotes/notes/bug-2098083-Pass-on-port-delete-not-found-error-5acafa7a7810a210.yaml diff --git a/manila/network/neutron/api.py b/manila/network/neutron/api.py index c675925566..b999085aff 100644 --- a/manila/network/neutron/api.py +++ b/manila/network/neutron/api.py @@ -212,6 +212,9 @@ class API(object): def delete_port(self, port_id): try: self.client.delete_port(port_id) + except neutron_client_exc.PortNotFoundClient: + LOG.warning('Neutron port not found: %s', port_id) + pass except neutron_client_exc.NeutronClientException as e: raise exception.NetworkException(code=e.status_code, message=e.message) diff --git a/manila/tests/network/neutron/test_neutron_api.py b/manila/tests/network/neutron/test_neutron_api.py index 11affea9ef..6b6dd339bf 100644 --- a/manila/tests/network/neutron/test_neutron_api.py +++ b/manila/tests/network/neutron/test_neutron_api.py @@ -288,6 +288,35 @@ class NeutronApiTest(test.TestCase): self.neutron_api.client.delete_port.assert_called_once_with(port_id) self.assertTrue(clientv20.Client.called) + def test_delete_port_NeutronClientException(self): + # Set up test data + self.mock_object( + self.neutron_api.client, 'delete_port', + mock.Mock(side_effect=neutron_client_exc.NeutronClientException())) + port_id = 'test port id' + + self.assertRaises(exception.NetworkException, + self.neutron_api.delete_port, + port_id) + + # Verify results + self.neutron_api.client.delete_port.assert_called_once_with(port_id) + self.assertTrue(clientv20.Client.called) + + def test_delete_port_PortNotFoundClient(self): + # Set up test data + self.mock_object( + self.neutron_api.client, 'delete_port', + mock.Mock(side_effect=neutron_client_exc.PortNotFoundClient())) + port_id = 'test port id' + + # Execute method 'delete_port' + self.neutron_api.delete_port(port_id) + + # Verify results + self.neutron_api.client.delete_port.assert_called_once_with(port_id) + self.assertTrue(clientv20.Client.called) + def test_list_ports(self): # Set up test data search_opts = {'test_option': 'test_value'} diff --git a/releasenotes/notes/bug-2098083-Pass-on-port-delete-not-found-error-5acafa7a7810a210.yaml b/releasenotes/notes/bug-2098083-Pass-on-port-delete-not-found-error-5acafa7a7810a210.yaml new file mode 100644 index 0000000000..6eab78f64d --- /dev/null +++ b/releasenotes/notes/bug-2098083-Pass-on-port-delete-not-found-error-5acafa7a7810a210.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Manila will no longer fail while attempting to delete a neutron port that + already has been deleted. Instead, a log warning will be created. + For more details, please check + `Launchpad bug #2098083 `_