Consistency of the --all argument for snapshots

This change is inspired by the volume.py.
It allow the user to use openstack snapshot list --all.

Closes-Bug: #1517386

Change-Id: I72a53fcd0c5c5af539cd88b37e71b4331fa67473
This commit is contained in:
Jean-Philippe Evrard 2015-11-18 10:50:34 +01:00
parent 12cc6347e5
commit 9168373b3d
4 changed files with 61 additions and 3 deletions

View File

@ -60,6 +60,11 @@ List snapshots
.. code:: bash
os snapshot list
[--all-projects]
.. option:: --all-projects
Include all projects (admin only)
.. option:: --long

View File

@ -225,6 +225,7 @@ class TestSnapshotList(TestSnapshot):
def test_snapshot_list_without_options(self):
arglist = []
verifylist = [
('all_projects', False),
("long", False)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -243,7 +244,7 @@ class TestSnapshotList(TestSnapshot):
def test_snapshot_list_with_options(self):
arglist = ["--long"]
verifylist = [("long", True)]
verifylist = [("long", True), ('all_projects', False)]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
@ -263,3 +264,33 @@ class TestSnapshotList(TestSnapshot):
volume_fakes.EXPECTED_SNAPSHOT.get("properties")
),)
self.assertEqual(datalist, tuple(data))
def test_snapshot_list_all_projects(self):
arglist = [
'--all-projects',
]
verifylist = [
('long', False),
('all_projects', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
collist = [
"ID",
"Name",
"Description",
"Status",
"Size"
]
self.assertEqual(collist, columns)
datalist = ((
volume_fakes.snapshot_id,
volume_fakes.snapshot_name,
volume_fakes.snapshot_description,
"available",
volume_fakes.snapshot_size
), )
self.assertEqual(datalist, tuple(data))

View File

@ -110,6 +110,12 @@ class ListSnapshot(lister.Lister):
def get_parser(self, prog_name):
parser = super(ListSnapshot, self).get_parser(prog_name)
parser.add_argument(
'--all-projects',
action='store_true',
default=False,
help='Include all projects (admin only)',
)
parser.add_argument(
'--long',
action='store_true',
@ -157,7 +163,12 @@ class ListSnapshot(lister.Lister):
# Just forget it if there's any trouble
pass
data = self.app.client_manager.volume.volume_snapshots.list()
search_opts = {
'all_tenants': parsed_args.all_projects,
}
data = self.app.client_manager.volume.volume_snapshots.list(
search_opts=search_opts)
return (column_headers,
(utils.get_item_properties(
s, columns,

View File

@ -107,6 +107,12 @@ class ListSnapshot(lister.Lister):
def get_parser(self, prog_name):
parser = super(ListSnapshot, self).get_parser(prog_name)
parser.add_argument(
'--all-projects',
action='store_true',
default=False,
help='Include all projects (admin only)',
)
parser.add_argument(
'--long',
action='store_true',
@ -149,7 +155,12 @@ class ListSnapshot(lister.Lister):
# Just forget it if there's any trouble
pass
data = self.app.client_manager.volume.volume_snapshots.list()
search_opts = {
'all_tenants': parsed_args.all_projects,
}
data = self.app.client_manager.volume.volume_snapshots.list(
search_opts=search_opts)
return (column_headers,
(utils.get_item_properties(
s, columns,