From 94b8e4e5eab4dc17e1115ddedad9974edf5b9c7c Mon Sep 17 00:00:00 2001 From: Valeriy Ponomaryov Date: Fri, 14 Aug 2015 19:35:52 +0300 Subject: [PATCH] Disable button 'create snapshot' if share not snapshottable On last midcycle meetup was decided to make snapshots optional feature. On Manila side was added new boolean share driver capability 'snapshot_support'. So, disable button 'create snapshot' for shares that have 'snapshot_support' attr equals to 'False'. Allow creation of a snapshot for shares that do not have such attr for backward compatibility. Change-Id: Ibaca8b6cdf9d223f94a83baf7686ad0a0dd9ef8c Depends-On: Id8e11b591a713654f7237cb1b66aeeaebfbf5871 --- manila_ui/api/manila.py | 3 +- .../project/shares/snapshots/tables.py | 11 +++- manila_ui/test/api/test_manila.py | 39 +++++++++++++ manila_ui/test/dashboards/project/__init__.py | 0 .../dashboards/project/shares/__init__.py | 0 .../project/shares/snapshots/__init__.py | 0 .../project/shares/snapshots/test_tables.py | 58 +++++++++++++++++++ 7 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 manila_ui/test/dashboards/project/__init__.py create mode 100644 manila_ui/test/dashboards/project/shares/__init__.py create mode 100644 manila_ui/test/dashboards/project/shares/snapshots/__init__.py create mode 100644 manila_ui/test/dashboards/project/shares/snapshots/test_tables.py diff --git a/manila_ui/api/manila.py b/manila_ui/api/manila.py index 9d3c6d01..6af6c187 100644 --- a/manila_ui/api/manila.py +++ b/manila_ui/api/manila.py @@ -283,10 +283,11 @@ def share_type_get(request, share_type_id): def share_type_create(request, name, spec_driver_handles_share_servers, - is_public=True): + spec_snapshot_support=True, is_public=True): return manilaclient(request).share_types.create( name=name, spec_driver_handles_share_servers=spec_driver_handles_share_servers, + spec_snapshot_support=spec_snapshot_support, is_public=is_public) diff --git a/manila_ui/dashboards/project/shares/snapshots/tables.py b/manila_ui/dashboards/project/shares/snapshots/tables.py index da74aee3..f0b4e945 100644 --- a/manila_ui/dashboards/project/shares/snapshots/tables.py +++ b/manila_ui/dashboards/project/shares/snapshots/tables.py @@ -70,7 +70,16 @@ class CreateSnapshot(tables.LinkAction): self.verbose_name = _("Create Snapshot") classes = [c for c in self.classes if c != "disabled"] self.classes = classes - return share.status in ("available", "in-use") + + # NOTE(vponomaryov): Disable form with creation of a snapshot for + # shares that has attr 'snapshot_support' equal to False. + if hasattr(share, 'snapshot_support'): + snapshot_support = share.snapshot_support + else: + # NOTE(vponomaryov): Allow creation of a snapshot for shares that + # do not have such attr for backward compatibility. + snapshot_support = True + return share.status in ("available", "in-use") and snapshot_support class DeleteSnapshot(tables.DeleteAction): diff --git a/manila_ui/test/api/test_manila.py b/manila_ui/test/api/test_manila.py index 458bbe27..573daa29 100644 --- a/manila_ui/test/api/test_manila.py +++ b/manila_ui/test/api/test_manila.py @@ -13,10 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import ddt + from manila_ui.api import manila as api from manila_ui.test import helpers as base +@ddt.ddt class ManilaApiTests(base.APITestCase): def setUp(self): @@ -32,6 +35,42 @@ class ManilaApiTests(base.APITestCase): self.id, new_size ) + @ddt.data(True, False) + def test_share_type_create_with_default_values(self, dhss): + name = 'fake_share_type_name' + + api.share_type_create(self.request, name, dhss) + + self.manilaclient.share_types.create.assert_called_once_with( + name=name, + spec_driver_handles_share_servers=dhss, + spec_snapshot_support=True, + is_public=True) + + @ddt.data( + (True, True, True), + (True, True, False), + (True, False, True), + (False, True, True), + (True, False, False), + (False, False, True), + (False, True, False), + (True, True, True), + ) + @ddt.unpack + def test_share_type_create_with_custom_values( + self, dhss, snapshot_support, is_public): + name = 'fake_share_type_name' + + api.share_type_create( + self.request, name, dhss, snapshot_support, is_public) + + self.manilaclient.share_types.create.assert_called_once_with( + name=name, + spec_driver_handles_share_servers=dhss, + spec_snapshot_support=snapshot_support, + is_public=is_public) + def test_share_type_set_extra_specs(self): data = {"foo": "bar"} diff --git a/manila_ui/test/dashboards/project/__init__.py b/manila_ui/test/dashboards/project/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/manila_ui/test/dashboards/project/shares/__init__.py b/manila_ui/test/dashboards/project/shares/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/manila_ui/test/dashboards/project/shares/snapshots/__init__.py b/manila_ui/test/dashboards/project/shares/snapshots/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/manila_ui/test/dashboards/project/shares/snapshots/test_tables.py b/manila_ui/test/dashboards/project/shares/snapshots/test_tables.py new file mode 100644 index 00000000..535baeb3 --- /dev/null +++ b/manila_ui/test/dashboards/project/shares/snapshots/test_tables.py @@ -0,0 +1,58 @@ +# Copyright (c) 2015 Mirantis, Inc. +# All rights reserved. + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import ddt +from django.core.handlers import wsgi +import mock + +from manila_ui.dashboards.project.shares.snapshots import tables +from manila_ui.test import helpers as base + + +@ddt.ddt +class CreateSnapshotTests(base.APITestCase): + + def setUp(self): + super(self.__class__, self).setUp() + FAKE_ENVIRON = {'REQUEST_METHOD': 'GET', 'wsgi.input': 'fake_input'} + self.request = wsgi.WSGIRequest(FAKE_ENVIRON) + self.create_snapshot = tables.CreateSnapshot() + + def _get_fake_share(self, **kwargs): + if 'status' not in kwargs.keys(): + kwargs.update({'status': 'available'}) + return type("Share", (object, ), kwargs)() + + @ddt.data(True, False) + @mock.patch('openstack_dashboard.usage.quotas.tenant_quota_usages') + def test_allowed_with_snapshot_support_attr(self, snapshot_support, + mock_quota_usages): + mock_quota_usages.return_value = {'snapshots': {'available': 1}} + share = self._get_fake_share(snapshot_support=snapshot_support) + + result = self.create_snapshot.allowed(self.request, share) + + self.assertEqual(snapshot_support, result) + mock_quota_usages.assert_called_once_with(self.request) + + @mock.patch('openstack_dashboard.usage.quotas.tenant_quota_usages') + def test_allowed_no_snapshot_support_attr(self, mock_quota_usages): + mock_quota_usages.return_value = {'snapshots': {'available': 1}} + share = self._get_fake_share() + + result = self.create_snapshot.allowed(self.request, share) + + self.assertTrue(result) + mock_quota_usages.assert_called_once_with(self.request)