summaryrefslogtreecommitdiff
path: root/nova/availability_zones.py
diff options
context:
space:
mode:
authorchenxiao <chenxiao@cn.ibm.com>2013-12-04 17:29:36 +0800
committerXiao Chen <chenxiao@cn.ibm.com>2013-12-26 17:50:26 +0800
commitdb0831ec96a6806035c51d94ade1e51eafb42162 (patch)
treea798fbc8c694420f25fb779a979a23fafb35ac24 /nova/availability_zones.py
parent3d19edc023e34c73cbaed60bf1fb0c9dc287fb89 (diff)
downloadnova-db0831ec96a6806035c51d94ade1e51eafb42162.tar.gz
Fixing availability-zone not take effect error
when add/remove a host to one aggregate or update aggregate metadata incluing availability_zone, "OS-EXT-AZ:availability_zone" property of some instances in the host can not show correctly. The cause is that when getting availability_zone of one instance, it will try to get the value from cache first, but unfortunately the cache does not update or reset in time, and it will keep one hour if we do not change it. This patch will add update or reset after adding/removing a host to one aggregate or updating aggregate metadata including availability_zone. Change-Id: I5dd07f876471b5faf8fb1016e25a861124b7cb6f Closes-bug: #1240374
Diffstat (limited to 'nova/availability_zones.py')
-rw-r--r--nova/availability_zones.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/nova/availability_zones.py b/nova/availability_zones.py
index 73b9bf2414..359b1e8b78 100644
--- a/nova/availability_zones.py
+++ b/nova/availability_zones.py
@@ -74,10 +74,8 @@ def set_availability_zones(context, services):
else:
az = CONF.default_availability_zone
# update the cache
- cache = _get_cache()
- cache_key = _make_cache_key(service['host'])
- cache.delete(cache_key)
- cache.set(cache_key, az, AZ_CACHE_SECONDS)
+ update_host_availability_zone_cache(context,
+ service['host'], az)
service['availability_zone'] = az
return services
@@ -96,6 +94,15 @@ def get_host_availability_zone(context, host, conductor_api=None):
return az
+def update_host_availability_zone_cache(context, host, availability_zone=None):
+ if not availability_zone:
+ availability_zone = get_host_availability_zone(context, host)
+ cache = _get_cache()
+ cache_key = _make_cache_key(host)
+ cache.delete(cache_key)
+ cache.set(cache_key, availability_zone, AZ_CACHE_SECONDS)
+
+
def get_availability_zones(context, get_only_available=False):
"""Return available and unavailable zones on demand.