Added 'description' in share type
This fix adds attr 'description' in list/create share type. Change-Id: I39705acbfca812b66d73fbd2fee228a7a85bc2d7 Closes-Bug: #1724183
This commit is contained in:
parent
8ff56c8d95
commit
8e8a3e7b71
@ -176,20 +176,24 @@ class BaseTestCase(base.ClientTestBase):
|
||||
create_share_from_snapshot=None,
|
||||
revert_to_snapshot=None, mount_snapshot=None,
|
||||
is_public=True, client=None, cleanup_in_class=True,
|
||||
microversion=None, extra_specs=None):
|
||||
microversion=None, extra_specs=None,
|
||||
description=None):
|
||||
if client is None:
|
||||
client = cls.get_admin_client()
|
||||
share_type = client.create_share_type(
|
||||
name=name,
|
||||
driver_handles_share_servers=driver_handles_share_servers,
|
||||
snapshot_support=snapshot_support,
|
||||
is_public=is_public,
|
||||
microversion=microversion,
|
||||
extra_specs=extra_specs,
|
||||
create_share_from_snapshot=create_share_from_snapshot,
|
||||
revert_to_snapshot=revert_to_snapshot,
|
||||
mount_snapshot=mount_snapshot,
|
||||
)
|
||||
data = {
|
||||
"name": name,
|
||||
"driver_handles_share_servers": driver_handles_share_servers,
|
||||
"snapshot_support": snapshot_support,
|
||||
"is_public": is_public,
|
||||
"microversion": microversion,
|
||||
"extra_specs": extra_specs,
|
||||
"create_share_from_snapshot": create_share_from_snapshot,
|
||||
"revert_to_snapshot": revert_to_snapshot,
|
||||
"mount_snapshot": mount_snapshot,
|
||||
}
|
||||
if description:
|
||||
data["description"] = description
|
||||
share_type = client.create_share_type(**data)
|
||||
resource = {
|
||||
"type": "share_type",
|
||||
"id": share_type["ID"],
|
||||
|
@ -170,11 +170,14 @@ class ManilaCLIClient(base.CLIClient):
|
||||
snapshot_support=None,
|
||||
create_share_from_snapshot=None,
|
||||
revert_to_snapshot=None, mount_snapshot=None,
|
||||
is_public=True, microversion=None, extra_specs=None):
|
||||
is_public=True, microversion=None, extra_specs=None,
|
||||
description=None):
|
||||
"""Creates share type.
|
||||
|
||||
:param name: text -- name of share type to use, if not set then
|
||||
autogenerated will be used
|
||||
:param description: text -- description of share type to use.
|
||||
Default is None.
|
||||
:param driver_handles_share_servers: bool/str -- boolean or its
|
||||
string alias. Default is True.
|
||||
:param snapshot_support: bool/str -- boolean or its
|
||||
@ -199,6 +202,9 @@ class ManilaCLIClient(base.CLIClient):
|
||||
cmd = ('type-create %(name)s %(dhss)s --is-public %(is_public)s ') % {
|
||||
'name': name, 'dhss': dhss, 'is_public': is_public}
|
||||
|
||||
if description is not None:
|
||||
cmd += " --description " + description
|
||||
|
||||
if snapshot_support is not None:
|
||||
if not isinstance(snapshot_support, six.string_types):
|
||||
snapshot_support = six.text_type(snapshot_support)
|
||||
|
@ -116,12 +116,19 @@ class ShareTypesReadWriteTest(base.BaseTestCase):
|
||||
spec_create_share_from_snapshot, spec_revert_to_snapshot_support,
|
||||
None, extra_specs)
|
||||
|
||||
def test_create_delete_share_type_with_description(self):
|
||||
self.skip_if_microversion_not_supported('2.41')
|
||||
self._test_create_delete_share_type(
|
||||
'2.41', True, False, None, None, None, None, None,
|
||||
description=data_utils.rand_name('test_share_type_description'))
|
||||
|
||||
def _test_create_delete_share_type(self, microversion, is_public, dhss,
|
||||
spec_snapshot_support,
|
||||
spec_create_share_from_snapshot,
|
||||
spec_revert_to_snapshot_support,
|
||||
spec_mount_snapshot_support,
|
||||
extra_specs):
|
||||
extra_specs,
|
||||
description=None):
|
||||
|
||||
share_type_name = data_utils.rand_name('manilaclient_functional_test')
|
||||
|
||||
@ -138,7 +145,8 @@ class ShareTypesReadWriteTest(base.BaseTestCase):
|
||||
mount_snapshot=spec_mount_snapshot_support,
|
||||
is_public=is_public,
|
||||
microversion=microversion,
|
||||
extra_specs=extra_specs)
|
||||
extra_specs=extra_specs,
|
||||
description=description)
|
||||
|
||||
# Verify response body
|
||||
for key in self.create_keys:
|
||||
@ -147,6 +155,13 @@ class ShareTypesReadWriteTest(base.BaseTestCase):
|
||||
# Verify type name
|
||||
self.assertEqual(share_type_name, share_type['Name'])
|
||||
|
||||
# Verify type description
|
||||
if (api_versions.APIVersion(microversion) >=
|
||||
api_versions.APIVersion('2.41')):
|
||||
self.assertEqual(description, share_type['Description'])
|
||||
else:
|
||||
self.assertNotIn('description', share_type)
|
||||
|
||||
# Verify required DHSS extra spec
|
||||
dhss_expected = 'driver_handles_share_servers : %s' % dhss
|
||||
self.assertEqual(dhss_expected, share_type['required_extra_specs'])
|
||||
|
@ -886,6 +886,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
||||
'share_type': {
|
||||
'id': 3,
|
||||
'name': 'test-type-3',
|
||||
'description': 'test description',
|
||||
'extra_specs': share_type['extra_specs'],
|
||||
'required_extra_specs': required_extra_specs,
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ class ShellTest(test_utils.TestCase):
|
||||
cliutils.print_list.assert_called_once_with(
|
||||
mock.ANY,
|
||||
['ID', 'Name', 'visibility', 'is_default', 'required_extra_specs',
|
||||
'optional_extra_specs'],
|
||||
'optional_extra_specs', 'Description'],
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
||||
@ -957,6 +957,31 @@ class ShellTest(test_utils.TestCase):
|
||||
|
||||
self.assert_called('POST', '/types', body=expected)
|
||||
|
||||
def test_type_create_with_description(self):
|
||||
expected = {
|
||||
"share_type": {
|
||||
"name": "test",
|
||||
"description": "test_description",
|
||||
"share_type_access:is_public": True,
|
||||
"extra_specs": {
|
||||
"driver_handles_share_servers": False,
|
||||
}
|
||||
}
|
||||
}
|
||||
self.run_command('type-create test false '
|
||||
'--description test_description', version='2.41')
|
||||
|
||||
self.assert_called('POST', '/types', body=expected)
|
||||
|
||||
@ddt.data('2.26', '2.40')
|
||||
def test_type_create_invalid_description_version(self, version):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.run_command,
|
||||
'type-create test false --description test_description',
|
||||
version=version
|
||||
)
|
||||
|
||||
@ddt.unpack
|
||||
@ddt.data(
|
||||
*([{'expected_bool': True, 'text': v}
|
||||
|
@ -364,9 +364,11 @@ class TypesTest(utils.TestCase):
|
||||
("2.6", True),
|
||||
("2.7", True),
|
||||
("2.24", True),
|
||||
("2.41", True),
|
||||
("2.6", False),
|
||||
("2.7", False),
|
||||
("2.24", False),
|
||||
("2.41", False),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_create_with_default_values(self, microversion, dhss):
|
||||
@ -374,7 +376,13 @@ class TypesTest(utils.TestCase):
|
||||
manager = self._get_share_types_manager(microversion)
|
||||
self.mock_object(manager, '_create', mock.Mock(return_value="fake"))
|
||||
|
||||
result = manager.create('test-type-3', dhss)
|
||||
description = 'test description'
|
||||
if (api_versions.APIVersion(microversion) >=
|
||||
api_versions.APIVersion("2.41")):
|
||||
result = manager.create(
|
||||
'test-type-3', dhss, description=description)
|
||||
else:
|
||||
result = manager.create('test-type-3', dhss)
|
||||
|
||||
if (api_versions.APIVersion(microversion) >
|
||||
api_versions.APIVersion("2.6")):
|
||||
@ -397,6 +405,9 @@ class TypesTest(utils.TestCase):
|
||||
api_versions.APIVersion("2.24")):
|
||||
del expected_body['share_type']['extra_specs']['snapshot_support']
|
||||
|
||||
if (api_versions.APIVersion(microversion) >=
|
||||
api_versions.APIVersion("2.41")):
|
||||
expected_body['share_type']['description'] = description
|
||||
manager._create.assert_called_once_with(
|
||||
"/types", expected_body, "share_type")
|
||||
self.assertEqual("fake", result)
|
||||
|
@ -134,7 +134,8 @@ class ShareTypeManager(base.ManagerWithFind):
|
||||
self._delete("/types/%s" % common_base.getid(share_type))
|
||||
|
||||
def _do_create(self, name, extra_specs, is_public,
|
||||
is_public_keyname="share_type_access:is_public"):
|
||||
is_public_keyname="share_type_access:is_public",
|
||||
description=None):
|
||||
"""Create a share type.
|
||||
|
||||
:param name: Descriptive name of the share type
|
||||
@ -148,6 +149,9 @@ class ShareTypeManager(base.ManagerWithFind):
|
||||
"extra_specs": extra_specs,
|
||||
}
|
||||
}
|
||||
|
||||
if description:
|
||||
body["share_type"]["description"] = description
|
||||
return self._create("/types", body, "share_type")
|
||||
|
||||
@api_versions.wraps("1.0", "2.6")
|
||||
@ -180,7 +184,7 @@ class ShareTypeManager(base.ManagerWithFind):
|
||||
|
||||
return self._do_create(name, extra_specs, is_public)
|
||||
|
||||
@api_versions.wraps("2.24") # noqa
|
||||
@api_versions.wraps("2.24", "2.40") # noqa
|
||||
def create(self, name, spec_driver_handles_share_servers,
|
||||
spec_snapshot_support=None, is_public=True, extra_specs=None):
|
||||
|
||||
@ -193,6 +197,20 @@ class ShareTypeManager(base.ManagerWithFind):
|
||||
|
||||
return self._do_create(name, extra_specs, is_public)
|
||||
|
||||
@api_versions.wraps("2.41") # noqa
|
||||
def create(self, name, spec_driver_handles_share_servers,
|
||||
spec_snapshot_support=None, is_public=True, extra_specs=None,
|
||||
description=None):
|
||||
if extra_specs is None:
|
||||
extra_specs = {}
|
||||
|
||||
self._handle_spec_driver_handles_share_servers(
|
||||
extra_specs, spec_driver_handles_share_servers)
|
||||
self._handle_spec_snapshot_support(extra_specs, spec_snapshot_support)
|
||||
|
||||
return self._do_create(name, extra_specs, is_public,
|
||||
description=description)
|
||||
|
||||
def _handle_spec_driver_handles_share_servers(
|
||||
self, extra_specs, spec_driver_handles_share_servers):
|
||||
"""Validation and default for DHSS extra spec."""
|
||||
|
@ -3578,7 +3578,8 @@ def _is_share_type_public(share_type):
|
||||
return 'public' if share_type.is_public else 'private'
|
||||
|
||||
|
||||
def _print_share_type_list(stypes, default_share_type=None, columns=None):
|
||||
def _print_share_type_list(stypes, default_share_type=None, columns=None,
|
||||
description=False):
|
||||
|
||||
def _is_default(share_type):
|
||||
if share_type == default_share_type:
|
||||
@ -3605,13 +3606,15 @@ def _print_share_type_list(stypes, default_share_type=None, columns=None):
|
||||
'required_extra_specs',
|
||||
'optional_extra_specs',
|
||||
]
|
||||
if description:
|
||||
fields.append('Description')
|
||||
if columns is not None:
|
||||
fields = _split_columns(columns=columns, title=False)
|
||||
|
||||
cliutils.print_list(stypes, fields, formatters)
|
||||
|
||||
|
||||
def _print_share_type(stype, default_share_type=None):
|
||||
def _print_share_type(stype, default_share_type=None, show_des=False):
|
||||
|
||||
def _is_default(share_type):
|
||||
if share_type == default_share_type:
|
||||
@ -3627,6 +3630,8 @@ def _print_share_type(stype, default_share_type=None):
|
||||
'required_extra_specs': _print_type_required_extra_specs(stype),
|
||||
'optional_extra_specs': _print_type_optional_extra_specs(stype),
|
||||
}
|
||||
if show_des:
|
||||
stype_dict['Description'] = stype.description
|
||||
cliutils.print_dict(stype_dict)
|
||||
|
||||
|
||||
@ -3669,8 +3674,10 @@ def do_type_list(cs, args):
|
||||
default = None
|
||||
|
||||
stypes = cs.share_types.list(show_all=args.all)
|
||||
show_des = cs.api_version.matches(
|
||||
api_versions.APIVersion("2.41"), api_versions.APIVersion())
|
||||
_print_share_type_list(stypes, default_share_type=default,
|
||||
columns=args.columns)
|
||||
columns=args.columns, description=show_des)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
@ -3696,6 +3703,13 @@ def do_extra_specs_list(cs, args):
|
||||
type=str,
|
||||
help="Required extra specification. "
|
||||
"Valid values are 'true'/'1' and 'false'/'0'.")
|
||||
@cliutils.arg(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
type=str,
|
||||
default=None,
|
||||
help='Filter results by description. '
|
||||
'Available only for microversion >= 2.41.')
|
||||
@cliutils.arg(
|
||||
'--snapshot_support',
|
||||
'--snapshot-support',
|
||||
@ -3764,6 +3778,16 @@ def do_type_create(cs, args):
|
||||
"set via positional argument.")
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
show_des = False
|
||||
if cs.api_version.matches(api_versions.APIVersion("2.41"),
|
||||
api_versions.APIVersion()):
|
||||
show_des = True
|
||||
kwargs['description'] = getattr(args, 'description')
|
||||
elif getattr(args, 'description'):
|
||||
raise exceptions.CommandError(
|
||||
"Pattern based option (description)"
|
||||
" is only available with manila API version >= 2.41")
|
||||
|
||||
boolean_keys = (
|
||||
'snapshot_support',
|
||||
'create_share_from_snapshot_support',
|
||||
@ -3791,7 +3815,7 @@ def do_type_create(cs, args):
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
stype = cs.share_types.create(**kwargs)
|
||||
_print_share_type(stype)
|
||||
_print_share_type(stype, show_des=show_des)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
fixes:
|
||||
- Added description in list/create share type CLI.
|
Loading…
x
Reference in New Issue
Block a user