snapshot-list now supports filtering by tenant

Admin can now filter snapshots on the basis of tenant.
No changes are needed on server side since snapshot model contains
project_id as a column which means that it supports native filtering
by tenant (i.e, project) via SQL.

This closely follows similar functionality for volume listing added in
the change-id - fa8c7e3d84

DocImpact
After this patch is merged we need to regenerate the CLI reference
guide so that the added documentation for the new option
"--tenant <tenant_id>" for "cinder snapshot-list" command gets
included.

Change-Id: I0bbd8e0b4aaf25da738c67638fb497337ead312b
Co-Authored-By: wuyuting <wytdahu@gmail.com>
This commit is contained in:
Deepti Ramakrishna
2016-02-27 22:13:49 -08:00
parent 580ed3f680
commit 20c0421857
2 changed files with 19 additions and 1 deletions

View File

@@ -475,6 +475,16 @@ class ShellTest(utils.TestCase):
mock_print_list.assert_called_once_with(mock.ANY, columns,
sortby_index=None)
def test_snapshot_list_filter_tenant_with_all_tenants(self):
self.run_command('snapshot-list --all-tenants=1 --tenant 123')
self.assert_called('GET',
'/snapshots/detail?all_tenants=1&project_id=123')
def test_snapshot_list_filter_tenant_without_all_tenants(self):
self.run_command('snapshot-list --tenant 123')
self.assert_called('GET',
'/snapshots/detail?all_tenants=1&project_id=123')
def test_rename(self):
# basic rename with positional arguments
self.run_command('rename 1234 new-name')

View File

@@ -665,10 +665,17 @@ def do_image_metadata(cs, args):
'form of <key>[:<asc|desc>]. '
'Valid keys: %s. '
'Default=None.') % ', '.join(base.SORT_KEY_VALUES)))
@utils.arg('--tenant',
type=str,
dest='tenant',
nargs='?',
metavar='<tenant>',
help='Display information from single tenant (Admin only).')
@utils.service_type('volumev2')
def do_snapshot_list(cs, args):
"""Lists all snapshots."""
all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants))
all_tenants = (1 if args.tenant else
int(os.environ.get("ALL_TENANTS", args.all_tenants)))
if args.display_name is not None:
args.name = args.display_name
@@ -678,6 +685,7 @@ def do_snapshot_list(cs, args):
'display_name': args.name,
'status': args.status,
'volume_id': args.volume_id,
'project_id': args.tenant,
}
snapshots = cs.volume_snapshots.list(search_opts=search_opts,