diff --git a/manila_ui/api/manila.py b/manila_ui/api/manila.py index 1a30a92e..f8800ce2 100644 --- a/manila_ui/api/manila.py +++ b/manila_ui/api/manila.py @@ -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.40" +MANILA_VERSION = "2.41" MANILA_SERVICE_TYPE = "sharev2" # API static values @@ -398,9 +398,10 @@ def share_type_get(request, share_type_id): def share_type_create(request, name, spec_driver_handles_share_servers, - is_public=True): + description=None, is_public=True): return manilaclient(request).share_types.create( name=name, + description=description, spec_driver_handles_share_servers=spec_driver_handles_share_servers, is_public=is_public) diff --git a/manila_ui/dashboards/admin/share_types/forms.py b/manila_ui/dashboards/admin/share_types/forms.py index d12911e3..a192a4b3 100644 --- a/manila_ui/dashboards/admin/share_types/forms.py +++ b/manila_ui/dashboards/admin/share_types/forms.py @@ -33,6 +33,8 @@ ST_EXTRA_SPECS_FORM_ATTRS = { class CreateShareType(forms.SelfHandlingForm): name = forms.CharField(max_length="255", label=_("Name"), required=True) + description = forms.CharField(widget=forms.Textarea, max_length="255", + label=_("Description"), required=False) spec_driver_handles_share_servers = forms.ChoiceField( label=_("Driver handles share servers"), required=True, choices=(('False', 'False'), ('True', 'True'))) @@ -72,7 +74,8 @@ class CreateShareType(forms.SelfHandlingForm): is_public = (self.enable_public_share_type_creation and data["is_public"]) share_type = manila.share_type_create( - request, data["name"], spec_dhss, is_public=is_public) + request, data["name"], spec_dhss, + description=data["description"], is_public=is_public) if set_dict: manila.share_type_set_extra_specs( request, share_type.id, set_dict) @@ -90,6 +93,9 @@ class CreateShareType(forms.SelfHandlingForm): class UpdateShareType(forms.SelfHandlingForm): + extra_specs = forms.CharField( + required=False, label=_("Extra specs"), + widget=forms.widgets.Textarea(attrs=ST_EXTRA_SPECS_FORM_ATTRS)) def __init__(self, *args, **kwargs): super(UpdateShareType, self).__init__(*args, **kwargs) @@ -100,10 +106,6 @@ class UpdateShareType(forms.SelfHandlingForm): es_str += "%s=%s\r\n" % (k, v) self.initial["extra_specs"] = es_str - extra_specs = forms.CharField( - required=False, label=_("Extra specs"), - widget=forms.widgets.Textarea(attrs=ST_EXTRA_SPECS_FORM_ATTRS)) - def handle(self, request, data): try: set_dict, unset_list = utils.parse_str_meta(data['extra_specs']) diff --git a/manila_ui/dashboards/admin/share_types/tables.py b/manila_ui/dashboards/admin/share_types/tables.py index 680881da..3041da84 100644 --- a/manila_ui/dashboards/admin/share_types/tables.py +++ b/manila_ui/dashboards/admin/share_types/tables.py @@ -83,6 +83,8 @@ class UpdateShareType(tables.LinkAction): class ShareTypesTable(tables.DataTable): name = tables.WrappingColumn("name", verbose_name=_("Name")) + description = tables.WrappingColumn( + "description", verbose_name=_("Description")) extra_specs = tables.Column("extra_specs", verbose_name=_("Extra specs"), ) visibility = tables.Column( "is_public", verbose_name=_("Visibility"), diff --git a/manila_ui/tests/api/test_manila.py b/manila_ui/tests/api/test_manila.py index aefa1ac1..02684f2d 100644 --- a/manila_ui/tests/api/test_manila.py +++ b/manila_ui/tests/api/test_manila.py @@ -674,24 +674,27 @@ class ManilaApiTests(base.APITestCase): self.manilaclient.share_types.create.assert_called_once_with( name=name, spec_driver_handles_share_servers=dhss, + description=None, is_public=True) @ddt.data( - (True, True), - (False, True), - (True, False), - (False, False), + (True, "fake_description", True), + (False, "fake_description", True), + (True, "fake_description", False), + (False, "fake_description", False), ) @ddt.unpack def test_share_type_create_with_custom_values( - self, dhss, is_public): + self, dhss, description, is_public): name = 'fake_share_type_name' api.share_type_create( - self.request, name, dhss, is_public) + self.request, name, dhss, description, + is_public) self.manilaclient.share_types.create.assert_called_once_with( name=name, + description=description, spec_driver_handles_share_servers=dhss, is_public=is_public) diff --git a/manila_ui/tests/dashboards/admin/share_types/test_forms.py b/manila_ui/tests/dashboards/admin/share_types/test_forms.py index 9478f7d6..e0911464 100644 --- a/manila_ui/tests/dashboards/admin/share_types/test_forms.py +++ b/manila_ui/tests/dashboards/admin/share_types/test_forms.py @@ -180,6 +180,7 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): 'is_public': False, 'spec_driver_handles_share_servers': 'True', 'name': 'share', + 'description': '' } result = form.handle(self.request, data) @@ -188,17 +189,19 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): self.manilaclient.share_types.create.assert_called_once_with( name=data['name'], spec_driver_handles_share_servers='true', + description=data['description'], is_public=data["is_public"]) mock_horizon_messages_success.assert_called_once_with( self.request, mock.ANY) @mock.patch('horizon.messages.success') - def test_create_share_type_with_extra_specs(self, - mock_horizon_messages_success): + def test_create_share_type_with_extra_specs_and_description( + self, mock_horizon_messages_success): form = self._get_form() data = {'extra_specs': 'a=b \n c=d', 'is_public': False, 'spec_driver_handles_share_servers': 'True', + 'description': 'st_description', 'name': 'share'} result = form.handle(self.request, data) @@ -211,6 +214,7 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): self.manilaclient.share_types.create.assert_called_once_with( name=data['name'], spec_driver_handles_share_servers='true', + description=data['description'], is_public=data["is_public"]) mock_horizon_messages_success.assert_called_once_with( self.request, mock.ANY) @@ -230,6 +234,7 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): 'is_public': enable_public_share_type_creation, 'spec_driver_handles_share_servers': 'True', 'name': 'share', + 'description': '', } result = form.handle(self.request, data) @@ -246,6 +251,7 @@ class ManilaDashboardsAdminSharesCreateShareTypeFormTests(base.APITestCase): self.manilaclient.share_types.create.assert_called_once_with( name=data['name'], spec_driver_handles_share_servers='true', + description=data['description'], is_public=enable_public_share_type_creation) mock_horizon_messages_success.assert_called_once_with( self.request, mock.ANY) diff --git a/manila_ui/tests/dashboards/admin/share_types/tests.py b/manila_ui/tests/dashboards/admin/share_types/tests.py index 719220f7..779ea00b 100644 --- a/manila_ui/tests/dashboards/admin/share_types/tests.py +++ b/manila_ui/tests/dashboards/admin/share_types/tests.py @@ -50,6 +50,7 @@ class ShareTypeTests(test.BaseAdminViewTests): data = { 'is_public': True, 'name': 'my_share_type', + 'description': 'share_type_description', 'spec_driver_handles_share_servers': 'False' } form_data = data.copy() @@ -61,6 +62,7 @@ class ShareTypeTests(test.BaseAdminViewTests): api_manila.share_type_create.assert_called_once_with( mock.ANY, form_data['name'], form_data['spec_driver_handles_share_servers'], + description=form_data['description'], is_public=form_data['is_public']) self.assertRedirectsNoFollow(res, INDEX_URL) diff --git a/releasenotes/notes/add-create-share-type-with-description-d57f4c734d107554.yaml b/releasenotes/notes/add-create-share-type-with-description-d57f4c734d107554.yaml new file mode 100644 index 00000000..d8c25526 --- /dev/null +++ b/releasenotes/notes/add-create-share-type-with-description-d57f4c734d107554.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added possibility to create share type with description.