create or delete port forwarding, update the floating ip status
create port forwarding, should set floating ip status running, delete all port forwarding, the floating ip status should be down. Closes-Bug: #1910334 Change-Id: I8b3e4bf6b3cac3a95ea76b85dd4882ddafc962c8
This commit is contained in:
parent
b2389a31a0
commit
a37dc71ad6
@ -16,6 +16,7 @@ from ovsdbapp import constants as ovsdbapp_const
|
|||||||
|
|
||||||
from neutron_lib.callbacks import events
|
from neutron_lib.callbacks import events
|
||||||
from neutron_lib.callbacks import registry
|
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 constants as plugin_constants
|
||||||
from neutron_lib.plugins import directory
|
from neutron_lib.plugins import directory
|
||||||
|
|
||||||
@ -182,14 +183,23 @@ class OVNPortForwarding(object):
|
|||||||
for pf_payload in payload:
|
for pf_payload in payload:
|
||||||
self._handler.port_forwarding_created(ovn_txn, ovn_nb,
|
self._handler.port_forwarding_created(ovn_txn, ovn_nb,
|
||||||
pf_payload.current_pf)
|
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:
|
elif event_type == events.AFTER_UPDATE:
|
||||||
for pf_payload in payload:
|
for pf_payload in payload:
|
||||||
self._handler.port_forwarding_updated(ovn_txn, ovn_nb,
|
self._handler.port_forwarding_updated(ovn_txn, ovn_nb,
|
||||||
pf_payload.current_pf, pf_payload.original_pf)
|
pf_payload.current_pf, pf_payload.original_pf)
|
||||||
elif event_type == events.AFTER_DELETE:
|
elif event_type == events.AFTER_DELETE:
|
||||||
for pf_payload in payload:
|
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,
|
self._handler.port_forwarding_deleted(ovn_txn, ovn_nb,
|
||||||
pf_payload.original_pf)
|
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
|
# Collect the revision numbers of all floating ips visited and
|
||||||
# update the corresponding load balancer entries affected.
|
# update the corresponding load balancer entries affected.
|
||||||
|
@ -23,6 +23,7 @@ from neutron.tests import base
|
|||||||
from neutron.tests.unit import fake_resources
|
from neutron.tests.unit import fake_resources
|
||||||
from neutron_lib.callbacks import events
|
from neutron_lib.callbacks import events
|
||||||
from neutron_lib.callbacks import registry
|
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 constants as plugin_constants
|
||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
from ovsdbapp import constants as ovsdbapp_const
|
from ovsdbapp import constants as ovsdbapp_const
|
||||||
@ -238,7 +239,8 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase):
|
|||||||
fip_objs = {}
|
fip_objs = {}
|
||||||
with mock.patch.object(self._ovn_pf, '_get_fip_objs',
|
with mock.patch.object(self._ovn_pf, '_get_fip_objs',
|
||||||
return_value=fip_objs) as mock_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)
|
self.assertTrue(self.fake_db_rev.called or not fip_objs)
|
||||||
if not payload:
|
if not payload:
|
||||||
return
|
return
|
||||||
@ -273,6 +275,10 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase):
|
|||||||
calls = [mock.call(mock.ANY, self.l3_plugin._ovn, entry.current_pf)
|
calls = [mock.call(mock.ANY, self.l3_plugin._ovn, entry.current_pf)
|
||||||
for entry in fake_payload]
|
for entry in fake_payload]
|
||||||
self.handler.port_forwarding_created.assert_has_calls(calls)
|
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):
|
def test_handle_notification_update(self):
|
||||||
fip_objs = {100: {'description': 'hundred'}, 101: {}}
|
fip_objs = {100: {'description': 'hundred'}, 101: {}}
|
||||||
@ -289,11 +295,20 @@ class TestOVNPortForwarding(TestOVNPortForwardingBase):
|
|||||||
2: {'description': 'two', 'revision_number': '222'}}
|
2: {'description': 'two', 'revision_number': '222'}}
|
||||||
fake_payload = [self._fake_pf_payload_entry(None, id)
|
fake_payload = [self._fake_pf_payload_entry(None, id)
|
||||||
for id in range(1, 4)]
|
for id in range(1, 4)]
|
||||||
self._handle_notification_common(events.AFTER_DELETE, fake_payload,
|
with mock.patch.object(
|
||||||
fip_objs)
|
self.pf_plugin, 'get_floatingip_port_forwardings',
|
||||||
calls = [mock.call(mock.ANY, self.l3_plugin._ovn, entry.original_pf)
|
return_value=[]):
|
||||||
for entry in fake_payload]
|
self._handle_notification_common(
|
||||||
self.handler.port_forwarding_deleted.assert_has_calls(calls)
|
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):
|
def test_maintenance_create_or_update(self):
|
||||||
pf_objs = [self._fake_pf_obj()]
|
pf_objs = [self._fake_pf_obj()]
|
||||||
|
Loading…
Reference in New Issue
Block a user