Comment 3 for bug 1390033

Revision history for this message
Trung Trinh (trung-t-trinh) wrote :

One of the buggy locations was found out.
It is inside the function "get_instance_availability_zone()" of the module "nova.availability_zones".

Let's look at the its code snippet:

def get_instance_availability_zone(context, instance):
    """Return availability zone of specified instance."""
    host = str(instance.get('host'))

    if not host:
        return None

It's quite easy to understand this code snippet that it tries to read value of the host from the "instance". If the "host" is empty or None, then the function will be returned and nothing will happen.
However, Python interpreter makes all surprised that even though the "host" value is None, but the if-clause does not hold and consequently the execution is continued with the "host" whose value is None. Finally, it leads to the fact that the "az" returned is the default one (as mentioned above).

For proof, please look at the output of the Python interactive session:

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> host = str(None)
>>> print host
None
>>> if not host:
... print "if not host"
... else:
... print "else"
...
else
>>> var = None
>>> if not var:
... print "if not var"
... else:
... print "else"
...
if not var

So, it can be seen that str(None) returns an object whose value is None, but it is not interpreted False as expected!

However, this is still not the root cause of this bug! Further investigation is being carried out.