From 532aef0c738edc937dbfa1b54efd8d7773af2204 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Wed, 26 Dec 2018 07:26:10 +0000 Subject: [PATCH] Fix: cinder group-list not working with non-admin user The all_tenants filter is passed to API when it's value is 0 (when not specified) which shouldn't be the case. This patch only allows adding of all_tenants when specified manually by user. Change-Id: Ic7810c4d6e9f4be7c28c7a8778d57bb5ccb996a0 Closes-Bug: #1808621 Closes-Bug: #1808622 --- cinderclient/tests/unit/v3/test_shell.py | 16 ++++++++-------- cinderclient/v3/shell.py | 8 +++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index a5ed614b5..eaba63f9c 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -140,28 +140,28 @@ class ShellTest(utils.TestCase): {'command': 'group-list --filters name=456', 'expected': - '/groups/detail?all_tenants=0&name=456'}, + '/groups/detail?name=456'}, {'command': 'group-list --filters status=available', 'expected': - '/groups/detail?all_tenants=0&status=available'}, + '/groups/detail?status=available'}, {'command': 'group-list --filters name~=456', 'expected': - '/groups/detail?all_tenants=0&name~=456'}, + '/groups/detail?name~=456'}, # testcases for list group-snapshot {'command': 'group-snapshot-list --status=error --filters status=available', 'expected': - '/group_snapshots/detail?all_tenants=0&status=available'}, + '/group_snapshots/detail?status=available'}, {'command': 'group-snapshot-list --filters availability_zone=123', 'expected': - '/group_snapshots/detail?all_tenants=0&availability_zone=123'}, + '/group_snapshots/detail?availability_zone=123'}, {'command': 'group-snapshot-list --filters status~=available', 'expected': - '/group_snapshots/detail?all_tenants=0&status~=available'}, + '/group_snapshots/detail?status~=available'}, # testcases for list message {'command': 'message-list --event_id=123 --filters event_id=456', @@ -632,7 +632,7 @@ class ShellTest(utils.TestCase): def test_group_list(self): self.run_command('--os-volume-api-version 3.13 group-list') - self.assert_called_anytime('GET', '/groups/detail?all_tenants=0') + self.assert_called_anytime('GET', '/groups/detail') def test_group_list__with_all_tenant(self): self.run_command( @@ -692,7 +692,7 @@ class ShellTest(utils.TestCase): def test_group_snapshot_list(self): self.run_command('--os-volume-api-version 3.14 group-snapshot-list') self.assert_called_anytime('GET', - '/group_snapshots/detail?all_tenants=0') + '/group_snapshots/detail') def test_group_snapshot_show(self): self.run_command('--os-volume-api-version 3.14 ' diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 1de0a3f9d..3573ff257 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -1291,7 +1291,7 @@ def do_manageable_list(cs, args): nargs='?', type=int, const=1, - default=utils.env('ALL_TENANTS', default=0), + default=utils.env('ALL_TENANTS', default=None), help='Shows details for all tenants. Admin only.') @utils.arg('--filters', type=six.text_type, @@ -1566,7 +1566,7 @@ def do_group_list_replication_targets(cs, args): nargs='?', type=int, const=1, - default=0, + default=utils.env('ALL_TENANTS', default=None), help='Shows details for all tenants. Admin only.') @utils.arg('--status', metavar='', @@ -1590,10 +1590,8 @@ def do_group_list_replication_targets(cs, args): def do_group_snapshot_list(cs, args): """Lists all group snapshots.""" - all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) - search_opts = { - 'all_tenants': all_tenants, + 'all_tenants': args.all_tenants, 'status': args.status, 'group_id': args.group_id, }