summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryatinkarel <ykarel@redhat.com>2021-12-16 11:38:20 +0530
committeryatinkarel <ykarel@redhat.com>2021-12-16 16:31:44 +0530
commit7b61adbb4a0e3147e08e511cdf40a4073c00d099 (patch)
tree1de6d83b42be7283b6a6cbe817647167226c1a49
parentc788f09f1bf6e448c19fd71e39da7707845ca36c (diff)
downloadneutron-7b61adbb4a0e3147e08e511cdf40a4073c00d099.tar.gz
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
-rw-r--r--lower-constraints.txt2
-rw-r--r--neutron/db/db_base_plugin_v2.py5
-rw-r--r--neutron/tests/unit/db/test_db_base_plugin_v2.py4
-rw-r--r--requirements.txt2
4 files changed, 10 insertions, 3 deletions
diff --git a/lower-constraints.txt b/lower-constraints.txt
index e5c956ba35..a4889e8d6a 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 ad20e87179..ff07301426 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 9899500601..db67ce95df 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 79eee84f8c..9b9551740a 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