From c0c5dc70593e208dc34124052464c5bddfb3f983 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Thu, 11 Feb 2016 13:53:07 -0800 Subject: [PATCH] NSX|V3: Fix floating IP status When a floating IP is not associated with any port, its status should be DOWN. Change-Id: Ide70916abfd1703fd102f32445d065688c4d38cf Fixes-Bug: #1544320 --- vmware_nsx/plugins/nsx_v3/plugin.py | 17 ++++++++++++++--- vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 9db0a17167..a88dd8ea3b 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -1435,7 +1435,10 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, def create_floatingip(self, context, floatingip): new_fip = super(NsxV3Plugin, self).create_floatingip( - context, floatingip) + context, floatingip, initial_status=( + const.FLOATINGIP_STATUS_ACTIVE + if floatingip['floatingip']['port_id'] + else const.FLOATINGIP_STATUS_DOWN)) router_id = new_fip['router_id'] if not router_id: return new_fip @@ -1472,6 +1475,9 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, def update_floatingip(self, context, fip_id, floatingip): old_fip = self.get_floatingip(context, fip_id) old_port_id = old_fip['port_id'] + new_status = (const.FLOATINGIP_STATUS_ACTIVE + if floatingip['floatingip']['port_id'] + else const.FLOATINGIP_STATUS_DOWN) new_fip = super(NsxV3Plugin, self).update_floatingip( context, fip_id, floatingip) router_id = new_fip['router_id'] @@ -1508,8 +1514,11 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, with excutils.save_and_reraise_exception(): super(NsxV3Plugin, self).update_floatingip( context, fip_id, {'floatingip': {'port_id': old_port_id}}) - self._set_floatingip_status( - context, const.FLOATINGIP_STATUS_ERROR) + self.update_floatingip_status(context, fip_id, + const.FLOATINGIP_STATUS_ERROR) + if new_fip['status'] != new_status: + new_fip['status'] = new_status + self.update_floatingip_status(context, fip_id, new_status) return new_fip def disassociate_floatingips(self, context, port_id): @@ -1532,6 +1541,8 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin, {'fip_id': fip_db.id, 'ext_ip': fip_db.floating_ip_address, 'int_ip': fip_db.fixed_ip_address}) + self.update_floatingip_status(context, fip_db.id, + const.FLOATINGIP_STATUS_DOWN) super(NsxV3Plugin, self).disassociate_floatingips( context, port_id, do_notify=False) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index d42434d27e..5165d350be 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -318,6 +318,10 @@ class TestL3NatTestCase(L3NatTest, def test_create_l3_ext_network_with_default_tier0(self): self._test_create_l3_ext_network() + def test_floatingip_update(self): + super(TestL3NatTestCase, self).test_floatingip_update( + expected_status=constants.FLOATINGIP_STATUS_DOWN) + def test_floatingip_with_invalid_create_port(self): self._test_floatingip_with_invalid_create_port(self._plugin_name)