diff --git a/neutron/services/portforwarding/drivers/ovn/driver.py b/neutron/services/portforwarding/drivers/ovn/driver.py index 83172ec8a79..042a04923c1 100644 --- a/neutron/services/portforwarding/drivers/ovn/driver.py +++ b/neutron/services/portforwarding/drivers/ovn/driver.py @@ -16,6 +16,7 @@ from ovsdbapp import constants as ovsdbapp_const from neutron_lib.callbacks import events from neutron_lib.callbacks import registry +from neutron_lib import constants as const from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import directory @@ -182,14 +183,23 @@ class OVNPortForwarding(object): for pf_payload in payload: self._handler.port_forwarding_created(ovn_txn, ovn_nb, pf_payload.current_pf) + self._l3_plugin.update_floatingip_status( + context, pf_payload.current_pf.floatingip_id, + const.FLOATINGIP_STATUS_ACTIVE) elif event_type == events.AFTER_UPDATE: for pf_payload in payload: self._handler.port_forwarding_updated(ovn_txn, ovn_nb, pf_payload.current_pf, pf_payload.original_pf) elif event_type == events.AFTER_DELETE: for pf_payload in payload: + pfs = _pf_plugin.get_floatingip_port_forwardings( + context, pf_payload.original_pf.floatingip_id) self._handler.port_forwarding_deleted(ovn_txn, ovn_nb, pf_payload.original_pf) + if not pfs: + self._l3_plugin.update_floatingip_status( + context, pf_payload.original_pf.floatingip_id, + const.FLOATINGIP_STATUS_DOWN) # Collect the revision numbers of all floating ips visited and # update the corresponding load balancer entries affected. diff --git a/neutron/tests/unit/services/portforwarding/drivers/ovn/test_driver.py b/neutron/tests/unit/services/portforwarding/drivers/ovn/test_driver.py index e57895e48fa..7fd7ea8ebeb 100644 --- a/neutron/tests/unit/services/portforwarding/drivers/ovn/test_driver.py +++ b/neutron/tests/unit/services/portforwarding/drivers/ovn/test_driver.py @@ -23,6 +23,7 @@ from neutron.tests import base from neutron.tests.unit import fake_resources from neutron_lib.callbacks import events from neutron_lib.callbacks import registry +from neutron_lib import constants as const from neutron_lib.plugins import constants as plugin_constants from oslo_utils import uuidutils from ovsdbapp import constants as ovsdbapp_const @@ -238,7 +239,8 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase): fip_objs = {} with mock.patch.object(self._ovn_pf, '_get_fip_objs', return_value=fip_objs) as mock_get_fip_objs: - self._ovn_pf._handle_notification(None, event_type, None, payload) + self._ovn_pf._handle_notification(None, event_type, + self.pf_plugin, payload) self.assertTrue(self.fake_db_rev.called or not fip_objs) if not payload: return @@ -273,6 +275,10 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase): calls = [mock.call(mock.ANY, self.l3_plugin._ovn, entry.current_pf) for entry in fake_payload] self.handler.port_forwarding_created.assert_has_calls(calls) + update_calls = [mock.call( + self.context, entry.current_pf.floatingip_id, + const.FLOATINGIP_STATUS_ACTIVE) for entry in fake_payload] + self.l3_plugin.update_floatingip_status.assert_has_calls(update_calls) def test_handle_notification_update(self): fip_objs = {100: {'description': 'hundred'}, 101: {}} @@ -289,11 +295,20 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase): 2: {'description': 'two', 'revision_number': '222'}} fake_payload = [self._fake_pf_payload_entry(None, id) for id in range(1, 4)] - self._handle_notification_common(events.AFTER_DELETE, fake_payload, - fip_objs) - calls = [mock.call(mock.ANY, self.l3_plugin._ovn, entry.original_pf) - for entry in fake_payload] - self.handler.port_forwarding_deleted.assert_has_calls(calls) + with mock.patch.object( + self.pf_plugin, 'get_floatingip_port_forwardings', + return_value=[]): + self._handle_notification_common( + events.AFTER_DELETE, fake_payload, fip_objs) + calls = [mock.call( + mock.ANY, self.l3_plugin._ovn, entry.original_pf) + for entry in fake_payload] + self.handler.port_forwarding_deleted.assert_has_calls(calls) + update_calls = [mock.call( + self.context, entry.original_pf.floatingip_id, + const.FLOATINGIP_STATUS_DOWN) for entry in fake_payload] + self.l3_plugin.update_floatingip_status.assert_has_calls( + update_calls) def test_maintenance_create_or_update(self): pf_objs = [self._fake_pf_obj()]