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

Bug #1461665 reported by Davanum Srinivas (DIMS)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Medium
Matt Riedemann

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/

Tags: db testing
Revision history for this message
Matt Riedemann (mriedem) wrote :

Confirmed in IRC, the user_quotas dict should be map of resources to ProjectUserQuota.hard_limit values, the test is setting it up incorrectly.

tags: added: db testing
Changed in nova:
status: New → Triaged
status: Triaged → In Progress
importance: Undecided → Medium
assignee: nobody → Matt Riedemann (mriedem)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/188231

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/188231
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=27236e3d6ab163c9032463b781b125ed62cd8afd
Submitter: Jenkins
Branch: master

commit 27236e3d6ab163c9032463b781b125ed62cd8afd
Author: Matt Riedemann <email address hidden>
Date: Wed Jun 3 19:00:02 2015 -0700

    Fix _quota_reserve test setup for incompatible type checking

    The db.quota_reserve() method expects to get project_quotas and
    user_quotas as dicts that map resource types to limits which are ints.

    The _quota_reserve test setup method was just mapping the resource type
    to the Quota sqlalchemy dict-like object that was coming back from
    db.quota_create. Since db._calculate_overquota compares the delta (int)
    to the user_quotas/project_quotas value, which was a Quota object, and
    py34 doesn't allow incompatible type checks like that, this fails with
    py34.

    This fixes the _quota_reserve test setup method to map the resource type
    to the hard_limit like the actual DB APIs do in the normal nova.quota
    flows. It also has to adjust the setup method to avoid going over-quota
    immediately due to the limit and usage being the same (which is why we
    add a buffer to the i value for the limit).

    Closes-Bug: #1461665

    Change-Id: I9f5f537eff58fe83caa7bff2fb0800ce9f7272fa

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → liberty-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: liberty-1 → 12.0.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.