Add update share-type name description and/or public access
Currently, only the name and public access of share-type is set when the share-type is created, and not allowed to be edited after the share-type is created. We can only set extra spec for share-type. This commit suppport update name,description or public access of share-type. Change-Id: Ia59ae574482fa8015f0151cd983ef880e180640a Partially-Implements: blueprint update-share-type-name-or-description
This commit is contained in:
parent
c5184b28fc
commit
0e971152f7
|
@ -55,6 +55,9 @@ Update share type
|
||||||
|
|
||||||
:guilabel:`Extra specs`: To add extra specs, use key=value.
|
:guilabel:`Extra specs`: To add extra specs, use key=value.
|
||||||
To unset extra specs, use key.
|
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.
|
#. Click :guilabel:`Update Share Type` button to confirm your changes.
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ from manilaclient import client as manila_client
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
MANILA_UI_USER_AGENT_REPR = "manila_ui_plugin_for_horizon"
|
MANILA_UI_USER_AGENT_REPR = "manila_ui_plugin_for_horizon"
|
||||||
MANILA_VERSION = "2.46"
|
MANILA_VERSION = "2.50"
|
||||||
MANILA_SERVICE_TYPE = "sharev2"
|
MANILA_SERVICE_TYPE = "sharev2"
|
||||||
|
|
||||||
# API static values
|
# API static values
|
||||||
|
@ -428,6 +428,17 @@ def share_type_create(request, name, spec_driver_handles_share_servers,
|
||||||
is_public=is_public)
|
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):
|
def share_type_delete(request, share_type_id):
|
||||||
return manilaclient(request).share_types.delete(share_type_id)
|
return manilaclient(request).share_types.delete(share_type_id)
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,13 @@ class CreateShareType(forms.SelfHandlingForm):
|
||||||
|
|
||||||
|
|
||||||
class UpdateShareType(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(
|
extra_specs = forms.CharField(
|
||||||
required=False, label=_("Extra specs"),
|
required=False, label=_("Extra specs"),
|
||||||
widget=forms.widgets.Textarea(attrs=ST_EXTRA_SPECS_FORM_ATTRS))
|
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():
|
for k, v in self.initial["extra_specs"].items():
|
||||||
es_str += "%s=%s\r\n" % (k, v)
|
es_str += "%s=%s\r\n" % (k, v)
|
||||||
self.initial["extra_specs"] = es_str
|
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):
|
def handle(self, request, data):
|
||||||
try:
|
try:
|
||||||
|
@ -121,7 +133,13 @@ class UpdateShareType(forms.SelfHandlingForm):
|
||||||
if to_unset:
|
if to_unset:
|
||||||
manila.share_type_unset_extra_specs(
|
manila.share_type_unset_extra_specs(
|
||||||
request, self.initial["id"], to_unset)
|
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']
|
msg = msg % self.initial['name']
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
return True
|
return True
|
||||||
|
@ -130,6 +148,6 @@ class UpdateShareType(forms.SelfHandlingForm):
|
||||||
self.api_error(e.messages[0])
|
self.api_error(e.messages[0])
|
||||||
return False
|
return False
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = _("Unable to update extra_specs for share type.")
|
msg = _("Unable to update share type.")
|
||||||
exceptions.handle(request, msg)
|
exceptions.handle(request, msg)
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block modal-body-right %}
|
{% block modal-body-right %}
|
||||||
<h3>{% trans "Description" %}:</h3>
|
<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 "Here can be modified extra-specs for share type." %}<br />
|
||||||
{% trans "One line - one action. Empty strings will be ignored." %}<br />
|
{% trans "One line - one action. Empty strings will be ignored." %}<br />
|
||||||
{% trans "To add extra-specs use:" %}
|
{% trans "To add extra-specs use:" %}
|
||||||
|
|
|
@ -132,8 +132,12 @@ class UpdateShareTypeView(forms.ModalFormView):
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
share_type = self.get_object()
|
share_type = self.get_object()
|
||||||
return {
|
st_info = {
|
||||||
"id": self.kwargs["share_type_id"],
|
"id": self.kwargs["share_type_id"],
|
||||||
"name": share_type.name,
|
"name": share_type.name,
|
||||||
"extra_specs": share_type.extra_specs,
|
"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
|
||||||
|
|
|
@ -237,10 +237,25 @@ class ManilaApiTests(base.APITestCase):
|
||||||
|
|
||||||
def test_migration_cancel(self):
|
def test_migration_cancel(self):
|
||||||
api.migration_cancel(self.request, 'fake_share')
|
api.migration_cancel(self.request, 'fake_share')
|
||||||
|
|
||||||
self.manilaclient.shares.migration_cancel.assert_called_once_with(
|
self.manilaclient.shares.migration_cancel.assert_called_once_with(
|
||||||
'fake_share')
|
'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):
|
def test_migration_get_progress(self):
|
||||||
api.migration_get_progress(self.request, 'fake_share')
|
api.migration_get_progress(self.request, 'fake_share')
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class ManilaDashboardsAdminSharesUpdateShareTypeFormTests(base.APITestCase):
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
mock_horizon_messages_success.assert_called_once_with(
|
mock_horizon_messages_success.assert_called_once_with(
|
||||||
mock.ANY, mock.ANY)
|
mock.ANY, mock.ANY)
|
||||||
self.manilaclient.share_types.get.assert_called_once_with(
|
self.manilaclient.share_types.get.assert_called_with(
|
||||||
initial['id'])
|
initial['id'])
|
||||||
self.manilaclient.share_types.get.return_value.set_keys.\
|
self.manilaclient.share_types.get.return_value.set_keys.\
|
||||||
assert_called_once_with({'foo': 'bar'})
|
assert_called_once_with({'foo': 'bar'})
|
||||||
|
@ -160,6 +160,42 @@ class ManilaDashboardsAdminSharesUpdateShareTypeFormTests(base.APITestCase):
|
||||||
mock_horizon_exceptions_handle.assert_called_once_with(
|
mock_horizon_exceptions_handle.assert_called_once_with(
|
||||||
self.request, mock.ANY)
|
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
|
@ddt.ddt
|
||||||
class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase):
|
class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase):
|
||||||
|
|
|
@ -76,15 +76,25 @@ class ShareTypeTests(test.BaseAdminViewTests):
|
||||||
|
|
||||||
def test_update_share_type_post(self):
|
def test_update_share_type_post(self):
|
||||||
data = {
|
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 = {
|
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_set_extra_specs")
|
||||||
|
self.mock_object(api_manila, "share_type_update")
|
||||||
|
|
||||||
res = self.client.post(self.url, data)
|
res = self.client.post(self.url, data)
|
||||||
|
|
||||||
api_manila.share_type_set_extra_specs.assert_called_once_with(
|
api_manila.share_type_set_extra_specs.assert_called_once_with(
|
||||||
mock.ANY, self.share_type.id, form_data['extra_specs'])
|
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)
|
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||||
|
|
|
@ -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.
|
Loading…
Reference in New Issue