Merge "Add update share-type name description and/or public access"

This commit is contained in:
Zuul 2023-02-21 00:02:15 +00:00 committed by Gerrit Code Review
commit c4ec74c284
9 changed files with 113 additions and 9 deletions

View File

@ -55,6 +55,9 @@ Update share type
:guilabel:`Extra specs`: To add extra specs, use key=value.
To unset extra specs, use key.
:guilabel:`Name`: To update share type name.
:guilabel:`Description`: To update share type description.
:guilabel:`Public`: To update share type visibility.
#. Click :guilabel:`Update Share Type` button to confirm your changes.

View File

@ -28,7 +28,7 @@ from manilaclient import client as manila_client
LOG = logging.getLogger(__name__)
MANILA_UI_USER_AGENT_REPR = "manila_ui_plugin_for_horizon"
MANILA_VERSION = "2.46"
MANILA_VERSION = "2.50"
MANILA_SERVICE_TYPE = "sharev2"
# API static values
@ -428,6 +428,17 @@ def share_type_create(request, name, spec_driver_handles_share_servers,
is_public=is_public)
def share_type_update(request, share_type_id, name=None, description=None,
is_public=None):
share_type_data = {
'name': name,
'description': description,
'is_public': is_public
}
return manilaclient(request).share_types.get(
share_type_id).update(**share_type_data)
def share_type_delete(request, share_type_id):
return manilaclient(request).share_types.delete(share_type_id)

View File

@ -93,6 +93,13 @@ class CreateShareType(forms.SelfHandlingForm):
class UpdateShareType(forms.SelfHandlingForm):
name = forms.CharField(max_length="255", label=_("Name"), required=True)
description = forms.CharField(max_length="255", label=_("Description"),
required=False)
is_public = forms.BooleanField(
label=_("Public"), required=False,
help_text=("New visibility of the share type. If set to True, share "
"type will be available to all projects in the cloud."))
extra_specs = forms.CharField(
required=False, label=_("Extra specs"),
widget=forms.widgets.Textarea(attrs=ST_EXTRA_SPECS_FORM_ATTRS))
@ -105,6 +112,11 @@ class UpdateShareType(forms.SelfHandlingForm):
for k, v in self.initial["extra_specs"].items():
es_str += "%s=%s\r\n" % (k, v)
self.initial["extra_specs"] = es_str
manila_features = getattr(settings, 'OPENSTACK_MANILA_FEATURES', {})
self.enable_public_share_type_creation = manila_features.get(
'enable_public_share_type_creation', True)
if not self.enable_public_share_type_creation:
self.fields.pop('is_public')
def handle(self, request, data):
try:
@ -121,7 +133,13 @@ class UpdateShareType(forms.SelfHandlingForm):
if to_unset:
manila.share_type_unset_extra_specs(
request, self.initial["id"], to_unset)
msg = _("Successfully updated extra specs for share type '%s'.")
name = data.get("name", None)
description = data.get("description", None)
is_public = (self.enable_public_share_type_creation and
data.get("is_public", True))
manila.share_type_update(
request, self.initial["id"], name, description, is_public)
msg = _("Successfully updated share type '%s'.")
msg = msg % self.initial['name']
messages.success(request, msg)
return True
@ -130,6 +148,6 @@ class UpdateShareType(forms.SelfHandlingForm):
self.api_error(e.messages[0])
return False
except Exception:
msg = _("Unable to update extra_specs for share type.")
msg = _("Unable to update share type.")
exceptions.handle(request, msg)
return False

View File

@ -2,7 +2,8 @@
{% load i18n %}
{% block modal-body-right %}
<h3>{% trans "Description" %}:</h3>
<p>
<p>{% trans "From here you can modify name, description, extra specs and visibility of a share type." %}
<br /><br /><strong>Extra specs</strong> field:<br />
{% trans "Here can be modified extra-specs for share type." %}<br />
{% trans "One line - one action. Empty strings will be ignored." %}<br />
{% trans "To add extra-specs use:" %}

View File

@ -132,8 +132,12 @@ class UpdateShareTypeView(forms.ModalFormView):
def get_initial(self):
share_type = self.get_object()
return {
st_info = {
"id": self.kwargs["share_type_id"],
"name": share_type.name,
"extra_specs": share_type.extra_specs,
"is_public": share_type.is_public,
}
if hasattr(share_type, 'description'):
st_info['description'] = share_type.description
return st_info

View File

@ -237,10 +237,25 @@ class ManilaApiTests(base.APITestCase):
def test_migration_cancel(self):
api.migration_cancel(self.request, 'fake_share')
self.manilaclient.shares.migration_cancel.assert_called_once_with(
'fake_share')
@ddt.data(
('name_updated_1', 'description_updated', True),
('name_updated_2', 'description_updated', False),
('name_updated_3', None, True),
)
@ddt.unpack
def test_share_type_update(
self, name, description, is_public):
api.share_type_update(self.request, self.id, name,
description, is_public)
self.manilaclient.share_types.get.return_value.update.\
assert_called_once_with(name=name,
description=description,
is_public=is_public)
def test_migration_get_progress(self):
api.migration_get_progress(self.request, 'fake_share')

View File

@ -79,7 +79,7 @@ class ManilaDashboardsAdminSharesUpdateShareTypeFormTests(base.APITestCase):
self.assertTrue(result)
mock_horizon_messages_success.assert_called_once_with(
mock.ANY, mock.ANY)
self.manilaclient.share_types.get.assert_called_once_with(
self.manilaclient.share_types.get.assert_called_with(
initial['id'])
self.manilaclient.share_types.get.return_value.set_keys.\
assert_called_once_with({'foo': 'bar'})
@ -160,6 +160,42 @@ class ManilaDashboardsAdminSharesUpdateShareTypeFormTests(base.APITestCase):
mock_horizon_exceptions_handle.assert_called_once_with(
self.request, mock.ANY)
@ddt.data(
('name_updated_1', 'description_updated', True),
('name_updated_2', 'description_updated', False),
('name_updated_3', None, True),
)
@ddt.unpack
@mock.patch('horizon.messages.success')
def test_update_share_type_name_description_public(
self, name, description, is_public,
mock_horizon_messages_success):
initial = {
'id': 'fake_id',
'name': 'fake_name',
'description': 'fake_description',
'is_public': True,
'extra_specs': {}
}
form = self._get_form(initial)
data = {
'name': name,
'description': description,
'is_public': is_public,
'extra_specs': '',
}
result = form.handle(self.request, data)
self.assertIs(True, result)
mock_horizon_messages_success.assert_called_once_with(
mock.ANY, mock.ANY)
self.manilaclient.share_types.get.assert_called_once_with(
initial['id'])
self.manilaclient.share_types.get.return_value.update.\
assert_called_once_with(name=data['name'],
description=data['description'],
is_public=data['is_public'])
@ddt.ddt
class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase):

View File

@ -76,15 +76,25 @@ class ShareTypeTests(test.BaseAdminViewTests):
def test_update_share_type_post(self):
data = {
'extra_specs': 'driver_handles_share_servers=True'
'name': 'share_type_update',
'description': 'share_type_description',
'is_public': True,
'extra_specs': 'fork_key=fork_val'
}
form_data = {
'extra_specs': {'driver_handles_share_servers': 'True'},
'name': 'share_type_update',
'description': 'share_type_description',
'is_public': True,
'extra_specs': {'fork_key': 'fork_val'},
}
self.mock_object(api_manila, "share_type_set_extra_specs")
self.mock_object(api_manila, "share_type_update")
res = self.client.post(self.url, data)
api_manila.share_type_set_extra_specs.assert_called_once_with(
mock.ANY, self.share_type.id, form_data['extra_specs'])
api_manila.share_type_update.assert_called_once_with(
mock.ANY, self.share_type.id, data['name'], data['description'],
data['is_public'])
self.assertRedirectsNoFollow(res, INDEX_URL)

View File

@ -0,0 +1,6 @@
---
features:
- |
The ``name``, ``description`` and/or ``share_type_access:is_public``
attributes of share types can be updated with API version ``2.50``
and beyond.