From 5ff0278561d4008bc710440129f4a7b5c38cdd98 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 8 May 2013 15:47:47 -0700 Subject: Report the az based on the value in the instance table. When attempting to find the availability zone of an instance do so by first trying to locate the availability zone of the host the instance is active on. If that fails then attempt to use the value that is in the instances 'availability_zone' key instead. For the caching used in the availability_zones module there was a new method added to get and reset the cache that is useful for unit tests, since during each run of a test you do not want to be affected by something in cache from a previous test. Fixes bug 1172246 Change-Id: I6f54a44cc87434120656ccc789cebcc08d434418 --- .../openstack/compute/contrib/extended_availability_zone.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/extended_availability_zone.py b/nova/api/openstack/compute/contrib/extended_availability_zone.py index 00765e209..6e77cd6bd 100644 --- a/nova/api/openstack/compute/contrib/extended_availability_zone.py +++ b/nova/api/openstack/compute/contrib/extended_availability_zone.py @@ -20,7 +20,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil -from nova import availability_zones +from nova import availability_zones as avail_zone authorize = extensions.soft_extension_authorizer('compute', 'extended_availability_zone') @@ -29,8 +29,13 @@ authorize = extensions.soft_extension_authorizer('compute', class ExtendedAZController(wsgi.Controller): def _extend_server(self, context, server, instance): key = "%s:availability_zone" % Extended_availability_zone.alias - server[key] = availability_zones.get_instance_availability_zone( - context, instance) + az = avail_zone.get_instance_availability_zone(context, instance) + if not az and instance.get('availability_zone'): + # Likely hasn't reached a viable compute node yet so give back the + # desired availability_zone that *may* exist in the instance + # record itself. + az = instance['availability_zone'] + server[key] = az @wsgi.extends def show(self, req, resp_obj, id): -- cgit