From 4e511e5b4b6ad44bf35600ae70e1646496d66602 Mon Sep 17 00:00:00 2001 From: "Dr. Jens Harbott" Date: Fri, 29 Dec 2023 17:13:25 +0100 Subject: [PATCH] Fix error in cinder-manage quota sync cmd This fixes a regression introduced in [0] which changed a variable name in some function definitions, but failed to change the matching variable references. Change some similar functions for consistency and to avoid overloading imports with local variable names. [0] https://review.opendev.org/c/openstack/cinder/+/842542 Related-Bug: 2047693 Change-Id: I153a73ad88762d5baa3f3c2c5c752e56280f7dc0 --- cinder/cmd/manage.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 5035f6d6bea..264e04ce805 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -346,7 +346,7 @@ class QuotaCommands(object): pass @args('--project-id', default=None, - help=('The ID of the project where we want to sync the quotas ' + help=('The ID of the project where we want to check the quotas ' '(defaults to all projects).')) def check(self, project_id: Optional[str]) -> None: """Check if quotas and reservations are correct @@ -386,13 +386,13 @@ class QuotaCommands(object): @db_api.main_context_manager.reader def _get_quota_projects(self, - context: context.RequestContext, + ctxt: context.RequestContext, project_id: Optional[str]) -> list[str]: """Get project ids that have quota_usage entries.""" if project_id: model = models.QuotaUsage # If the project does not exist - if not context.session.query( + if not ctxt.session.query( db_api.sql.exists() .where( db_api.and_( @@ -409,7 +409,7 @@ class QuotaCommands(object): return [project_id] projects = db_api.model_query( - context, + ctxt, models.QuotaUsage, read_deleted="no" ).with_entities('project_id').distinct().all() @@ -422,10 +422,10 @@ class QuotaCommands(object): project_id: str) -> list: """Get data necessary to check out of sync quota usage. - Returns a list QuotaUsage instances for the specific project + Returns a list of QuotaUsage instances for the specific project """ usages = db_api.model_query( - context, + ctxt, db_api.models.QuotaUsage, read_deleted="no", ).filter_by(project_id=project_id).with_for_update().all() @@ -438,7 +438,7 @@ class QuotaCommands(object): """Get reservations for a given project and usage id.""" reservations = ( db_api.model_query( - context, + ctxt, models.Reservation, read_deleted="no", ) @@ -449,7 +449,7 @@ class QuotaCommands(object): return reservations def _check_duplicates(self, - context: context.RequestContext, + ctxt: context.RequestContext, usages, do_fix: bool) -> tuple[list, bool]: """Look for duplicated quota used entries (bug#1484343) @@ -476,7 +476,7 @@ class QuotaCommands(object): reassigned = 0 for usage in resource_usages[1:]: reservations = self._get_reservations( - context, + ctxt, usage.project_id, usage.id, ) @@ -485,7 +485,7 @@ class QuotaCommands(object): reservation.usage_id = keep_usage.id keep_usage.in_use += usage.in_use keep_usage.reserved += usage.reserved - usage.delete(context.session) + usage.delete(ctxt.session) print('duplicates removed & %s reservations reassigned' % reassigned) else: @@ -520,7 +520,7 @@ class QuotaCommands(object): @db_api.main_context_manager.reader def _check_project_sync(self, - context: context.RequestContext, + ctxt: context.RequestContext, project: str, do_fix: bool, resources) -> bool: @@ -534,11 +534,11 @@ class QuotaCommands(object): # running Cinder services. # We only want to sync existing quota usage rows - usages = self._get_usages(context, resources, project) + usages = self._get_usages(ctxt, resources, project) # Check for duplicated entries (bug#1484343) usages, duplicates_found = self._check_duplicates( - context, usages, do_fix, + ctxt, usages, do_fix, ) if duplicates_found: discrepancy = True @@ -548,7 +548,7 @@ class QuotaCommands(object): resource_name = usage.resource # Get the correct value for this quota usage resource updates = db_api._get_sync_updates( - context, + ctxt, project, resources, resource_name, @@ -564,7 +564,7 @@ class QuotaCommands(object): usage.in_use = in_use reservations = self._get_reservations( - context, + ctxt, project, usage.id, )