[openstack-dev] [nova] need help with unit test framework, trying to fix bug 1292963

Chris Friesen chris.friesen at windriver.com
Tue Mar 18 06:18:36 UTC 2014


On 03/17/2014 04:28 PM, Chris Friesen wrote:

> The second one filters out all of the objects and returns nothing.
>
> (Pdb) query_prefix.filter(models.Instance.vm_state != vm_states.SOFT_DELETED).all()
> []

I think I've found another problem.  (The rabbit hole continues...)

It appears that by design in SQL and sqlalchemy the comparison operators 
do not test NULL values, so the above filter will not return objects 
where vm_state is NULL.  This seems to me to be extra confusing in 
sqlalchemy since you can in fact use the comparison operators to 
explicitly test against None.

The problem is that in the Instance object the "vm_state" field is 
declared as nullable.  In many cases "vm_state" will in fact have a 
value, but in get_test_instance() in test/utils.py the value of 
"vm_state" is not specified.

Given the above, it seems that either we need to configure 
"models.Instance.vm_state" as not nullable (and deal with the fallout), 
or else we need to update instance_get_all_by_filters() to explicitly 
check for None--something like this perhaps:

if not filters.pop('soft_deleted', False):
     query_prefix = query_prefix.\
         filter(or_(models.Instance.vm_state != vm_states.SOFT_DELETED,
                    models.Instance.vm_state == None))


I could do the latter--should I open another bug and make the fix for 
bug 1292963 dependent on the other fix going in first?

I wonder if we have other similar tests that might behave unexpectedly?

Chris



More information about the OpenStack-dev mailing list