Add --default option to "volume type list"

Add "--default" option to volume v2's "type list"
command, it will show which volume type the volume
service has set as default.

Implements: bp cinder-command-support
Change-Id: Iae7ebc633ebe5554cc88390a84361887ec211fb2
This commit is contained in:
jiahui.qiang 2016-11-13 06:15:13 +08:00
parent 60370b46f5
commit d083ddb12f
5 changed files with 64 additions and 12 deletions

View File

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

View File

@ -42,6 +42,11 @@ class VolumeTypeTests(common.BaseVolumeTests):
raw_output = self.openstack('volume type list' + opts)
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):
opts = self.get_opts(self.FIELDS)
raw_output = self.openstack('volume type show ' + self.NAME + opts)

View File

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

View File

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