Merge "Add options to "volume type list" command"

This commit is contained in:
Jenkins 2016-07-26 10:53:40 +00:00 committed by Gerrit Code Review
commit 6da7a127af
4 changed files with 67 additions and 4 deletions

View File

@ -87,11 +87,24 @@ List volume types
os volume type list
[--long]
[--public | --private]
.. option:: --long
List additional fields in output
.. option:: --public
List only public types
*Volume version 2 only*
.. option:: --private
List only private types (admin only)
*Volume version 2 only*
volume type set
---------------

View File

@ -199,23 +199,50 @@ class TestTypeList(TestType):
def test_type_list_without_options(self):
arglist = []
verifylist = [
("long", False)
("long", False),
("private", False),
("public", False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=None)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_type_list_with_options(self):
arglist = ["--long"]
verifylist = [("long", True)]
arglist = [
"--long",
"--public",
]
verifylist = [
("long", True),
("private", False),
("public", True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=True)
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
def test_type_list_with_private_option(self):
arglist = [
"--private",
]
verifylist = [
("long", False),
("private", True),
("public", False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=False)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestTypeSet(TestType):

View File

@ -160,6 +160,17 @@ class ListVolumeType(command.Lister):
action='store_true',
default=False,
help=_('List additional fields in output'))
public_group = parser.add_mutually_exclusive_group()
public_group.add_argument(
"--public",
action="store_true",
help=_("List only public types")
)
public_group.add_argument(
"--private",
action="store_true",
help=_("List only private types (admin only)")
)
return parser
def take_action(self, parsed_args):
@ -169,7 +180,14 @@ class ListVolumeType(command.Lister):
else:
columns = ['ID', 'Name']
column_headers = columns
data = self.app.client_manager.volume.volume_types.list()
is_public = None
if parsed_args.public:
is_public = True
if parsed_args.private:
is_public = False
data = self.app.client_manager.volume.volume_types.list(
is_public=is_public)
return (column_headers,
(utils.get_item_properties(
s, columns,

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``--public`` and ``--private`` options to ``volume type list`` command.
[Bug `1597198 <https://bugs.launchpad.net/bugs/1597198>`_]