diff options
-rw-r--r-- | nova/network/manager.py | 7 | ||||
-rw-r--r-- | nova/network/rpcapi.py | 17 | ||||
-rw-r--r-- | nova/tests/network/test_manager.py | 111 | ||||
-rw-r--r-- | nova/tests/network/test_rpcapi.py | 5 |
4 files changed, 129 insertions, 11 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py index 0e8530d14..e38c6c7a3 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -575,7 +575,8 @@ class FloatingIP(object): else: # send to correct host self.network_rpcapi._associate_floating_ip(context, - floating_address, fixed_address, interface, host) + floating_address, fixed_address, interface, host, + fixed_ip['instance_uuid']) return orig_instance_uuid @@ -658,7 +659,7 @@ class FloatingIP(object): else: # send to correct host self.network_rpcapi._disassociate_floating_ip(context, address, - interface, host) + interface, host, fixed_ip['instance_uuid']) def _disassociate_floating_ip(self, context, address, interface, instance_uuid): @@ -900,7 +901,7 @@ class NetworkManager(manager.SchedulerDependentManager): The one at a time part is to flatten the layout to help scale """ - RPC_API_VERSION = '1.5' + RPC_API_VERSION = '1.6' # If True, this manager requires VIF to create a bridge. SHOULD_CREATE_BRIDGE = False diff --git a/nova/network/rpcapi.py b/nova/network/rpcapi.py index 8ee1ce443..4f8ebeb22 100644 --- a/nova/network/rpcapi.py +++ b/nova/network/rpcapi.py @@ -38,6 +38,7 @@ class NetworkAPI(rpc_proxy.RpcProxy): 1.3 - Adds fanout cast update_dns for multi_host networks 1.4 - Add get_backdoor_port() 1.5 - Adds associate + 1.6 - Adds instance_uuid to _{dis,}associate_floating_ip ''' # @@ -259,20 +260,24 @@ class NetworkAPI(rpc_proxy.RpcProxy): # 1.0 API was being documented using this client proxy class. It should be # changed if there was ever a 2.0. def _associate_floating_ip(self, ctxt, floating_address, fixed_address, - interface, host): + interface, host, instance_uuid=None): return self.call(ctxt, self.make_msg('_associate_floating_ip', floating_address=floating_address, fixed_address=fixed_address, - interface=interface), - topic=rpc.queue_get_for(ctxt, self.topic, host)) + interface=interface, instance_uuid=instance_uuid), + topic=rpc.queue_get_for(ctxt, self.topic, host), + version='1.6') # NOTE(russellb): Ideally this would not have a prefix of '_' since it is # a part of the rpc API. However, this is how it was being called when the # 1.0 API was being documented using this client proxy class. It should be # changed if there was ever a 2.0. - def _disassociate_floating_ip(self, ctxt, address, interface, host): + def _disassociate_floating_ip(self, ctxt, address, interface, host, + instance_uuid=None): return self.call(ctxt, self.make_msg('_disassociate_floating_ip', - address=address, interface=interface), - topic=rpc.queue_get_for(ctxt, self.topic, host)) + address=address, interface=interface, + instance_uuid=instance_uuid), + topic=rpc.queue_get_for(ctxt, self.topic, host), + version='1.6') def lease_fixed_ip(self, ctxt, address, host): self.cast(ctxt, self.make_msg('lease_fixed_ip', address=address), diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index e80ea3936..524cf17a3 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -689,6 +689,7 @@ class VlanNetworkTestCase(test.TestCase): def fake4(*args, **kwargs): return {'address': '10.0.0.1', 'pool': 'nova', + 'instance_uuid': FAKEUUID, 'interface': 'eth0', 'network_id': 'blah'} @@ -840,6 +841,7 @@ class VlanNetworkTestCase(test.TestCase): def fake4(*args, **kwargs): return {'address': '10.0.0.1', 'pool': 'nova', + 'instance_uuid': FAKEUUID, 'interface': 'eth0', 'network_id': 'blah'} @@ -1633,6 +1635,115 @@ class FloatingIPTestCase(test.TestCase): shutil.rmtree(self.tempdir) super(FloatingIPTestCase, self).tearDown() + def test_disassociate_floating_ip_multi_host_calls(self): + floating_ip = { + 'fixed_ip_id': 12 + } + + fixed_ip = { + 'network_id': None, + 'instance_uuid': 'instance-uuid' + } + + network = { + 'multi_host': True + } + + instance = { + 'host': 'some-other-host' + } + + ctxt = context.RequestContext('testuser', 'testproject', + is_admin=False) + + self.stubs.Set(self.network.db, + 'floating_ip_get_by_address', + lambda _x, _y: floating_ip) + + self.stubs.Set(self.network, + '_floating_ip_owned_by_project', + lambda _x, _y: True) + + self.stubs.Set(self.network.db, + 'fixed_ip_get', + lambda _x, _y: fixed_ip) + + self.stubs.Set(self.network, + '_get_network_by_id', + lambda _x, _y: network) + + self.stubs.Set(self.network.db, + 'instance_get_by_uuid', + lambda _x, _y: instance) + + self.stubs.Set(self.network.db, + 'service_get_by_host_and_topic', + lambda _x, _y, _z: 'service') + + self.stubs.Set(self.network.servicegroup_api, + 'service_is_up', + lambda _x: True) + + self.mox.StubOutWithMock( + self.network.network_rpcapi, '_disassociate_floating_ip') + + self.network.network_rpcapi._disassociate_floating_ip( + ctxt, 'fl_ip', mox.IgnoreArg(), 'some-other-host', 'instance-uuid') + self.mox.ReplayAll() + + self.network.disassociate_floating_ip(ctxt, 'fl_ip', True) + + def test_associate_floating_ip_multi_host_calls(self): + floating_ip = { + 'fixed_ip_id': None + } + + fixed_ip = { + 'network_id': None, + 'instance_uuid': 'instance-uuid' + } + + network = { + 'multi_host': True + } + + instance = { + 'host': 'some-other-host' + } + + ctxt = context.RequestContext('testuser', 'testproject', + is_admin=False) + + self.stubs.Set(self.network.db, + 'floating_ip_get_by_address', + lambda _x, _y: floating_ip) + + self.stubs.Set(self.network, + '_floating_ip_owned_by_project', + lambda _x, _y: True) + + self.stubs.Set(self.network.db, + 'fixed_ip_get_by_address', + lambda _x, _y: fixed_ip) + + self.stubs.Set(self.network, + '_get_network_by_id', + lambda _x, _y: network) + + self.stubs.Set(self.network.db, + 'instance_get_by_uuid', + lambda _x, _y: instance) + + self.mox.StubOutWithMock( + self.network.network_rpcapi, '_associate_floating_ip') + + self.network.network_rpcapi._associate_floating_ip( + ctxt, 'fl_ip', 'fix_ip', mox.IgnoreArg(), 'some-other-host', + 'instance-uuid') + self.mox.ReplayAll() + + self.network.associate_floating_ip(ctxt, 'fl_ip', 'fix_ip', True) + def test_double_deallocation(self): instance_ref = db.api.instance_create(self.context, {"project_id": self.project_id}) diff --git a/nova/tests/network/test_rpcapi.py b/nova/tests/network/test_rpcapi.py index 77a936b63..032996209 100644 --- a/nova/tests/network/test_rpcapi.py +++ b/nova/tests/network/test_rpcapi.py @@ -265,12 +265,13 @@ class NetworkRpcAPITestCase(test.TestCase): def test__associate_floating_ip(self): self._test_network_api('_associate_floating_ip', rpc_method='call', floating_address='fake_addr', fixed_address='fixed_address', - interface='fake_interface', host='fake_host') + interface='fake_interface', host='fake_host', + instance_uuid='fake_uuid', version='1.6') def test__disassociate_floating_ip(self): self._test_network_api('_disassociate_floating_ip', rpc_method='call', address='fake_addr', interface='fake_interface', - host='fake_host') + host='fake_host', instance_uuid='fake_uuid', version='1.6') def test_migrate_instance_start(self): self._test_network_api('migrate_instance_start', rpc_method='call', |