Implements usage of '-c /--column' instead of additional logic.
"openstack share type list" and "openstack share access list" do not need a "--columns" option. The OSC client has inherent support for output filtering via the "-c/--column" options. Closes-Bug:#1899325 Change-Id: I6666e279e5ec97ced2e03aaf1eb88faec7408531
This commit is contained in:
parent
6673930aa4
commit
f98d4fa7d3
@ -164,13 +164,7 @@ class ListShareAccess(command.Lister):
|
||||
metavar="<share>",
|
||||
help=_('Name or ID of the share.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--columns',
|
||||
metavar="<columns>",
|
||||
default=None,
|
||||
help=_('Comma separated list of columns to be displayed. '
|
||||
'Example --columns "access_type,access_to".')
|
||||
)
|
||||
|
||||
# metadata --> properties in osc
|
||||
parser.add_argument(
|
||||
'--properties',
|
||||
@ -222,25 +216,10 @@ class ListShareAccess(command.Lister):
|
||||
list_of_keys.append('created_at')
|
||||
list_of_keys.append('updated_at')
|
||||
|
||||
if parsed_args.columns:
|
||||
columns = parsed_args.columns.split(',')
|
||||
for column in columns:
|
||||
if column not in list_of_keys:
|
||||
msg = ("No column named '%s'. Possible columns are: "
|
||||
"'id', 'access_type', 'access_to', "
|
||||
"'access_level', 'state', "
|
||||
"'access_key'(API microversion 2.21 and beyond), "
|
||||
"'created_at'(API microversion 2.33 and beyond), "
|
||||
"'updated_at'(API microversion 2.33 and beyond)."
|
||||
% column)
|
||||
raise exceptions.CommandError(msg)
|
||||
else:
|
||||
columns = list_of_keys
|
||||
|
||||
values = (oscutils.get_item_properties(
|
||||
a, columns) for a in access_list)
|
||||
a, list_of_keys) for a in access_list)
|
||||
|
||||
return (columns, values)
|
||||
return (list_of_keys, values)
|
||||
|
||||
|
||||
class ShowShareAccess(command.ShowOne):
|
||||
|
@ -392,12 +392,6 @@ class ListShareType(command.Lister):
|
||||
'Available only for API microversion >= 2.43. '
|
||||
'OPTIONAL: Default=None.'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--columns',
|
||||
metavar='<columns>',
|
||||
help=_('Comma separated list of columns to be displayed '
|
||||
'example --columns "id,name".'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -420,26 +414,14 @@ class ListShareType(command.Lister):
|
||||
search_opts=search_opts,
|
||||
show_all=parsed_args.all)
|
||||
|
||||
if parsed_args.columns:
|
||||
columns = parsed_args.columns.split(',')
|
||||
for column in columns:
|
||||
if column not in ATTRIBUTES:
|
||||
msg = ("No column named '%s'. "
|
||||
"Possible columns are: 'id', 'name', 'visibility', "
|
||||
"is_default', 'required_extra_specs', "
|
||||
"'optional_extra_specs', 'description'." % column)
|
||||
raise exceptions.CommandError(msg)
|
||||
else:
|
||||
columns = ATTRIBUTES
|
||||
|
||||
formatted_types = []
|
||||
for share_type in share_types:
|
||||
formatted_types.append(format_share_type(share_type))
|
||||
|
||||
values = (oscutils.get_dict_properties(
|
||||
s._info, columns) for s in formatted_types)
|
||||
s._info, ATTRIBUTES) for s in formatted_types)
|
||||
|
||||
return (columns, values)
|
||||
return (ATTRIBUTES, values)
|
||||
|
||||
|
||||
class ShowShareType(command.ShowOne):
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
The commands "openstack share type list" and
|
||||
"openstack share access list" no longer support
|
||||
the "--columns" option.
|
||||
Use "--column" to filter the output.
|
||||
|
@ -236,33 +236,6 @@ class TestShareAccessList(TestShareAccess):
|
||||
self.assertEqual(self.access_rules_columns, columns)
|
||||
self.assertEqual(tuple(self.values_list), tuple(data))
|
||||
|
||||
def test_access_rules_list_columns(self):
|
||||
expected_columns = [
|
||||
'id',
|
||||
'access_to'
|
||||
]
|
||||
|
||||
expected_data = (oscutils.get_dict_properties(
|
||||
a._info, expected_columns) for a in self.access_rules)
|
||||
|
||||
arglist = [
|
||||
self.share.id,
|
||||
'--columns', 'id,access_to'
|
||||
]
|
||||
verifylist = [
|
||||
("share", self.share.id),
|
||||
('columns', 'id,access_to')
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.shares_mock.get.assert_called_with(self.share.id)
|
||||
self.access_rules_mock.access_list.assert_called_with(
|
||||
self.share,
|
||||
{})
|
||||
self.assertEqual(expected_columns, columns)
|
||||
self.assertEqual(tuple(expected_data), tuple(data))
|
||||
|
||||
|
||||
class TestShareAccessShow(TestShareAccess):
|
||||
|
||||
|
@ -510,30 +510,6 @@ class TestShareTypeList(TestShareType):
|
||||
self.assertEqual(COLUMNS, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_share_type_list_columns(self):
|
||||
arglist = [
|
||||
'--columns', 'id,name'
|
||||
]
|
||||
verifylist = [
|
||||
('columns', 'id,name')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
arg_columns = [
|
||||
'id',
|
||||
'name'
|
||||
]
|
||||
arg_columns_data = (oscutils.get_item_properties(
|
||||
s, arg_columns) for s in self.share_types)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.shares_mock.list.assert_called_once_with(
|
||||
search_opts={},
|
||||
show_all=False)
|
||||
self.assertEqual(arg_columns, columns)
|
||||
self.assertEqual(list(arg_columns_data), list(data))
|
||||
|
||||
def test_share_type_list_api_versions_exception(self):
|
||||
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||
"2.42")
|
||||
@ -549,19 +525,6 @@ class TestShareTypeList(TestShareType):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_share_type_list_columns_invalid_value(self):
|
||||
arglist = [
|
||||
'--columns', 'invalid_column_name'
|
||||
]
|
||||
verifylist = [
|
||||
('columns', 'invalid_column_name')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestShareTypeShow(TestShareType):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user