cinder.quota.QuotaEngine.get_default function using unexpected argument

Bug #1785947 reported by Yang Zhang
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
In Progress
Undecided
Unassigned

Bug Description

The get_default function in cinder.quota.QuotaEngine calls the _driver's
get_default function, but neither DbQuotaDriver nor NestedDbQuotaDriver
actually takes parent_project_id as an argument; see the code below.

    def get_default(self, context, resource, parent_project_id=None):
        """Get a specific default quota for a resource.

        :param parent_project_id: The id of the current project's parent,
                                  if any.
        """

        return self._driver.get_default(context, resource,
                                        parent_project_id=parent_project_id)

The NestedDbQuotaDriver get_default function is like this:

    def get_default(self, context, resource, project_id):
        """Get a specific default quota for a resource."""
        resource = super(NestedDbQuotaDriver, self).get_default(
            context, resource, project_id)

        return 0 if quota_utils.get_parent_project_id(
            context, project_id) else resource.default

The DbQuotaDriver get_default function is like this:

    def get_default(self, context, resource, project_id):
        """Get a specific default quota for a resource."""
        default_quotas = db.quota_class_get_defaults(context)
        return default_quotas.get(resource.name, resource.default)

I used the get_default function while adding a new quota item,
and the unit tests failed a lot. So I read these codes and find this part
being weired. I think this can be easily fixed, since no one seems using
this function and no unit test runs this part too.

Yang Zhang (wosunoozzy)
description: updated
Changed in cinder:
assignee: nobody → Deepak Mourya (mourya007)
Revision history for this message
Deepak Mourya (mourya007) wrote :

Hi Yang, So do you want to write a test for this also or just change in the get_default method.?

Revision history for this message
Yang Zhang (wosunoozzy) wrote :

Hi Deepak, if it is indeed a bug, then we have to fix it and add some tests for the code I think :)
Or maybe we can just remove this part if is really usless.

Revision history for this message
Deepak Mourya (mourya007) wrote :

I believe updating it to parent_id would be sufficient. What do you think?

Revision history for this message
Yang Zhang (wosunoozzy) wrote :

I'm not sure what exactly the author intended to do with "get_default" function in the drivers.
I think maybe we should change the code where the driver's function is called.

self._driver.get_default(context, resource, project_id)

Changed in cinder:
assignee: Deepak Mourya (mourya007) → nobody
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/cinder/+/819691

Changed in cinder:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/cinder/+/907152

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on cinder (master)

Change abandoned by "Rajat Dhasmana <email address hidden>" on branch: master
Review: https://review.opendev.org/c/openstack/cinder/+/819691
Reason: in favor of https://review.opendev.org/c/openstack/cinder/+/907152 (since i thought doing it over master would be better, it wasn't)

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.