Merge "Add --default option to "volume type list""

This commit is contained in:
Jenkins 2016-12-18 12:20:28 +00:00 committed by Gerrit Code Review
commit cc4ede88e9
5 changed files with 64 additions and 12 deletions

View File

@ -87,7 +87,7 @@ List volume types
os volume type list os volume type list
[--long] [--long]
[--public | --private] [--default | --public | --private]
.. option:: --long .. option:: --long
@ -105,6 +105,12 @@ List volume types
*Volume version 2 only* *Volume version 2 only*
.. option:: --default
List the default volume type
*Volume version 2 only*
volume type set volume type set
--------------- ---------------

View File

@ -42,6 +42,11 @@ class VolumeTypeTests(common.BaseVolumeTests):
raw_output = self.openstack('volume type list' + opts) raw_output = self.openstack('volume type list' + opts)
self.assertIn(self.NAME, raw_output) self.assertIn(self.NAME, raw_output)
def test_volume_type_list_default(self):
opts = self.get_opts(self.HEADERS)
raw_output = self.openstack('volume type list --default' + opts)
self.assertEqual("lvmdriver-1\n", raw_output)
def test_volume_type_show(self): def test_volume_type_show(self):
opts = self.get_opts(self.FIELDS) opts = self.get_opts(self.FIELDS)
raw_output = self.openstack('volume type show ' + self.NAME + opts) raw_output = self.openstack('volume type show ' + self.NAME + opts)

View File

@ -172,7 +172,11 @@ class TestTypeList(TestType):
"Description", "Description",
"Properties" "Properties"
] ]
data_with_default_type = [(
volume_types[0].id,
volume_types[0].name,
True
)]
data = [] data = []
for t in volume_types: for t in volume_types:
data.append(( data.append((
@ -194,6 +198,7 @@ class TestTypeList(TestType):
super(TestTypeList, self).setUp() super(TestTypeList, self).setUp()
self.types_mock.list.return_value = self.volume_types self.types_mock.list.return_value = self.volume_types
self.types_mock.default.return_value = self.volume_types[0]
# get the command to test # get the command to test
self.cmd = volume_type.ListVolumeType(self.app, None) self.cmd = volume_type.ListVolumeType(self.app, None)
@ -203,6 +208,7 @@ class TestTypeList(TestType):
("long", False), ("long", False),
("private", False), ("private", False),
("public", False), ("public", False),
("default", False),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -220,6 +226,7 @@ class TestTypeList(TestType):
("long", True), ("long", True),
("private", False), ("private", False),
("public", True), ("public", True),
("default", False),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -236,6 +243,7 @@ class TestTypeList(TestType):
("long", False), ("long", False),
("private", True), ("private", True),
("public", False), ("public", False),
("default", False),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -244,6 +252,23 @@ class TestTypeList(TestType):
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data)) self.assertEqual(self.data, list(data))
def test_type_list_with_default_option(self):
arglist = [
"--default",
]
verifylist = [
("long", False),
("private", False),
("public", False),
("default", True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.default.assert_called_once_with()
self.assertEqual(self.columns, columns)
self.assertEqual(self.data_with_default_type, list(data))
class TestTypeSet(TestType): class TestTypeSet(TestType):

View File

@ -160,8 +160,15 @@ class ListVolumeType(command.Lister):
'--long', '--long',
action='store_true', action='store_true',
default=False, default=False,
help=_('List additional fields in output')) help=_('List additional fields in output')
)
public_group = parser.add_mutually_exclusive_group() public_group = parser.add_mutually_exclusive_group()
public_group.add_argument(
"--default",
action='store_true',
default=False,
help=_('List the default volume type')
)
public_group.add_argument( public_group.add_argument(
"--public", "--public",
action="store_true", action="store_true",
@ -175,6 +182,7 @@ class ListVolumeType(command.Lister):
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
volume_client = self.app.client_manager.volume
if parsed_args.long: if parsed_args.long:
columns = ['ID', 'Name', 'Is Public', 'Description', 'Extra Specs'] columns = ['ID', 'Name', 'Is Public', 'Description', 'Extra Specs']
column_headers = [ column_headers = [
@ -182,14 +190,16 @@ class ListVolumeType(command.Lister):
else: else:
columns = ['ID', 'Name', 'Is Public'] columns = ['ID', 'Name', 'Is Public']
column_headers = columns column_headers = columns
if parsed_args.default:
is_public = None data = [volume_client.volume_types.default()]
if parsed_args.public: else:
is_public = True is_public = None
if parsed_args.private: if parsed_args.public:
is_public = False is_public = True
data = self.app.client_manager.volume.volume_types.list( if parsed_args.private:
is_public=is_public) is_public = False
data = volume_client.volume_types.list(
is_public=is_public)
return (column_headers, return (column_headers,
(utils.get_item_properties( (utils.get_item_properties(
s, columns, s, columns,
@ -240,7 +250,6 @@ class SetVolumeType(command.Command):
volume_type = utils.find_resource( volume_type = utils.find_resource(
volume_client.volume_types, parsed_args.volume_type) volume_client.volume_types, parsed_args.volume_type)
result = 0 result = 0
kwargs = {} kwargs = {}
if parsed_args.name: if parsed_args.name:

View File

@ -0,0 +1,7 @@
---
features:
- |
Add ``--default`` option to ``volume type list`` command, in
order to show which volume type the volume sets as it's
default.
[Blueprint :oscbp:`cinder-command-support`]