From aee267182ab86814bac22e28fed0beb370fa2293 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Fri, 10 Feb 2012 17:21:52 -0600 Subject: remove all instance_type db lookups from network increases efficiency without requiring extra parameters Change-Id: I858067afb94007c8e71748373873f7cc8bd54662 --- nova/network/api.py | 4 ++-- nova/network/manager.py | 24 +++++++++++------------- nova/network/quantum/manager.py | 18 +++++++----------- nova/tests/api/ec2/test_cloud.py | 3 +-- nova/tests/fake_network.py | 16 +--------------- nova/tests/test_quantum.py | 12 ++++++------ nova/tests/test_xenapi.py | 2 +- 7 files changed, 29 insertions(+), 50 deletions(-) diff --git a/nova/network/api.py b/nova/network/api.py index 27e07b869..eafbeba60 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -157,7 +157,7 @@ class API(base.Base): args['instance_uuid'] = instance['uuid'] args['project_id'] = instance['project_id'] args['host'] = instance['host'] - args['instance_type_id'] = instance['instance_type_id'] + args['rxtx_factor'] = instance['instance_type']['rxtx_factor'] nw_info = rpc.call(context, FLAGS.network_topic, {'method': 'allocate_for_instance', @@ -201,7 +201,7 @@ class API(base.Base): """Returns all network info related to an instance.""" args = {'instance_id': instance['id'], 'instance_uuid': instance['uuid'], - 'instance_type_id': instance['instance_type_id'], + 'rxtx_factor': instance['instance_type']['rxtx_factor'], 'host': instance['host']} try: nw_info = rpc.call(context, FLAGS.network_topic, diff --git a/nova/network/manager.py b/nova/network/manager.py index 053305992..eafc34417 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -57,7 +57,6 @@ from eventlet import greenpool import netaddr from nova.compute import api as compute_api -from nova.compute import instance_types from nova import context from nova import db from nova import exception @@ -852,13 +851,13 @@ class NetworkManager(manager.SchedulerDependentManager): rpc.called by network_api """ - instance_id = kwargs.pop('instance_id') - instance_uuid = kwargs.pop('instance_uuid') - host = kwargs.pop('host') - project_id = kwargs.pop('project_id') - type_id = kwargs.pop('instance_type_id') + instance_id = kwargs['instance_id'] + instance_uuid = kwargs['instance_uuid'] + host = kwargs['host'] + project_id = kwargs['project_id'] + rxtx_factor = kwargs['rxtx_factor'] requested_networks = kwargs.get('requested_networks') - vpn = kwargs.pop('vpn') + vpn = kwargs['vpn'] admin_context = context.elevated() LOG.debug(_("network allocations for instance %s"), instance_id, context=context) @@ -870,7 +869,7 @@ class NetworkManager(manager.SchedulerDependentManager): host, networks, vpn=vpn, requested_networks=requested_networks) return self.get_instance_nw_info(context, instance_id, instance_uuid, - type_id, host) + rxtx_factor, host) @wrap_check_policy def deallocate_for_instance(self, context, **kwargs): @@ -896,7 +895,7 @@ class NetworkManager(manager.SchedulerDependentManager): @wrap_check_policy def get_instance_nw_info(self, context, instance_id, instance_uuid, - instance_type_id, host): + rxtx_factor, host): """Creates network info list for instance. called by allocate_for_instance and network_api @@ -906,7 +905,6 @@ class NetworkManager(manager.SchedulerDependentManager): and info = dict containing pertinent networking data """ vifs = self.db.virtual_interface_get_by_instance(context, instance_id) - instance_type = instance_types.get_instance_type(instance_type_id) networks = {} for vif in vifs: @@ -916,13 +914,13 @@ class NetworkManager(manager.SchedulerDependentManager): # update instance network cache and return network_info nw_info = self.build_network_info_model(context, vifs, networks, - instance_type, host) + rxtx_factor, host) self.db.instance_info_cache_update(context, instance_uuid, {'network_info': nw_info.as_cache()}) return nw_info def build_network_info_model(self, context, vifs, networks, - instance_type, instance_host): + rxtx_factor, instance_host): """Builds a NetworkInfo object containing all network information for an instance""" nw_info = network_model.NetworkInfo() @@ -943,7 +941,7 @@ class NetworkManager(manager.SchedulerDependentManager): # if rxtx_cap data are not set everywhere, set to none try: - rxtx_cap = network['rxtx_base'] * instance_type['rxtx_factor'] + rxtx_cap = network['rxtx_base'] * rxtx_factor except (TypeError, KeyError): rxtx_cap = None diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py index 341c3b5e3..cde27ddc0 100644 --- a/nova/network/quantum/manager.py +++ b/nova/network/quantum/manager.py @@ -19,7 +19,6 @@ import time from netaddr import IPNetwork, IPAddress -from nova.compute import instance_types from nova import context from nova import db from nova import exception @@ -279,10 +278,10 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): create a port and attachment the vNIC, and use the IPAM lib to allocate IP addresses. """ - instance_id = kwargs.pop('instance_id') - instance_type_id = kwargs['instance_type_id'] - host = kwargs.pop('host') - project_id = kwargs.pop('project_id') + instance_id = kwargs['instance_id'] + rxtx_factor = kwargs['rxtx_factor'] + host = kwargs['host'] + project_id = kwargs['project_id'] LOG.debug(_("network allocations for instance %s"), project_id) requested_networks = kwargs.get('requested_networks') @@ -337,8 +336,6 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): # talk to Quantum API to create and attach port. instance = db.instance_get(context, instance_id) - instance_type = instance_types.get_instance_type(instance_type_id) - rxtx_factor = instance_type['rxtx_factor'] nova_id = self._get_nova_id(instance) # Tell the ipam library to allocate an IP ips = self.ipam.allocate_fixed_ips(context, project_id, @@ -360,7 +357,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): vif_rec, net_tenant_id) return self.get_instance_nw_info(context, instance_id, instance['uuid'], - instance_type_id, host) + rxtx_factor, host) @utils.synchronized('quantum-enable-dhcp') def enable_dhcp(self, context, quantum_net_id, network_ref, vif_rec, @@ -447,7 +444,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): return self.db.virtual_interface_create(context, vif) def get_instance_nw_info(self, context, instance_id, instance_uuid, - instance_type_id, host): + rxtx_factor, host): """This method is used by compute to fetch all network data that should be used when creating the VM. @@ -463,7 +460,6 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): admin_context = context.elevated() project_id = context.project_id vifs = db.virtual_interface_get_by_instance(context, instance_id) - instance_type = instance_types.get_instance_type(instance_type_id) net_tenant_dict = dict((net_id, tenant_id) for (net_id, tenant_id) @@ -485,7 +481,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager): # update instance network cache and return network_info nw_info = self.build_network_info_model(context, vifs, networks, - instance_type, host) + rxtx_factor, host) db.instance_info_cache_update(context, instance_uuid, {'network_info': nw_info.as_cache()}) diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index ef9d0e8c7..3b38ad259 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -198,13 +198,12 @@ class CloudTestCase(test.TestCase): db.network_update(self.context, network['id'], {'host': self.network.host}) project_id = self.context.project_id - type_id = inst['instance_type_id'] nw_info = self.network.allocate_for_instance(self.context, instance_id=inst['id'], instance_uuid='', host=inst['host'], vpn=None, - instance_type_id=type_id, + rxtx_factor=3, project_id=project_id) fixed_ips = nw_info.fixed_ips() diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index 08712a302..86167520c 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -154,16 +154,6 @@ class FakeNetworkManager(network_manager.NetworkManager): pass -flavor = {'id': 0, - 'name': 'fake_flavor', - 'memory_mb': 2048, - 'vcpus': 2, - 'root_gb': 10, - 'flavor_id': 0, - 'swap': 0, - 'rxtx_factor': 3} - - def fake_network(network_id, ipv6=None): if ipv6 is None: ipv6 = FLAGS.use_ipv6 @@ -295,9 +285,6 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2, 'network': None, 'instance_id': 0} - def instance_type_fake(*args, **kwargs): - return flavor - def network_get_fake(context, network_id): nets = [n for n in networks if n['id'] == network_id] if not nets: @@ -335,7 +322,6 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2, stubs.Set(db, 'virtual_interface_get_by_uuid', vif_by_uuid_fake) stubs.Set(db, 'network_get_by_uuid', get_network_by_uuid) stubs.Set(db, 'virtual_interface_get_by_instance', virtual_interfaces_fake) - stubs.Set(db, 'instance_type_get', instance_type_fake) stubs.Set(db, 'network_get', network_get_fake) stubs.Set(db, 'instance_info_cache_update', update_cache_fake) @@ -350,7 +336,7 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2, nw_model = network.get_instance_nw_info( FakeContext('fakeuser', 'fake_project'), - 0, 0, 0, None) + 0, 0, 3, None) if spectacular: return nw_model return nova.compute.utils.legacy_network_info(nw_model) diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py index 2e60bbc45..1605c49db 100644 --- a/nova/tests/test_quantum.py +++ b/nova/tests/test_quantum.py @@ -277,7 +277,7 @@ class QuantumNovaIPAMTestCase(QuantumNovaTestCase): self.net_man.driver.kill_dhcp = func1 nw_info = self.net_man.allocate_for_instance(ctx.elevated(), instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id) self.assertEquals(len(nw_info), 2) @@ -346,7 +346,7 @@ class QuantumNovaIPAMTestCase(QuantumNovaTestCase): self.net_man.driver.kill_dhcp = func1 nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id, requested_networks=requested_networks) @@ -410,7 +410,7 @@ class QuantumNovaMACGenerationTestCase(QuantumNovaTestCase): {"project_id": project_id}) nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id, requested_networks=requested_networks) self.assertEqual(nw_info[0]['address'], fake_mac) @@ -431,7 +431,7 @@ class QuantumNovaMACGenerationTestCase(QuantumNovaTestCase): {"project_id": project_id}) nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id, requested_networks=requested_networks) self.assertEqual(nw_info[0]['address'], fake_mac) @@ -468,7 +468,7 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase): _instrumented_create_and_attach_port nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id, requested_networks=requested_networks) self.assertEqual(nw_info[0]['address'], fake_mac) @@ -502,7 +502,7 @@ class QuantumNovaPortSecurityTestCase(QuantumNovaTestCase): _instrumented_create_and_attach_port nw_info = self.net_man.allocate_for_instance(ctx, instance_id=instance_ref['id'], host="", - instance_type_id=instance_ref['instance_type_id'], + rxtx_factor=3, project_id=project_id, requested_networks=requested_networks) self.assertEqual(nw_info[0]['address'], fake_mac) diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 281e00fc0..ec10defea 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -642,7 +642,7 @@ class XenAPIVMTestCase(test.TestCase): instance_uuid="00000000-0000-0000-0000-000000000000", host=FLAGS.host, vpn=None, - instance_type_id=1, + rxtx_factor=3, project_id=self.project_id) self._test_spawn(glance_stubs.FakeGlance.IMAGE_MACHINE, glance_stubs.FakeGlance.IMAGE_KERNEL, -- cgit