From 9168373b3d7502f0ebe7bca9097ee474bb8d6c5b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Wed, 18 Nov 2015 10:50:34 +0100 Subject: [PATCH] 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 --- doc/source/command-objects/snapshot.rst | 5 +++ .../tests/volume/v2/test_snapshot.py | 33 ++++++++++++++++++- openstackclient/volume/v1/snapshot.py | 13 +++++++- openstackclient/volume/v2/snapshot.py | 13 +++++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/doc/source/command-objects/snapshot.rst b/doc/source/command-objects/snapshot.rst index 7bfd1d9203..e05673b82e 100644 --- a/doc/source/command-objects/snapshot.rst +++ b/doc/source/command-objects/snapshot.rst @@ -60,6 +60,11 @@ List snapshots .. code:: bash os snapshot list + [--all-projects] + +.. option:: --all-projects + + Include all projects (admin only) .. option:: --long diff --git a/openstackclient/tests/volume/v2/test_snapshot.py b/openstackclient/tests/volume/v2/test_snapshot.py index 3ceb57faf2..3b30d4ef20 100644 --- a/openstackclient/tests/volume/v2/test_snapshot.py +++ b/openstackclient/tests/volume/v2/test_snapshot.py @@ -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)) diff --git a/openstackclient/volume/v1/snapshot.py b/openstackclient/volume/v1/snapshot.py index de7bb5b9ac..93e17eb8a6 100644 --- a/openstackclient/volume/v1/snapshot.py +++ b/openstackclient/volume/v1/snapshot.py @@ -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, diff --git a/openstackclient/volume/v2/snapshot.py b/openstackclient/volume/v2/snapshot.py index bbc92c4888..aa7630ae6e 100644 --- a/openstackclient/volume/v2/snapshot.py +++ b/openstackclient/volume/v2/snapshot.py @@ -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,