Skip to content

Commit cc4ede8

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add --default option to "volume type list""
2 parents 3ff713f + d083ddb commit cc4ede8

5 files changed

Lines changed: 64 additions & 12 deletions

File tree

doc/source/command-objects/volume-type.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ List volume types
8787
8888
os volume type list
8989
[--long]
90-
[--public | --private]
90+
[--default | --public | --private]
9191
9292
.. option:: --long
9393

@@ -105,6 +105,12 @@ List volume types
105105

106106
*Volume version 2 only*
107107

108+
.. option:: --default
109+
110+
List the default volume type
111+
112+
*Volume version 2 only*
113+
108114
volume type set
109115
---------------
110116

openstackclient/tests/functional/volume/v2/test_volume_type.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def test_volume_type_list(self):
4242
raw_output = self.openstack('volume type list' + opts)
4343
self.assertIn(self.NAME, raw_output)
4444

45+
def test_volume_type_list_default(self):
46+
opts = self.get_opts(self.HEADERS)
47+
raw_output = self.openstack('volume type list --default' + opts)
48+
self.assertEqual("lvmdriver-1\n", raw_output)
49+
4550
def test_volume_type_show(self):
4651
opts = self.get_opts(self.FIELDS)
4752
raw_output = self.openstack('volume type show ' + self.NAME + opts)

openstackclient/tests/unit/volume/v2/test_type.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ class TestTypeList(TestType):
172172
"Description",
173173
"Properties"
174174
]
175-
175+
data_with_default_type = [(
176+
volume_types[0].id,
177+
volume_types[0].name,
178+
True
179+
)]
176180
data = []
177181
for t in volume_types:
178182
data.append((
@@ -194,6 +198,7 @@ def setUp(self):
194198
super(TestTypeList, self).setUp()
195199

196200
self.types_mock.list.return_value = self.volume_types
201+
self.types_mock.default.return_value = self.volume_types[0]
197202
# get the command to test
198203
self.cmd = volume_type.ListVolumeType(self.app, None)
199204

@@ -203,6 +208,7 @@ def test_type_list_without_options(self):
203208
("long", False),
204209
("private", False),
205210
("public", False),
211+
("default", False),
206212
]
207213
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
208214

@@ -220,6 +226,7 @@ def test_type_list_with_options(self):
220226
("long", True),
221227
("private", False),
222228
("public", True),
229+
("default", False),
223230
]
224231
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
225232

@@ -236,6 +243,7 @@ def test_type_list_with_private_option(self):
236243
("long", False),
237244
("private", True),
238245
("public", False),
246+
("default", False),
239247
]
240248
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
241249

@@ -244,6 +252,23 @@ def test_type_list_with_private_option(self):
244252
self.assertEqual(self.columns, columns)
245253
self.assertEqual(self.data, list(data))
246254

255+
def test_type_list_with_default_option(self):
256+
arglist = [
257+
"--default",
258+
]
259+
verifylist = [
260+
("long", False),
261+
("private", False),
262+
("public", False),
263+
("default", True),
264+
]
265+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
266+
267+
columns, data = self.cmd.take_action(parsed_args)
268+
self.types_mock.default.assert_called_once_with()
269+
self.assertEqual(self.columns, columns)
270+
self.assertEqual(self.data_with_default_type, list(data))
271+
247272

248273
class TestTypeSet(TestType):
249274

openstackclient/volume/v2/volume_type.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,15 @@ def get_parser(self, prog_name):
160160
'--long',
161161
action='store_true',
162162
default=False,
163-
help=_('List additional fields in output'))
163+
help=_('List additional fields in output')
164+
)
164165
public_group = parser.add_mutually_exclusive_group()
166+
public_group.add_argument(
167+
"--default",
168+
action='store_true',
169+
default=False,
170+
help=_('List the default volume type')
171+
)
165172
public_group.add_argument(
166173
"--public",
167174
action="store_true",
@@ -175,21 +182,24 @@ def get_parser(self, prog_name):
175182
return parser
176183

177184
def take_action(self, parsed_args):
185+
volume_client = self.app.client_manager.volume
178186
if parsed_args.long:
179187
columns = ['ID', 'Name', 'Is Public', 'Description', 'Extra Specs']
180188
column_headers = [
181189
'ID', 'Name', 'Is Public', 'Description', 'Properties']
182190
else:
183191
columns = ['ID', 'Name', 'Is Public']
184192
column_headers = columns
185-
186-
is_public = None
187-
if parsed_args.public:
188-
is_public = True
189-
if parsed_args.private:
190-
is_public = False
191-
data = self.app.client_manager.volume.volume_types.list(
192-
is_public=is_public)
193+
if parsed_args.default:
194+
data = [volume_client.volume_types.default()]
195+
else:
196+
is_public = None
197+
if parsed_args.public:
198+
is_public = True
199+
if parsed_args.private:
200+
is_public = False
201+
data = volume_client.volume_types.list(
202+
is_public=is_public)
193203
return (column_headers,
194204
(utils.get_item_properties(
195205
s, columns,
@@ -240,7 +250,6 @@ def take_action(self, parsed_args):
240250

241251
volume_type = utils.find_resource(
242252
volume_client.volume_types, parsed_args.volume_type)
243-
244253
result = 0
245254
kwargs = {}
246255
if parsed_args.name:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add ``--default`` option to ``volume type list`` command, in
5+
order to show which volume type the volume sets as it's
6+
default.
7+
[Blueprint :oscbp:`cinder-command-support`]

0 commit comments

Comments
 (0)