From 82be2371fc47a485722dfa84427888f24a377612 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Thu, 22 Aug 2024 15:19:33 +0000 Subject: [PATCH] Fix "cinder-manage quota check" When no project id is specified, this fails with: ERROR cinder sqlalchemy.exc.ArgumentError: Textual column expression 'project_id' should be explicitly declared with text('project_id'), or use column('project_id') for more specificity Re-work the query to use column('project_id') to fix this. This moves into the db layer so that cinder-manage doesn't need to directly import sqlalchemy. Closes-Bug: #2077643 Change-Id: I5ff068b01cce8a1ae8747b57b1785325c037cd68 --- cinder/cmd/manage.py | 8 +++----- cinder/db/api.py | 4 ++++ cinder/db/sqlalchemy/api.py | 5 +++++ ...077643-manage-quota-sync-no-args-7fe8dbc6e3069cfc.yaml | 6 ++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-2077643-manage-quota-sync-no-args-7fe8dbc6e3069cfc.yaml diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index a573768f43f..a7cac0cf946 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -401,11 +401,9 @@ class QuotaCommands(object): return [] return [project_id] - projects = db_api.model_query( - ctxt, - models.QuotaUsage, - read_deleted="no" - ).with_entities('project_id').distinct().all() + projects = db_api.get_projects(ctxt, + models.QuotaUsage, + read_deleted="no") project_ids = [row.project_id for row in projects] return project_ids diff --git a/cinder/db/api.py b/cinder/db/api.py index b5e66906ac4..47507a43a93 100644 --- a/cinder/db/api.py +++ b/cinder/db/api.py @@ -1982,3 +1982,7 @@ def attachment_specs_update_or_create(context, def remove_temporary_admin_metadata_data_migration(context, max_count): return IMPL.remove_temporary_admin_metadata_data_migration( context, max_count) + + +def get_projects(context, model, read_deleted="no"): + return IMPL.get_projects(context, model, read_deleted=read_deleted) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 0fe7596ba0f..4fba07d69c4 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -8653,3 +8653,8 @@ CALCULATE_COUNT_HELPERS = { 'snapshot': (_snaps_get_query, _process_snaps_filters), 'backup': (_backups_get_query, _process_backups_filters), } + + +def get_projects(context, model, read_deleted="no"): + return model_query(context, model, read_deleted=read_deleted).\ + with_entities(sa.Column('project_id')).distinct().all() diff --git a/releasenotes/notes/bug-2077643-manage-quota-sync-no-args-7fe8dbc6e3069cfc.yaml b/releasenotes/notes/bug-2077643-manage-quota-sync-no-args-7fe8dbc6e3069cfc.yaml new file mode 100644 index 00000000000..7bc86428203 --- /dev/null +++ b/releasenotes/notes/bug-2077643-manage-quota-sync-no-args-7fe8dbc6e3069cfc.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + `Bug #2077643 `_: Fixed + "cinder-manage quota sync" CLI command, which failed with an sqlalchemy + error when a project id was not specified.