[openstack-dev] Decorator behavior

Dan Smith dms at danplanet.com
Mon Mar 31 17:32:49 UTC 2014


> At run time there are decorators that behave in an unexpected manner.
> For instance, in nova/compute/manager.py when ComputeManager's
> resize_instance method is called, the "migration" positional argument
> is somehow added to kwargs (paired with the "migration" key) and is
> stripped out of the args parameters when the decorators are called.
> However, when this same method is called in
> nova/tests/compute/test_compute_mgr.py, the "migration" positional
> argument remains in args when the decorators are called.  In other
> words at run time the decorators see these arguments:
> 
> (self, context, [], {'migration': migration, 'image': image,
> 'instance': instance, 'reservations': reservations})
> 
> while when running a test case, they see these arguments:
> 
> (self, context, [instance, image, reservations, migration,
> instance_type], {})

All RPC-called methods get called with all of their arguments as keyword
arguments. I think this explains the runtime behavior you're seeing.
Tests tend to differ in this regard because test writers are human and
call the methods in the way they normally expect, passing positional
arguments when appropriate.

--Dan




More information about the OpenStack-dev mailing list