Ask Your Question

Units test failing when un-stubbing db.instance_create

asked 2011-03-24 10:47:13 -0500

salvatore-orlando gravatar image


In one of my branches (lp:~citrix-openstack/nova/xenapi-netinject-prop), I tried to improve code coverage as well by un-stubbing several routines, among which db.instance_create (currently stubbed out in nova/test/db/

After merging with lp:nova rev #862 one unit test, test_finish_resize, was failing complaining that instance.local_gb was none. I noticed that in stubbed-out method we were retrieving the value for local_gb from INSTANCE_TYPES as follows:

type_data = INSTANCE_TYPES[values['instance_type']]

It seems that some recent merge instead is not using this anymore, taking just the value passed by the caller of the DB API method.

I was therefore wondering whether there is a chance that the resize feature for XenAPI in VMOps might be broken (although it is very highly unlikely that an instance will not have a null local_gb field!).

As a general note, we should probably avoid stubbing out db APIs.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2011-03-26 21:43:08 -0500

When I added dynamic instance types, I left the fake in since the other tests relied not on the db.instance_type_get_by_name working correctly but also it producing a known set of values (i.e. there is a x1.large in the instance_type table). This sort of tight coupling will make our tests very brittle. While this is currently the case (we initialize the values in the migration), it may not always be -- for example if we embrace the openstack api more fully. If these are unit tests, I think it is still valid to stub/fake these.

An additional comment, shouldn't

  db.instance_type_get_by_name(None, 'm1.large')


  db.instance_type_get_by_name(context.get_admin_context(), 'm1.large')

in bzr revno 893 ?

In [1]: from nova import db

In [2]: db.instance_type_get_by_name(None, 'm1.large') /Users/kpepple/Documents/dev/openstack/projects/nova/nova/db/sqlalchemy/ DeprecationWarning: Use of empty request context is deprecated


Exception Traceback (most recent call last)

/Users/kpepple/Documents/dev/openstack/projects/nova/<ipython console=""> in <module>()

/Users/kpepple/Documents/dev/openstack/projects/nova/nova/db/ in instance_type_get_by_name(context, name) 1127 def instance_type_get_by_name(context, name): 1128 """Get instance type by name""" -> 1129 return IMPL.instance_type_get_by_name(context, name) 1130 1131

/Users/kpepple/Documents/dev/openstack/projects/nova/nova/db/sqlalchemy/ in wrapper(args, *kwargs) 105 """ 106 def wrapper(args, *kwargs): --> 107 if not is_admin_context(args[0]) and not is_user_context(args[0]): 108 raise exception.NotAuthorized() 109 return f(args, *kwargs)

/Users/kpepple/Documents/dev/openstack/projects/nova/nova/db/sqlalchemy/ in is_admin_context(context) 45 warnings.warn(_('Use of empty request context is deprecated'), 46 DeprecationWarning) ---> 47 raise Exception('die') 48 return context.is_admin 49

Exception: die

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2011-03-24 10:47:13 -0500

Seen: 37 times

Last updated: Mar 26 '11