]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: properly handle floating ip status
authorSalvatore Orlando <salv.orlando@gmail.com>
Fri, 27 Jun 2014 18:50:00 +0000 (11:50 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 1 Jul 2014 13:19:29 +0000 (06:19 -0700)
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

neutron/plugins/vmware/plugins/base.py
neutron/plugins/vmware/plugins/service.py
neutron/tests/unit/vmware/test_nsx_plugin.py
neutron/tests/unit/vmware/vshield/test_edge_router.py

index 384964c8fb55dfa0918507cf2f51789abc91897a..ebfeebdd92e9143aa8374e21430471755fc644c3 100644 (file)
@@ -1892,6 +1892,14 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
                 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.
 
@@ -1984,10 +1992,12 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
                                    '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)
index f9d70321af10f8cbd0191a18fae5abfe00f8d3dc..9da8c7b11f83850849d7eb667252aa01e70bc673 100644 (file)
@@ -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
@@ -758,6 +759,10 @@ class NsxAdvancedPlugin(sr_db.ServiceRouter_mixin,
             # 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):
index 4b99bd734e4db2c317351d9e636a56fc21161ab3..78b713cb7e10419151228fecb5143b3234dc4c50 100644 (file)
@@ -947,6 +947,13 @@ class TestL3NatTestCase(L3NatTest,
             # 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':
@@ -956,12 +963,18 @@ class TestL3NatTestCase(L3NatTest,
                 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:
index c43e9b34ba21b90df15adc95579d17a6f6fd8278..4daddf70b32f3c76ae9ac8098faec7017225a187 100644 (file)
@@ -20,6 +20,7 @@ import mock
 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
@@ -232,6 +233,9 @@ class ServiceRouterTestCase(ServiceRouterTest,
               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):