Units test failing when un-stubbing db.instance_create

Asked by Salvatore Orlando

Hi,

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/fakes.py).

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.

Question information

Language:
English Edit question
Status:
Answered
For:
OpenStack Compute (nova) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Ken Pepple (ken-pepple) said :
#1

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 test_vmwareapi.py:78

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

be

      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/api.py:46: DeprecationWarning: Use of empty request context is deprecated
  DeprecationWarning)
---------------------------------------------------------------------------
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/api.py 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/api.py 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/api.py 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

Can you help with this problem?

Provide an answer of your own, or ask Salvatore Orlando for more information if necessary.

To post a message you must log in.