← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1461665] [NEW] nova.tests.unit.db.test_db_api sets up quotas incorrectly

 

Public bug reported:

Faced this problem when porting tests to python3. user_quotas[res] field
is bring populated with the class object instead of hard_limit. python2
is magically allowing "user_quotas[res] >= 0" to succed when that
variable has nova.db.sqlalchemy.models.Quota or
nova.db.sqlalchemy.models.ProjectQuota

You can also reproduce this with the following patch:

diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 16342e1..7e7e43a 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -3428,6 +3428,10 @@ def _calculate_overquota(project_quotas, user_quotas, deltas,
     for res, delta in deltas.items():
         # We can't go over-quota if we're not reserving anything or if
         # we have unlimited quotas.
+        if not isinstance(user_quotas[res], six.integer_types):
+            raise Exception('user_quotas[res] is not an integer - %r'
+                            % user_quotas[res])
+
         if user_quotas[res] >= 0 and delta >= 0:
             # over if the project usage + delta is more than project quota
             if project_quotas[res] < delta + project_usages[res]['total']:

Here's a sample output:
http://paste.openstack.org/show/260349/

** Affects: nova
     Importance: Medium
     Assignee: Matt Riedemann (mriedem)
         Status: In Progress


** Tags: db testing

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1461665

Title:
  nova.tests.unit.db.test_db_api sets up quotas incorrectly

Status in OpenStack Compute (Nova):
  In Progress

Bug description:
  Faced this problem when porting tests to python3. user_quotas[res]
  field is bring populated with the class object instead of hard_limit.
  python2 is magically allowing "user_quotas[res] >= 0" to succed when
  that variable has nova.db.sqlalchemy.models.Quota or
  nova.db.sqlalchemy.models.ProjectQuota

  You can also reproduce this with the following patch:

  diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
  index 16342e1..7e7e43a 100644
  --- a/nova/db/sqlalchemy/api.py
  +++ b/nova/db/sqlalchemy/api.py
  @@ -3428,6 +3428,10 @@ def _calculate_overquota(project_quotas, user_quotas, deltas,
       for res, delta in deltas.items():
           # We can't go over-quota if we're not reserving anything or if
           # we have unlimited quotas.
  +        if not isinstance(user_quotas[res], six.integer_types):
  +            raise Exception('user_quotas[res] is not an integer - %r'
  +                            % user_quotas[res])
  +
           if user_quotas[res] >= 0 and delta >= 0:
               # over if the project usage + delta is more than project quota
               if project_quotas[res] < delta + project_usages[res]['total']:

  Here's a sample output:
  http://paste.openstack.org/show/260349/

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1461665/+subscriptions


Follow ups

References