From 7b61adbb4a0e3147e08e511cdf40a4073c00d099 Mon Sep 17 00:00:00 2001 From: yatinkarel Date: Thu, 16 Dec 2021 11:38:20 +0530 Subject: [PATCH] List ports when attempt to delete network with ports When there is attempt to delete network with ports, a general error message is displayed that one or more ports are in use on the network. This patch proposes to also return the ports which are in use as part of the message. Also modify test_delete_network_if_port_exists unit test to check for port id and network id in Error message. Also bump required version of neutron-lib to 2.18.0 as that's needed for custom message in NetworkInUse Exception. Depends-On: https://review.opendev.org/c/openstack/neutron-lib/+/821806 Closes-Bug: #1953716 Change-Id: Ib0b40402746c6a487a226b238907142384608d3c --- lower-constraints.txt | 2 +- neutron/db/db_base_plugin_v2.py | 5 ++++- neutron/tests/unit/db/test_db_base_plugin_v2.py | 4 ++++ requirements.txt | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index e5c956ba357..a4889e8d6a1 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -50,7 +50,7 @@ msgpack-python==0.4.0 munch==2.1.0 netaddr==0.7.18 netifaces==0.10.4 -neutron-lib==2.17.0 +neutron-lib==2.18.0 openstacksdk==0.31.2 os-client-config==1.28.0 os-ken==2.2.0 diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index ad20e871794..ff073014267 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -476,7 +476,10 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, ~models_v2.Port.device_owner.in_( _constants.AUTO_DELETE_PORT_OWNERS)) if non_auto_ports.count(): - raise exc.NetworkInUse(net_id=net_id) + ports = [port.id for port in non_auto_ports.all()] + reason = _("There are one or more ports still in use on the " + "network, id for these ports is: %s" % ",".join(ports)) + raise exc.NetworkInUse(net_id=net_id, reason=reason) @db_api.retry_if_session_inactive() def delete_network(self, context, id): diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index 98995006011..db67ce95df1 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -1621,6 +1621,10 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s port['port']['network_id']) res = req.get_response(self.api) self.assertEqual(webob.exc.HTTPConflict.code, res.status_int) + self.assertIn(port['port']['network_id'], + res.json["NeutronError"]["message"]) + self.assertIn(port['port']['id'], + res.json["NeutronError"]["message"]) def _test_delete_network_port_exists_owned_by_network(self, device_owner): res = self._create_network(fmt=self.fmt, name='net', diff --git a/requirements.txt b/requirements.txt index 79eee84f8cb..9b9551740ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,7 +16,7 @@ Jinja2>=2.10 # BSD License (3 clause) keystonemiddleware>=5.1.0 # Apache-2.0 netaddr>=0.7.18 # BSD netifaces>=0.10.4 # MIT -neutron-lib>=2.17.0 # Apache-2.0 +neutron-lib>=2.18.0 # Apache-2.0 python-neutronclient>=6.7.0 # Apache-2.0 tenacity>=6.0.0 # Apache-2.0 SQLAlchemy>=1.4.23 # MIT