Merge "Make floating_ips module use FloatingIP for associations"

This commit is contained in:
Jenkins 2014-02-22 06:12:17 +00:00 committed by Gerrit Code Review
commit 1135ed5a40
2 changed files with 20 additions and 16 deletions

View File

@ -356,10 +356,11 @@ class FloatingIP(object):
@utils.synchronized(unicode(floating_address))
def do_associate():
# associate floating ip
fixed = self.db.floating_ip_fixed_ip_associate(context,
floating_address,
fixed_address,
self.host)
floating = floating_ip_obj.FloatingIP.associate(context,
floating_address,
fixed_address,
self.host)
fixed = floating.fixed_ip
if not fixed:
# NOTE(vish): ip was already associated
return
@ -370,8 +371,8 @@ class FloatingIP(object):
except processutils.ProcessExecutionError as e:
with excutils.save_and_reraise_exception() as exc_ctxt:
try:
self.db.floating_ip_disassociate(context,
floating_address)
floating_ip_obj.FloatingIP.disassociate(
context, floating_address)
except Exception:
LOG.warn(_('Failed to disassociated floating '
'address: %s'), floating_address)
@ -461,15 +462,16 @@ class FloatingIP(object):
# don't worry about this case because the minuscule
# window where the ip is on both hosts shouldn't cause
# any problems.
fixed = self.db.floating_ip_disassociate(context, address)
floating = floating_ip_obj.FloatingIP.disassociate(context,
address)
fixed = floating.fixed_ip
if not fixed:
# NOTE(vish): ip was already disassociated
return
if interface:
# go go driver time
self.l3driver.remove_floating_ip(address, fixed['address'],
interface, fixed['network'])
self.l3driver.remove_floating_ip(address, fixed.address,
interface, fixed.network)
payload = dict(project_id=context.project_id,
instance_id=instance_uuid,
floating_ip=address)

View File

@ -919,8 +919,9 @@ class VlanNetworkTestCase(test.TestCase):
is_admin=False)
def fake1(*args, **kwargs):
return dict(test_floating_ip.fake_floating_ip,
address='10.0.0.1', network='fakenet')
return dict(test_fixed_ip.fake_fixed_ip,
address='10.0.0.1',
network=test_network.fake_network)
# floating ip that's already associated
def fake2(*args, **kwargs):
@ -986,8 +987,8 @@ class VlanNetworkTestCase(test.TestCase):
self.assertRaises(exception.NoFloatingIpInterface,
self.network._associate_floating_ip,
ctxt,
mox.IgnoreArg(),
mox.IgnoreArg(),
'1.2.3.4',
'1.2.3.5',
mox.IgnoreArg(),
mox.IgnoreArg())
@ -2678,7 +2679,8 @@ class FloatingIPTestCase(test.TestCase):
def _test_associate_floating_ip_failure(self, stdout, expected_exception):
def _fake_catchall(*args, **kwargs):
return {'id': 'fake', 'network': 'fake'}
return dict(test_fixed_ip.fake_fixed_ip,
network=test_network.fake_network)
def _fake_add_floating_ip(*args, **kwargs):
raise processutils.ProcessExecutionError(stdout)
@ -2692,7 +2694,7 @@ class FloatingIPTestCase(test.TestCase):
self.assertRaises(expected_exception,
self.network._associate_floating_ip, self.context,
'', '', '', '')
'1.2.3.4', '1.2.3.5', '', '')
def test_associate_floating_ip_failure(self):
self._test_associate_floating_ip_failure(None,