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
This commit is contained in:
Valeriy Ponomaryov 2015-08-14 19:35:52 +03:00
parent f66e6660c7
commit 94b8e4e5ea
7 changed files with 109 additions and 2 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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"}

View File

@ -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)