diff options
author | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-01-30 13:28:10 -0800 |
---|---|---|
committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-02-07 14:58:17 -0800 |
commit | 331e19e3b5b37758c10eb856fb563dc7300b913d (patch) | |
tree | a61e1c0e7fca4e9791b5b2dfe319b4b0cf50207a | |
parent | 12fa59dbb2a96d8f07d6247a08709222b359d87a (diff) | |
download | nova-331e19e3b5b37758c10eb856fb563dc7300b913d.tar.gz nova-331e19e3b5b37758c10eb856fb563dc7300b913d.tar.xz nova-331e19e3b5b37758c10eb856fb563dc7300b913d.zip |
Optimize rpc handling for allocate and deallocate
If we are in multi_host mode we can save an extra rpc call by
sending the message to the instance host the first time. This
will prevent nova-network from having to resend the message
to actually allocate the fixed ips.
Part of blueprint optimize-nova-network
DocImpact: before multi_host only affected the network create
commands, but now it can be used at run-time to optimize the
path for allocating and deallocating fixed_ips, so it is important
to set it if you are using multi_host networks.
Change-Id: Ide48e0adb2e1051e31965c9a8422b27c1a9c40b3
-rw-r--r-- | nova/network/manager.py | 3 | ||||
-rw-r--r-- | nova/network/rpcapi.py | 17 | ||||
-rw-r--r-- | nova/tests/network/test_rpcapi.py | 25 |
3 files changed, 37 insertions, 8 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py index b182613e2..e53573a0e 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -104,9 +104,6 @@ network_opts = [ cfg.IntOpt('vpn_start', default=1000, help='First Vpn port for private networks'), - cfg.BoolOpt('multi_host', - default=False, - help='Default value for multi_host in networks'), cfg.IntOpt('network_size', default=256, help='Number of addresses in each private subnet'), diff --git a/nova/network/rpcapi.py b/nova/network/rpcapi.py index a9056845d..5c11f956f 100644 --- a/nova/network/rpcapi.py +++ b/nova/network/rpcapi.py @@ -27,6 +27,10 @@ rpcapi_opts = [ cfg.StrOpt('network_topic', default='network', help='the topic network nodes listen on'), + cfg.BoolOpt('multi_host', + default=False, + help='Default value for multi_host in networks. Also, if set, ' + 'some rpc network calls will be sent directly to host.'), ] CONF = cfg.CONF @@ -153,15 +157,24 @@ class NetworkAPI(rpc_proxy.RpcProxy): def allocate_for_instance(self, ctxt, instance_id, instance_uuid, project_id, host, rxtx_factor, vpn, requested_networks, macs=None): + if CONF.multi_host: + topic = rpc.queue_get_for(ctxt, self.topic, host) + else: + topic = None return self.call(ctxt, self.make_msg('allocate_for_instance', instance_id=instance_id, instance_uuid=instance_uuid, project_id=project_id, host=host, rxtx_factor=rxtx_factor, vpn=vpn, requested_networks=requested_networks, macs=macs), - version='1.8') + topic=topic, version='1.8') def deallocate_for_instance(self, ctxt, instance_id, project_id, host): + if CONF.multi_host: + topic = rpc.queue_get_for(ctxt, self.topic, host) + else: + topic = None return self.call(ctxt, self.make_msg('deallocate_for_instance', - instance_id=instance_id, project_id=project_id, host=host)) + instance_id=instance_id, project_id=project_id, host=host), + topic=topic) def add_fixed_ip_to_instance(self, ctxt, instance_id, host, network_id): return self.call(ctxt, self.make_msg('add_fixed_ip_to_instance', diff --git a/nova/tests/network/test_rpcapi.py b/nova/tests/network/test_rpcapi.py index 132d5a433..f3a032dfe 100644 --- a/nova/tests/network/test_rpcapi.py +++ b/nova/tests/network/test_rpcapi.py @@ -28,6 +28,10 @@ CONF = cfg.CONF class NetworkRpcAPITestCase(test.TestCase): + def setUp(self): + super(NetworkRpcAPITestCase, self).setUp() + self.flags(multi_host=True) + def _test_network_api(self, method, rpc_method, **kwargs): ctxt = context.RequestContext('fake_user', 'fake_project') rpcapi = network_rpcapi.NetworkAPI() @@ -45,13 +49,18 @@ class NetworkRpcAPITestCase(test.TestCase): '_rpc_allocate_fixed_ip', 'deallocate_fixed_ip', 'update_dns', '_associate_floating_ip', '_disassociate_floating_ip', 'lease_fixed_ip', 'release_fixed_ip', 'migrate_instance_start', - 'migrate_instance_finish', 'get_backdoor_port' + 'migrate_instance_finish', 'get_backdoor_port', + 'allocate_for_instance', 'deallocate_for_instance', ] if method in targeted_methods and 'host' in kwargs: - if method != 'deallocate_fixed_ip': + if method not in ['allocate_for_instance', + 'deallocate_for_instance', + 'deallocate_fixed_ip']: del expected_msg['args']['host'] host = kwargs['host'] - expected_topic = rpc.queue_get_for(ctxt, CONF.network_topic, host) + if CONF.multi_host: + expected_topic = rpc.queue_get_for(ctxt, CONF.network_topic, + host) expected_msg['version'] = expected_version self.fake_args = None @@ -148,6 +157,16 @@ class NetworkRpcAPITestCase(test.TestCase): self._test_network_api('deallocate_floating_ip', rpc_method='call', address='addr', affect_auto_assigned=True) + def test_allocate_floating_ip_no_multi(self): + self.flags(multi_host=False) + self._test_network_api('allocate_floating_ip', rpc_method='call', + project_id='fake_id', pool='fake_pool', auto_assigned=False) + + def test_deallocate_floating_ip_no_multi(self): + self.flags(multi_host=False) + self._test_network_api('deallocate_floating_ip', rpc_method='call', + address='addr', affect_auto_assigned=True) + def test_associate_floating_ip(self): self._test_network_api('associate_floating_ip', rpc_method='call', floating_address='blah', fixed_address='foo', |