From 12fa59dbb2a96d8f07d6247a08709222b359d87a Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 30 Jan 2013 11:17:33 -0800 Subject: Move floating ip db access to calling side. Most of the allocation for floating ips can be done on the calling side, including finding the proper host to send the message to. This saves us from making an rpc call for allocate/deallocate and makes sure that we only need 1 call for associate/disassociate by finding the proper host to send the message to immediately. Getting exceptions to work properly required pulling in the helper that was used by the conductor to regenerate exceptions that are wrapped for rpc. Since this is now a shared class, it was moved to utils. Also a few config options were moved to avoid circular imports. Part of blueprint optimize-nova-network Change-Id: I6ec65b1f3e8d00cab778b10eec620760886567e0 --- .../api/openstack/compute/contrib/test_floating_ips.py | 13 +++++++------ nova/tests/conf_fixture.py | 4 ++-- nova/tests/network/test_api.py | 7 ++++--- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py index b6b8dd630..864ab7a9f 100644 --- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py @@ -27,7 +27,6 @@ from nova import db from nova import exception from nova import network from nova.openstack.common import jsonutils -from nova.openstack.common import rpc from nova import test from nova.tests.api.openstack import fakes from nova.tests import fake_network @@ -275,12 +274,11 @@ class FloatingIpTest(test.TestCase): self.assertIn(self.floating_ip, ip_list) self.assertNotIn(self.floating_ip_2, ip_list) -# test floating ip allocate/release(deallocate) def test_floating_ip_allocate_no_free_ips(self): - def fake_call(*args, **kwargs): + def fake_allocate(*args, **kwargs): raise exception.NoMoreFloatingIps() - self.stubs.Set(rpc, "call", fake_call) + self.stubs.Set(network.api.API, "allocate_floating_ip", fake_allocate) req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips') self.assertRaises(exception.NoMoreFloatingIps, @@ -316,9 +314,12 @@ class FloatingIpTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/os-floating-ips/1') self.controller.delete(req, 1) -# test floating ip add/remove -> associate/disassociate - def test_floating_ip_associate(self): + def fake_associate_floating_ip(*args, **kwargs): + pass + + self.stubs.Set(network.api.API, "associate_floating_ip", + fake_associate_floating_ip) body = dict(addFloatingIp=dict(address=self.floating_ip)) req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action') diff --git a/nova/tests/conf_fixture.py b/nova/tests/conf_fixture.py index 2f4d0ebb1..230f70a1b 100644 --- a/nova/tests/conf_fixture.py +++ b/nova/tests/conf_fixture.py @@ -30,8 +30,8 @@ CONF.import_opt('scheduler_driver', 'nova.scheduler.manager') CONF.import_opt('fake_network', 'nova.network.manager') CONF.import_opt('network_size', 'nova.network.manager') CONF.import_opt('num_networks', 'nova.network.manager') -CONF.import_opt('floating_ip_dns_manager', 'nova.network.manager') -CONF.import_opt('instance_dns_manager', 'nova.network.manager') +CONF.import_opt('floating_ip_dns_manager', 'nova.network.floating_ips') +CONF.import_opt('instance_dns_manager', 'nova.network.floating_ips') CONF.import_opt('policy_file', 'nova.policy') CONF.import_opt('compute_driver', 'nova.virt.driver') CONF.import_opt('api_paste_config', 'nova.wsgi') diff --git a/nova/tests/network/test_api.py b/nova/tests/network/test_api.py index 8e9abe1db..01c727c17 100644 --- a/nova/tests/network/test_api.py +++ b/nova/tests/network/test_api.py @@ -26,8 +26,8 @@ from nova import context from nova import exception from nova import network from nova.network import api +from nova.network import floating_ips from nova.network import rpcapi as network_rpcapi -from nova.openstack.common import rpc from nova import policy from nova import test @@ -90,10 +90,11 @@ class ApiTestCase(test.TestCase): new_instance = {'uuid': 'new-uuid'} - def fake_rpc_call(context, topic, msg, timeout=None): + def fake_associate(*args, **kwargs): return orig_instance_uuid - self.stubs.Set(rpc, 'call', fake_rpc_call) + self.stubs.Set(floating_ips.FloatingIP, 'associate_floating_ip', + fake_associate) def fake_instance_get_by_uuid(context, instance_uuid): return {'uuid': instance_uuid} -- cgit