quota_reserve headroom might be wrong if project_quotas != user_quotas

Bug #1369696 reported by Matt Riedemann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Liyingjun

Bug Description

Looking at this code:

https://github.com/openstack/nova/blob/2014.2.b3/nova/db/sqlalchemy/api.py#L3343

Notice the headroom variable is created based on usages and user_quotas:

        headroom = dict((res, user_quotas[res] -
                             (usages[res]['in_use'] + usages[res]['reserved']))
                        for res in user_quotas.keys())

but the usages variable is based on whether or not project_quotas == user_quotas:

        if project_quotas == user_quotas:
            usages = project_usages
        else:
            usages = user_usages

So it appears that headroom could be incorrect if project_quotas != user_quotas.

Looking at what uses headroom, the compute API uses this in the instance create and resize flows. For resize it's just using headroom to plug into an error message for the TooManyInstances exception.

In the create flow (_check_num_instances_quota) it's used for a bit more advanced logic with recursion.

We should probably just remove the headroom calculation from quota_reserve and let the caller figure it out and what needs to be done with it. It's also odd that this is happening in the DB API because it's dealing with instance quotas but maybe I'm not doing anything with instance quotas, maybe I'm doing things with security group or fixed IP quotas - so this code seems to be in the wrong place. Maybe it's just conveniently placed here given the other data already in scope from the database.

Revision history for this message
Chris Behrens (cbehrens) wrote :

Agree with fixing this by removing the headroom calculation from the db layer. I don't like the hardcoding of things like 'cores' and so forth in there related to this. I think returning current usage+reservations along with quotas is enough to let the caller to compute headroom itself on the resources it cares about, etc...

Matt Riedemann (mriedem)
Changed in nova:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Matt Riedemann (mriedem) wrote :

Maybe user_quotas is used since that's the only thing checked when calculating headroom for cores and ram (flavor info), but still seems like this is a hack and should be done on the calling side rather than in the DB API.

Liyingjun (liyingjun)
Changed in nova:
assignee: nobody → Liyingjun (liyingjun)
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/121786

Changed in nova:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/121786
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=0045f7d50cad345c26ae02394ad57716b270d268
Submitter: Jenkins
Branch: master

commit 0045f7d50cad345c26ae02394ad57716b270d268
Author: liyingjun <email address hidden>
Date: Sat Sep 6 09:10:31 2014 +0800

    Removing the headroom calculation from db layer

    It's odd that this is happening in the DB API because it's dealing
    with instance quotas but maybe I'm not doing anything with instance
    quotas, maybe I'm doing things with security group or fixed IP quotas.

    This patch moves the headroom calculation from db layer to the
    calling side.

    Change-Id: I8379471eea4ea7b114c2a235224f6fe61f8f981f
    Closes-bug: #1369696

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → kilo-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: kilo-1 → 2015.1.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.