Browse Source

Fix incorrect exception catch when update floating ip port forwarding

Closes-Bug: #1912596
Change-Id: Ib1a95dd41d25f39f3378a6728d752a6589b9b61c
(cherry picked from commit e9e4395d57)
changes/85/774585/2
yangjianfeng 4 months ago
parent
commit
3e06f40e3d
2 changed files with 58 additions and 1 deletions
  1. +2
    -1
      neutron/services/portforwarding/pf_plugin.py
  2. +56
    -0
      neutron/tests/unit/extensions/test_floating_ip_port_forwarding.py

+ 2
- 1
neutron/services/portforwarding/pf_plugin.py View File

@ -30,6 +30,7 @@ from neutron_lib.exceptions import l3 as lib_l3_exc
from neutron_lib.objects import exceptions as obj_exc
from neutron_lib.plugins import constants
from neutron_lib.plugins import directory
from oslo_db import exception as oslo_db_exc
from oslo_log import log as logging
from neutron._i18n import _
@ -386,7 +387,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
pf_obj.update_fields(port_forwarding, reset_changes=True)
self._check_port_forwarding_update(context, pf_obj)
pf_obj.update()
except obj_exc.NeutronDbObjectDuplicateEntry:
except oslo_db_exc.DBDuplicateEntry:
(__, conflict_params) = self._find_existing_port_forwarding(
context, floatingip_id, pf_obj.to_dict())
message = _("A duplicate port forwarding entry with same "


+ 56
- 0
neutron/tests/unit/extensions/test_floating_ip_port_forwarding.py View File

@ -66,6 +66,21 @@ class FloatingIPPorForwardingTestCase(test_l3.L3BaseForIntTests,
return fip_pf_req.get_response(self.ext_api)
def _update_fip_port_forwarding(self, fmt, floating_ip_id,
port_forwarding_id, **kwargs):
port_forwarding = {}
for k, v in kwargs.items():
port_forwarding[k] = v
data = {'port_forwarding': port_forwarding}
fip_pf_req = self._req(
'PUT', 'floatingips', data,
fmt or self.fmt, id=floating_ip_id,
sub_id=port_forwarding_id,
subresource='port_forwardings')
return fip_pf_req.get_response(self.ext_api)
def test_create_floatingip_port_forwarding_with_port_number_0(self):
with self.network() as ext_net:
network_id = ext_net['network']['id']
@ -100,3 +115,44 @@ class FloatingIPPorForwardingTestCase(test_l3.L3BaseForIntTests,
port['port']['fixed_ips'][0]['ip_address'],
port['port']['id'])
self.assertEqual(exc.HTTPBadRequest.code, res.status_int)
def test_update_floatingip_port_forwarding_with_dup_internal_port(self):
with self.network() as ext_net:
network_id = ext_net['network']['id']
self._set_net_external(network_id)
with self.subnet(ext_net, cidr='10.10.10.0/24'), \
self.router() as router, \
self.subnet(cidr='11.0.0.0/24') as private_subnet, \
self.port(private_subnet) as port:
self._add_external_gateway_to_router(
router['router']['id'],
network_id)
self._router_interface_action(
'add', router['router']['id'],
private_subnet['subnet']['id'],
None)
fip1 = self._make_floatingip(
self.fmt,
network_id)
self.assertIsNone(fip1['floatingip'].get('port_id'))
self._create_fip_port_forwarding(
self.fmt, fip1['floatingip']['id'],
2222, 22,
'tcp',
port['port']['fixed_ips'][0]['ip_address'],
port['port']['id'])
fip2 = self._make_floatingip(
self.fmt,
network_id)
fip_pf_response = self._create_fip_port_forwarding(
self.fmt, fip2['floatingip']['id'],
2222, 23,
'tcp',
port['port']['fixed_ips'][0]['ip_address'],
port['port']['id'])
update_res = self._update_fip_port_forwarding(
self.fmt, fip2['floatingip']['id'],
fip_pf_response.json['port_forwarding']['id'],
**{'internal_port': 22})
self.assertEqual(exc.HTTPBadRequest.code,
update_res.status_int)

Loading…
Cancel
Save