Make floating_ips module use FloatingIP for associations
This makes the network.floating_ips module use the FloatingIP object for association operations instead of direct database access. Related to blueprint nova-network-objects Change-Id: I71db51e2ad3a79665140ef21b5960c1ff9ff3a05
This commit is contained in:
parent
e0f0f14fb6
commit
2bcf240399
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user