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
This commit is contained in:
yatinkarel 2021-12-16 11:38:20 +05:30
parent c788f09f1b
commit 7b61adbb4a
4 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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):

View File

@ -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',

View File

@ -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