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:
@@ -176,20 +176,24 @@ class BaseTestCase(base.ClientTestBase):
|
|||||||
create_share_from_snapshot=None,
|
create_share_from_snapshot=None,
|
||||||
revert_to_snapshot=None, mount_snapshot=None,
|
revert_to_snapshot=None, mount_snapshot=None,
|
||||||
is_public=True, client=None, cleanup_in_class=True,
|
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:
|
if client is None:
|
||||||
client = cls.get_admin_client()
|
client = cls.get_admin_client()
|
||||||
share_type = client.create_share_type(
|
data = {
|
||||||
name=name,
|
"name": name,
|
||||||
driver_handles_share_servers=driver_handles_share_servers,
|
"driver_handles_share_servers": driver_handles_share_servers,
|
||||||
snapshot_support=snapshot_support,
|
"snapshot_support": snapshot_support,
|
||||||
is_public=is_public,
|
"is_public": is_public,
|
||||||
microversion=microversion,
|
"microversion": microversion,
|
||||||
extra_specs=extra_specs,
|
"extra_specs": extra_specs,
|
||||||
create_share_from_snapshot=create_share_from_snapshot,
|
"create_share_from_snapshot": create_share_from_snapshot,
|
||||||
revert_to_snapshot=revert_to_snapshot,
|
"revert_to_snapshot": revert_to_snapshot,
|
||||||
mount_snapshot=mount_snapshot,
|
"mount_snapshot": mount_snapshot,
|
||||||
)
|
}
|
||||||
|
if description:
|
||||||
|
data["description"] = description
|
||||||
|
share_type = client.create_share_type(**data)
|
||||||
resource = {
|
resource = {
|
||||||
"type": "share_type",
|
"type": "share_type",
|
||||||
"id": share_type["ID"],
|
"id": share_type["ID"],
|
||||||
|
@@ -170,11 +170,14 @@ class ManilaCLIClient(base.CLIClient):
|
|||||||
snapshot_support=None,
|
snapshot_support=None,
|
||||||
create_share_from_snapshot=None,
|
create_share_from_snapshot=None,
|
||||||
revert_to_snapshot=None, mount_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.
|
"""Creates share type.
|
||||||
|
|
||||||
:param name: text -- name of share type to use, if not set then
|
:param name: text -- name of share type to use, if not set then
|
||||||
autogenerated will be used
|
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
|
:param driver_handles_share_servers: bool/str -- boolean or its
|
||||||
string alias. Default is True.
|
string alias. Default is True.
|
||||||
:param snapshot_support: bool/str -- boolean or its
|
: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 ') % {
|
cmd = ('type-create %(name)s %(dhss)s --is-public %(is_public)s ') % {
|
||||||
'name': name, 'dhss': dhss, 'is_public': is_public}
|
'name': name, 'dhss': dhss, 'is_public': is_public}
|
||||||
|
|
||||||
|
if description is not None:
|
||||||
|
cmd += " --description " + description
|
||||||
|
|
||||||
if snapshot_support is not None:
|
if snapshot_support is not None:
|
||||||
if not isinstance(snapshot_support, six.string_types):
|
if not isinstance(snapshot_support, six.string_types):
|
||||||
snapshot_support = six.text_type(snapshot_support)
|
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,
|
spec_create_share_from_snapshot, spec_revert_to_snapshot_support,
|
||||||
None, extra_specs)
|
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,
|
def _test_create_delete_share_type(self, microversion, is_public, dhss,
|
||||||
spec_snapshot_support,
|
spec_snapshot_support,
|
||||||
spec_create_share_from_snapshot,
|
spec_create_share_from_snapshot,
|
||||||
spec_revert_to_snapshot_support,
|
spec_revert_to_snapshot_support,
|
||||||
spec_mount_snapshot_support,
|
spec_mount_snapshot_support,
|
||||||
extra_specs):
|
extra_specs,
|
||||||
|
description=None):
|
||||||
|
|
||||||
share_type_name = data_utils.rand_name('manilaclient_functional_test')
|
share_type_name = data_utils.rand_name('manilaclient_functional_test')
|
||||||
|
|
||||||
@@ -138,7 +145,8 @@ class ShareTypesReadWriteTest(base.BaseTestCase):
|
|||||||
mount_snapshot=spec_mount_snapshot_support,
|
mount_snapshot=spec_mount_snapshot_support,
|
||||||
is_public=is_public,
|
is_public=is_public,
|
||||||
microversion=microversion,
|
microversion=microversion,
|
||||||
extra_specs=extra_specs)
|
extra_specs=extra_specs,
|
||||||
|
description=description)
|
||||||
|
|
||||||
# Verify response body
|
# Verify response body
|
||||||
for key in self.create_keys:
|
for key in self.create_keys:
|
||||||
@@ -147,6 +155,13 @@ class ShareTypesReadWriteTest(base.BaseTestCase):
|
|||||||
# Verify type name
|
# Verify type name
|
||||||
self.assertEqual(share_type_name, share_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
|
# Verify required DHSS extra spec
|
||||||
dhss_expected = 'driver_handles_share_servers : %s' % dhss
|
dhss_expected = 'driver_handles_share_servers : %s' % dhss
|
||||||
self.assertEqual(dhss_expected, share_type['required_extra_specs'])
|
self.assertEqual(dhss_expected, share_type['required_extra_specs'])
|
||||||
|
@@ -886,6 +886,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient):
|
|||||||
'share_type': {
|
'share_type': {
|
||||||
'id': 3,
|
'id': 3,
|
||||||
'name': 'test-type-3',
|
'name': 'test-type-3',
|
||||||
|
'description': 'test description',
|
||||||
'extra_specs': share_type['extra_specs'],
|
'extra_specs': share_type['extra_specs'],
|
||||||
'required_extra_specs': required_extra_specs,
|
'required_extra_specs': required_extra_specs,
|
||||||
}
|
}
|
||||||
|
@@ -511,7 +511,7 @@ class ShellTest(test_utils.TestCase):
|
|||||||
cliutils.print_list.assert_called_once_with(
|
cliutils.print_list.assert_called_once_with(
|
||||||
mock.ANY,
|
mock.ANY,
|
||||||
['ID', 'Name', 'visibility', 'is_default', 'required_extra_specs',
|
['ID', 'Name', 'visibility', 'is_default', 'required_extra_specs',
|
||||||
'optional_extra_specs'],
|
'optional_extra_specs', 'Description'],
|
||||||
mock.ANY)
|
mock.ANY)
|
||||||
|
|
||||||
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
||||||
@@ -957,6 +957,31 @@ class ShellTest(test_utils.TestCase):
|
|||||||
|
|
||||||
self.assert_called('POST', '/types', body=expected)
|
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.unpack
|
||||||
@ddt.data(
|
@ddt.data(
|
||||||
*([{'expected_bool': True, 'text': v}
|
*([{'expected_bool': True, 'text': v}
|
||||||
|
@@ -364,9 +364,11 @@ class TypesTest(utils.TestCase):
|
|||||||
("2.6", True),
|
("2.6", True),
|
||||||
("2.7", True),
|
("2.7", True),
|
||||||
("2.24", True),
|
("2.24", True),
|
||||||
|
("2.41", True),
|
||||||
("2.6", False),
|
("2.6", False),
|
||||||
("2.7", False),
|
("2.7", False),
|
||||||
("2.24", False),
|
("2.24", False),
|
||||||
|
("2.41", False),
|
||||||
)
|
)
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
def test_create_with_default_values(self, microversion, dhss):
|
def test_create_with_default_values(self, microversion, dhss):
|
||||||
@@ -374,7 +376,13 @@ class TypesTest(utils.TestCase):
|
|||||||
manager = self._get_share_types_manager(microversion)
|
manager = self._get_share_types_manager(microversion)
|
||||||
self.mock_object(manager, '_create', mock.Mock(return_value="fake"))
|
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) >
|
if (api_versions.APIVersion(microversion) >
|
||||||
api_versions.APIVersion("2.6")):
|
api_versions.APIVersion("2.6")):
|
||||||
@@ -397,6 +405,9 @@ class TypesTest(utils.TestCase):
|
|||||||
api_versions.APIVersion("2.24")):
|
api_versions.APIVersion("2.24")):
|
||||||
del expected_body['share_type']['extra_specs']['snapshot_support']
|
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(
|
manager._create.assert_called_once_with(
|
||||||
"/types", expected_body, "share_type")
|
"/types", expected_body, "share_type")
|
||||||
self.assertEqual("fake", result)
|
self.assertEqual("fake", result)
|
||||||
|
@@ -134,7 +134,8 @@ class ShareTypeManager(base.ManagerWithFind):
|
|||||||
self._delete("/types/%s" % common_base.getid(share_type))
|
self._delete("/types/%s" % common_base.getid(share_type))
|
||||||
|
|
||||||
def _do_create(self, name, extra_specs, is_public,
|
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.
|
"""Create a share type.
|
||||||
|
|
||||||
:param name: Descriptive name of the share type
|
:param name: Descriptive name of the share type
|
||||||
@@ -148,6 +149,9 @@ class ShareTypeManager(base.ManagerWithFind):
|
|||||||
"extra_specs": extra_specs,
|
"extra_specs": extra_specs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if description:
|
||||||
|
body["share_type"]["description"] = description
|
||||||
return self._create("/types", body, "share_type")
|
return self._create("/types", body, "share_type")
|
||||||
|
|
||||||
@api_versions.wraps("1.0", "2.6")
|
@api_versions.wraps("1.0", "2.6")
|
||||||
@@ -180,7 +184,7 @@ class ShareTypeManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
return self._do_create(name, extra_specs, is_public)
|
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,
|
def create(self, name, spec_driver_handles_share_servers,
|
||||||
spec_snapshot_support=None, is_public=True, extra_specs=None):
|
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)
|
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(
|
def _handle_spec_driver_handles_share_servers(
|
||||||
self, extra_specs, spec_driver_handles_share_servers):
|
self, extra_specs, spec_driver_handles_share_servers):
|
||||||
"""Validation and default for DHSS extra spec."""
|
"""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'
|
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):
|
def _is_default(share_type):
|
||||||
if share_type == 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',
|
'required_extra_specs',
|
||||||
'optional_extra_specs',
|
'optional_extra_specs',
|
||||||
]
|
]
|
||||||
|
if description:
|
||||||
|
fields.append('Description')
|
||||||
if columns is not None:
|
if columns is not None:
|
||||||
fields = _split_columns(columns=columns, title=False)
|
fields = _split_columns(columns=columns, title=False)
|
||||||
|
|
||||||
cliutils.print_list(stypes, fields, formatters)
|
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):
|
def _is_default(share_type):
|
||||||
if share_type == 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),
|
'required_extra_specs': _print_type_required_extra_specs(stype),
|
||||||
'optional_extra_specs': _print_type_optional_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)
|
cliutils.print_dict(stype_dict)
|
||||||
|
|
||||||
|
|
||||||
@@ -3669,8 +3674,10 @@ def do_type_list(cs, args):
|
|||||||
default = None
|
default = None
|
||||||
|
|
||||||
stypes = cs.share_types.list(show_all=args.all)
|
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,
|
_print_share_type_list(stypes, default_share_type=default,
|
||||||
columns=args.columns)
|
columns=args.columns, description=show_des)
|
||||||
|
|
||||||
|
|
||||||
@cliutils.arg(
|
@cliutils.arg(
|
||||||
@@ -3696,6 +3703,13 @@ def do_extra_specs_list(cs, args):
|
|||||||
type=str,
|
type=str,
|
||||||
help="Required extra specification. "
|
help="Required extra specification. "
|
||||||
"Valid values are 'true'/'1' and 'false'/'0'.")
|
"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(
|
@cliutils.arg(
|
||||||
'--snapshot_support',
|
'--snapshot_support',
|
||||||
'--snapshot-support',
|
'--snapshot-support',
|
||||||
@@ -3764,6 +3778,16 @@ def do_type_create(cs, args):
|
|||||||
"set via positional argument.")
|
"set via positional argument.")
|
||||||
raise exceptions.CommandError(msg)
|
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 = (
|
boolean_keys = (
|
||||||
'snapshot_support',
|
'snapshot_support',
|
||||||
'create_share_from_snapshot_support',
|
'create_share_from_snapshot_support',
|
||||||
@@ -3791,7 +3815,7 @@ def do_type_create(cs, args):
|
|||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
stype = cs.share_types.create(**kwargs)
|
stype = cs.share_types.create(**kwargs)
|
||||||
_print_share_type(stype)
|
_print_share_type(stype, show_des=show_des)
|
||||||
|
|
||||||
|
|
||||||
@cliutils.arg(
|
@cliutils.arg(
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- Added description in list/create share type CLI.
|
Reference in New Issue
Block a user