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
This commit is contained in:
whoami-rajat 2018-12-26 07:26:10 +00:00
parent 3c143d95b3
commit 532aef0c73
2 changed files with 11 additions and 13 deletions

View File

@ -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 '

View File

@ -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='<status>',
@ -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,
}