summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2012-03-31 14:48:30 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2012-03-31 18:27:52 -0700
commit73fe1a6fa38fb85e66ab04f091fe623fc67e0b0b (patch)
treeac05fe2533331d580c0a02cbab1a370086d7232f
parentaf4abf1583fc5a91eb714f06ab8dd26fa036043a (diff)
downloadnova-73fe1a6fa38fb85e66ab04f091fe623fc67e0b0b.tar.gz
Ensure floating ips are recreated on reboot
* includes failing test * fixes bug 970041 Change-Id: Ifee5b95b86278dcf2320460cf700293fd3a21153
-rw-r--r--nova/network/manager.py12
-rw-r--r--nova/tests/network/test_manager.py27
2 files changed, 37 insertions, 2 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 8e18ba28eb..b0b84af9b5 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -282,8 +282,16 @@ class FloatingIP(object):
return
for floating_ip in floating_ips:
- if floating_ip.get('fixed_ip', None):
- fixed_address = floating_ip['fixed_ip']['address']
+ fixed_ip_id = floating_ip.get('fixed_ip_id')
+ if fixed_ip_id:
+ try:
+ fixed_ip_ref = self.db.fixed_ip_get(admin_context,
+ fixed_ip_id)
+ except exception.FixedIpNotFound:
+ msg = _('Fixed ip %(fixed_ip_id)s not found') % locals()
+ LOG.debug(msg)
+ continue
+ fixed_address = fixed_ip_ref['address']
interface = floating_ip['interface']
try:
self.l3driver.add_floating_ip(floating_ip['address'],
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index e8da5b3f81..6720be5843 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -692,6 +692,33 @@ class VlanNetworkTestCase(test.TestCase):
mox.IgnoreArg())
self.assertTrue(self.local)
+ def test_floating_ip_init_host(self):
+
+ def get_all_by_host(_context, _host):
+ return [{'interface': 'foo',
+ 'address': 'foo'},
+ {'interface': 'fakeiface',
+ 'address': 'fakefloat',
+ 'fixed_ip_id': 1},
+ {'interface': 'bar',
+ 'address': 'bar',
+ 'fixed_ip_id': 2}]
+ self.stubs.Set(self.network.db, 'floating_ip_get_all_by_host',
+ get_all_by_host)
+
+ def fixed_ip_get(_context, fixed_ip_id):
+ if fixed_ip_id == 1:
+ return {'address': 'fakefixed'}
+ raise exception.FixedIpNotFound()
+ self.stubs.Set(self.network.db, 'fixed_ip_get', fixed_ip_get)
+
+ self.mox.StubOutWithMock(self.network.l3driver, 'add_floating_ip')
+ self.network.l3driver.add_floating_ip('fakefloat',
+ 'fakefixed',
+ 'fakeiface')
+ self.mox.ReplayAll()
+ self.network.init_host_floating_ips()
+
def test_disassociate_floating_ip(self):
ctxt = context.RequestContext('testuser', 'testproject',
is_admin=False)