Skip to content

Commit

Permalink
NSX: properly handle floating ip status
Browse files Browse the repository at this point in the history
Ensure the floating IP status is put ACTIVE or DOWN when it
is associated or disassociated.
This is done directly on the plugin class as the NSX backend
applies relevant NAT rules synchronously.

Change-Id: Ie747c4eae2ac33016fdabaade2335f7d2d24eec9
Closes-Bug: #1334708
  • Loading branch information
salv-orlando committed Jul 1, 2014
1 parent 320b9bd commit 3709a1b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
18 changes: 14 additions & 4 deletions neutron/plugins/vmware/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,14 @@ def _get_fip_assoc_data(self, context, fip, floatingip_db):
pass
return (port_id, internal_ip, router_id)

def _floatingip_status(self, floatingip_db, associated):
if (associated and
floatingip_db['status'] != constants.FLOATINGIP_STATUS_ACTIVE):
return constants.FLOATINGIP_STATUS_ACTIVE
elif (not associated and
floatingip_db['status'] != constants.FLOATINGIP_STATUS_DOWN):
return constants.FLOATINGIP_STATUS_DOWN

def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
"""Update floating IP association data.
Expand Down Expand Up @@ -1984,10 +1992,12 @@ def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
'internal_ip': internal_ip})
msg = _("Failed to update NAT rules for floatingip update")
raise nsx_exc.NsxPluginException(err_msg=msg)

floatingip_db.update({'fixed_ip_address': internal_ip,
'fixed_port_id': port_id,
'router_id': router_id})
# Update also floating ip status (no need to call base class method)
floatingip_db.update(
{'fixed_ip_address': internal_ip,
'fixed_port_id': port_id,
'router_id': router_id,
'status': self._floatingip_status(floatingip_db, router_id)})

def delete_floatingip(self, context, id):
fip_db = self._get_floatingip(context, id)
Expand Down
5 changes: 5 additions & 0 deletions neutron/plugins/vmware/plugins/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import netaddr
from oslo.config import cfg

from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.db.firewall import firewall_db
from neutron.db import l3_db
Expand Down Expand Up @@ -758,6 +759,10 @@ def update_floatingip(self, context, id, floatingip):
# do sync work (rollback, re-configure, or make router down)
self._update_nat_rules(context, router)
self._update_interface(context, router)
elif not router_id:
# The floating IP has been disassociated and should be set to DOWN
self.update_floatingip_status(context, fip['id'],
constants.FLOATINGIP_STATUS_DOWN)
return fip

def delete_floatingip(self, context, id):
Expand Down
13 changes: 13 additions & 0 deletions neutron/tests/unit/vmware/test_nsx_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@ def test_metadata_dhcp_host_route(self):
# Test that route is deleted after dhcp port is removed
self.assertEqual(len(subnets[0]['host_routes']), 0)

def _test_floatingip_update(self, expected_status):
super(TestL3NatTestCase, self).test_floatingip_update(
expected_status)

def test_floatingip_update(self):
self._test_floatingip_update(constants.FLOATINGIP_STATUS_DOWN)

def test_floatingip_disassociate(self):
with self.port() as p:
private_sub = {'subnet': {'id':
Expand All @@ -956,12 +963,18 @@ def test_floatingip_disassociate(self):
body = self._update('floatingips', fip['floatingip']['id'],
{'floatingip': {'port_id': port_id}})
self.assertEqual(body['floatingip']['port_id'], port_id)
# Floating IP status should be active
self.assertEqual(constants.FLOATINGIP_STATUS_ACTIVE,
body['floatingip']['status'])
# Disassociate
body = self._update('floatingips', fip['floatingip']['id'],
{'floatingip': {'port_id': None}})
body = self._show('floatingips', fip['floatingip']['id'])
self.assertIsNone(body['floatingip']['port_id'])
self.assertIsNone(body['floatingip']['fixed_ip_address'])
# Floating IP status should be down
self.assertEqual(constants.FLOATINGIP_STATUS_DOWN,
body['floatingip']['status'])

def test_create_router_maintenance_returns_503(self):
with self._create_l3_ext_network() as net:
Expand Down
4 changes: 4 additions & 0 deletions neutron/tests/unit/vmware/vshield/test_edge_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from oslo.config import cfg

from neutron.api.v2 import attributes
from neutron.common import constants
from neutron import context
from neutron.extensions import l3
from neutron import manager as n_manager
Expand Down Expand Up @@ -232,6 +233,9 @@ def _test_router_update_gateway_on_l3_ext_net(self, vlan_id=None):
self)._test_router_update_gateway_on_l3_ext_net(
vlan_id, validate_ext_gw=False)

def test_floatingip_update(self):
self._test_floatingip_update(constants.FLOATINGIP_STATUS_ACTIVE)


class TestProxyCreateLswitch(base.BaseTestCase):
def setUp(self):
Expand Down

0 comments on commit 3709a1b

Please sign in to comment.