Skip to content

Commit

Permalink
l3.py,add_floating_ip: setup NAT before binding
Browse files Browse the repository at this point in the history
fix for bug 1100435

Change-Id: Iad022f61297fe26edb230ba7b9e31d73df99b5a5
  • Loading branch information
bao-mingyan committed Feb 8, 2013
1 parent 36fffe9 commit 12c73ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nova/network/l3.py
Expand Up @@ -101,9 +101,9 @@ def remove_gateway(self, network_ref):

def add_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,
network=None):
linux_net.bind_floating_ip(floating_ip, l3_interface_id)
linux_net.ensure_floating_forward(floating_ip, fixed_ip,
l3_interface_id, network)
linux_net.bind_floating_ip(floating_ip, l3_interface_id)

def remove_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,
network=None):
Expand Down
38 changes: 37 additions & 1 deletion nova/tests/network/test_manager.py
Expand Up @@ -726,7 +726,7 @@ def fake9(*args, **kwargs):
'floating_ip_fixed_ip_associate',
fake1)
self.stubs.Set(self.network.db, 'floating_ip_disassociate', fake1)
self.stubs.Set(self.network.driver, 'bind_floating_ip', fake8)
self.stubs.Set(self.network.driver, 'ensure_floating_forward', fake8)
self.assertRaises(exception.NoFloatingIpInterface,
self.network._associate_floating_ip,
ctxt,
Expand Down Expand Up @@ -776,6 +776,42 @@ def fake_fixed_ip_get(context, fixed_ip_id):
mox.IgnoreArg())
self.assertTrue(self.local)

def test_add_floating_ip_nat_before_bind(self):
# Tried to verify order with documented mox record/verify
# functionality, but it doesn't seem to work since I can't make it
# fail. I'm using stubs and a flag for now, but if this mox feature
# can be made to work, it would be a better way to test this.
#
# self.mox.StubOutWithMock(self.network.driver,
# 'ensure_floating_forward')
# self.mox.StubOutWithMock(self.network.driver, 'bind_floating_ip')
#
# self.network.driver.ensure_floating_forward(mox.IgnoreArg(),
# mox.IgnoreArg(),
# mox.IgnoreArg(),
# mox.IgnoreArg())
# self.network.driver.bind_floating_ip(mox.IgnoreArg(),
# mox.IgnoreArg())
# self.mox.ReplayAll()

nat_called = [False]

def fake_nat(*args, **kwargs):
nat_called[0] = True

def fake_bind(*args, **kwargs):
self.assertTrue(nat_called[0])

self.stubs.Set(self.network.driver,
'ensure_floating_forward',
fake_nat)
self.stubs.Set(self.network.driver, 'bind_floating_ip', fake_bind)

self.network.l3driver.add_floating_ip('fakefloat',
'fakefixed',
'fakeiface',
'fakenet')

def test_floating_ip_init_host(self):

def get_all_by_host(_context, _host):
Expand Down

0 comments on commit 12c73ee

Please sign in to comment.