diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2012-02-17 00:42:10 +0000 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2012-02-22 23:36:50 +0000 |
| commit | 08fa534a0d28fa1be48aef927584161becb936c7 (patch) | |
| tree | d872447d9d266df831c0f077afd09a3bd5e90d32 /nova/api | |
| parent | 9196e1c7b07be8d3f9dbe7947cace9fd4e862f9c (diff) | |
| download | nova-08fa534a0d28fa1be48aef927584161becb936c7.tar.gz nova-08fa534a0d28fa1be48aef927584161becb936c7.tar.xz nova-08fa534a0d28fa1be48aef927584161becb936c7.zip | |
Remove network_api fallback for info_cache from APIs
Fixes bug 932395
OS API and EC2 would query the network API when instance['info_cache']
had no network info.. or network info was an empty list. The ideal was
to fall back to querying the network IP in case the cache was busted.
However, reality says this case is extremely common as it is the case
when instances are freshly built and haven't had network info assigned
yet. The calls to network API are expensive and goes against the whole
idea of this "cache".
So, this patch removes the fallback to querying the network API. In its
place, it adds a periodic task to the compute manager to periodically
sync the cache entry.
Since I had to fix a number of tests, I consolidated some things there
as well with regards to instance stubbing.
Change-Id: I493f811bcba4e99ac6a5756bcab473557d5c0104
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/ec2/ec2utils.py | 32 | ||||
| -rw-r--r-- | nova/api/openstack/common.py | 32 |
2 files changed, 11 insertions, 53 deletions
diff --git a/nova/api/ec2/ec2utils.py b/nova/api/ec2/ec2utils.py index d0e9e81d9..e0f336d4c 100644 --- a/nova/api/ec2/ec2utils.py +++ b/nova/api/ec2/ec2utils.py @@ -83,33 +83,15 @@ def get_ip_info_for_instance_from_nw_info(nw_info): return ip_info -def get_ip_info_for_instance_from_cache(instance): - if (not instance.get('info_cache') or - not instance['info_cache'].get('network_info')): - # NOTE(jkoelker) Raising ValueError so that we trigger the - # fallback lookup - raise ValueError - - cached_info = instance['info_cache']['network_info'] - nw_info = network_model.NetworkInfo.hydrate(cached_info) - - return get_ip_info_for_instance_from_nw_info(nw_info) - - def get_ip_info_for_instance(context, instance): - """Return a list of all fixed IPs for an instance""" + """Return a dictionary of IP information for an instance""" - try: - return get_ip_info_for_instance_from_cache(instance) - except (ValueError, KeyError, AttributeError): - # NOTE(jkoelker) If the json load (ValueError) or the - # sqlalchemy FK (KeyError, AttributeError) - # fail fall back to calling out to he - # network api - network_api = network.API() - - nw_info = network_api.get_instance_nw_info(context, instance) - return get_ip_info_for_instance_from_nw_info(nw_info) + cached_nwinfo = instance['info_cache']['network_info'] + # Make sure empty response is turned into [] + if not cached_nwinfo: + cached_nwinfo = [] + nw_info = network_model.NetworkInfo.hydrate(cached_nwinfo) + return get_ip_info_for_instance_from_nw_info(nw_info) def get_availability_zone_by_host(services, host): diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 4305de950..575c58fac 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -304,18 +304,6 @@ def get_networks_for_instance_from_nw_info(nw_info): return networks -def get_networks_for_instance_from_cache(instance): - if (not instance.get('info_cache') or - not instance['info_cache'].get('network_info')): - # NOTE(jkoelker) Raising ValueError so that we trigger the - # fallback lookup - raise ValueError - - cached_info = instance['info_cache']['network_info'] - nw_info = network_model.NetworkInfo.hydrate(cached_info) - return get_networks_for_instance_from_nw_info(nw_info) - - def get_networks_for_instance(context, instance): """Returns a prepared nw_info list for passing into the view builders @@ -328,22 +316,10 @@ def get_networks_for_instance(context, instance): ...} """ - try: - return get_networks_for_instance_from_cache(instance) - except (ValueError, KeyError, AttributeError): - # NOTE(jkoelker) If the json load (ValueError) or the - # sqlalchemy FK (KeyError, AttributeError) - # fail fall back to calling out the the - # network api - pass - - network_api = network.API() - - try: - nw_info = network_api.get_instance_nw_info(context, instance) - except exception.InstanceNotFound: - nw_info = [] - + cached_nwinfo = instance['info_cache']['network_info'] + if not cached_nwinfo: + return {} + nw_info = network_model.NetworkInfo.hydrate(cached_nwinfo) return get_networks_for_instance_from_nw_info(nw_info) |
