Merge "port_forwarding: validate args before invoking db update (cont.)"
This commit is contained in:
commit
cbddc79c4e
@ -471,7 +471,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
|
|||||||
msg=message)
|
msg=message)
|
||||||
|
|
||||||
def _check_port_forwarding_update(self, context, pf_obj):
|
def _check_port_forwarding_update(self, context, pf_obj):
|
||||||
def _check_port_forwarding_update_failed(conflict):
|
def _raise_port_forwarding_update_failed(conflict):
|
||||||
message = _("Another port forwarding entry with the same "
|
message = _("Another port forwarding entry with the same "
|
||||||
"attributes already exists, conflicting "
|
"attributes already exists, conflicting "
|
||||||
"values are %s") % conflict
|
"values are %s") % conflict
|
||||||
@ -499,7 +499,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
|
|||||||
# Ensure there are no conflicts on the outside
|
# Ensure there are no conflicts on the outside
|
||||||
if (obj.floating_ip_address == pf_obj.floating_ip_address and
|
if (obj.floating_ip_address == pf_obj.floating_ip_address and
|
||||||
obj.external_port == pf_obj.external_port):
|
obj.external_port == pf_obj.external_port):
|
||||||
_check_port_forwarding_update_failed(
|
_raise_port_forwarding_update_failed(
|
||||||
{'floating_ip_address': str(obj.floating_ip_address),
|
{'floating_ip_address': str(obj.floating_ip_address),
|
||||||
'external_port': obj.external_port})
|
'external_port': obj.external_port})
|
||||||
# Ensure there are no conflicts in the inside
|
# Ensure there are no conflicts in the inside
|
||||||
@ -507,7 +507,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
|
|||||||
if (obj.internal_port_id == pf_obj.internal_port_id and
|
if (obj.internal_port_id == pf_obj.internal_port_id and
|
||||||
obj.internal_ip_address == pf_obj.internal_ip_address and
|
obj.internal_ip_address == pf_obj.internal_ip_address and
|
||||||
obj.internal_port == pf_obj.internal_port):
|
obj.internal_port == pf_obj.internal_port):
|
||||||
_check_port_forwarding_update_failed(
|
_raise_port_forwarding_update_failed(
|
||||||
{'internal_port_id': obj.internal_port_id,
|
{'internal_port_id': obj.internal_port_id,
|
||||||
'internal_ip_address': str(obj.internal_ip_address),
|
'internal_ip_address': str(obj.internal_ip_address),
|
||||||
'internal_port': obj.internal_port})
|
'internal_port': obj.internal_port})
|
||||||
|
@ -246,7 +246,7 @@ class TestPortForwardingPlugin(testlib_api.SqlTestCase):
|
|||||||
mock_pf_get_objects.return_value = [pf_obj, other_pf_obj]
|
mock_pf_get_objects.return_value = [pf_obj, other_pf_obj]
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
lib_exc.BadRequest,
|
lib_exc.BadRequest,
|
||||||
"already exist.*same_fip_addr.*same_ext_port",
|
"already exist.*same_fip_addr",
|
||||||
self.pf_plugin._check_port_forwarding_update,
|
self.pf_plugin._check_port_forwarding_update,
|
||||||
self.ctxt, pf_obj)
|
self.ctxt, pf_obj)
|
||||||
mock_get_port.assert_called_once_with(self.ctxt, mock.ANY)
|
mock_get_port.assert_called_once_with(self.ctxt, mock.ANY)
|
||||||
@ -269,8 +269,7 @@ class TestPortForwardingPlugin(testlib_api.SqlTestCase):
|
|||||||
mock_pf_get_objects.return_value = [pf_obj, other_pf_obj]
|
mock_pf_get_objects.return_value = [pf_obj, other_pf_obj]
|
||||||
self.assertRaisesRegex(
|
self.assertRaisesRegex(
|
||||||
lib_exc.BadRequest,
|
lib_exc.BadRequest,
|
||||||
"already exist.*same_int_port_id.*{}.*same_int_port".format(
|
"already exist.*{}".format(same_internal_ip),
|
||||||
same_internal_ip),
|
|
||||||
self.pf_plugin._check_port_forwarding_update,
|
self.pf_plugin._check_port_forwarding_update,
|
||||||
self.ctxt, pf_obj)
|
self.ctxt, pf_obj)
|
||||||
mock_get_port.assert_called_once_with(self.ctxt, 'same_int_port_id')
|
mock_get_port.assert_called_once_with(self.ctxt, 'same_int_port_id')
|
||||||
|
Loading…
Reference in New Issue
Block a user