NSX: Avoid floating IP status reset

The method for setting the floating IP status in the NSX plugin
has a flaw that causes in some cases the status to be reset.
This patch removes this bug and also protects against regression
adding status check in the unit test covering floating ip
creation.

This patch also moves the above mentioned unit test in a more
suitable place in the test same module.

Change-Id: Ib08c421ade20ce23b5c08145203a2df6a8f3efa5
Closes-Bug: #1357514
This commit is contained in:
Salvatore Orlando 2014-08-15 04:20:26 -07:00
parent f9981d0495
commit 58744ee4db
2 changed files with 14 additions and 10 deletions

View File

@ -1837,6 +1837,8 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
elif (not associated and
floatingip_db['status'] != constants.FLOATINGIP_STATUS_DOWN):
return constants.FLOATINGIP_STATUS_DOWN
# in any case ensure the status is not reset by this method!
return floatingip_db['status']
def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
"""Update floating IP association data.

View File

@ -1335,6 +1335,18 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
self._test_floatingip_with_assoc_fails(
'neutron.db.l3_db.L3_NAT_db_mixin._check_and_get_fip_assoc')
def test_create_floatingip_with_assoc(
self, expected_status=l3_constants.FLOATINGIP_STATUS_ACTIVE):
with self.floatingip_with_assoc() as fip:
body = self._show('floatingips', fip['floatingip']['id'])
self.assertEqual(body['floatingip']['id'],
fip['floatingip']['id'])
self.assertEqual(body['floatingip']['port_id'],
fip['floatingip']['port_id'])
self.assertEqual(expected_status, body['floatingip']['status'])
self.assertIsNotNone(body['floatingip']['fixed_ip_address'])
self.assertIsNotNone(body['floatingip']['router_id'])
def test_floatingip_update(
self, expected_status=l3_constants.FLOATINGIP_STATUS_ACTIVE):
with self.port() as p:
@ -1508,16 +1520,6 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
fip2_r2_res = associate_and_assert(fip2, p2)
self.assertEqual(fip2_r2_res, r2['router']['id'])
def test_floatingip_with_assoc(self):
with self.floatingip_with_assoc() as fip:
body = self._show('floatingips', fip['floatingip']['id'])
self.assertEqual(body['floatingip']['id'],
fip['floatingip']['id'])
self.assertEqual(body['floatingip']['port_id'],
fip['floatingip']['port_id'])
self.assertIsNotNone(body['floatingip']['fixed_ip_address'])
self.assertIsNotNone(body['floatingip']['router_id'])
def test_floatingip_port_delete(self):
with self.subnet() as private_sub:
with self.floatingip_no_assoc(private_sub) as fip: