Merge "Updated to get quotas data for Modify Quotas dialog Share tab"
This commit is contained in:
commit
66761605f4
|
@ -47,6 +47,16 @@ MANILA_QUOTA_FIELDS = {
|
|||
"share_networks",
|
||||
}
|
||||
|
||||
# UI field names do not match data field names returned, have
|
||||
# a map to convert them.
|
||||
MANILA_QUOTA_FIELDS_DATA_MAP = {
|
||||
"shares": "shares",
|
||||
"share_gigabytes": "gigabytes",
|
||||
"share_snapshots": "snapshots",
|
||||
"share_snapshot_gigabytes": "snapshot_gigabytes",
|
||||
"share_networks": "share_networks"
|
||||
}
|
||||
|
||||
|
||||
def manilaclient(request):
|
||||
insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
|
||||
|
|
|
@ -10,8 +10,11 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import workflows
|
||||
|
||||
|
@ -21,6 +24,8 @@ from openstack_dashboard.dashboards.identity.projects \
|
|||
|
||||
from manila_ui.api import manila as api_manila
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ShareQuotaAction(project_workflows.CommonQuotaAction):
|
||||
shares = forms.IntegerField(min_value=-1, label=_("Shares"))
|
||||
|
@ -50,5 +55,19 @@ class UpdateShareQuota(workflows.Step):
|
|||
depends_on = ("project_id", "disabled_quotas")
|
||||
contributes = api_manila.MANILA_QUOTA_FIELDS
|
||||
|
||||
def prepare_action_context(self, request, context):
|
||||
try:
|
||||
quotas = api_manila.tenant_quota_get(
|
||||
request, context['project_id'])
|
||||
for field in api_manila.MANILA_QUOTA_FIELDS:
|
||||
# Resolve mismatch UI field names and data field names.
|
||||
data_field = api_manila.MANILA_QUOTA_FIELDS_DATA_MAP[field]
|
||||
context[field] = quotas.get(data_field).limit
|
||||
except Exception as ex:
|
||||
LOG.exception(ex)
|
||||
exceptions.handle(request,
|
||||
_('Unable to retrieve share quotas.'))
|
||||
return context
|
||||
|
||||
def allowed(self, request):
|
||||
return base.is_service_enabled(request, 'share')
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
import ddt
|
||||
|
||||
from openstack_dashboard.api import base as horizon_api
|
||||
|
||||
from manila_ui.api import manila as api
|
||||
from manila_ui.tests import helpers as base
|
||||
|
||||
|
@ -25,6 +27,7 @@ class ManilaApiTests(base.APITestCase):
|
|||
def setUp(self):
|
||||
super(self.__class__, self).setUp()
|
||||
self.id = "fake_id"
|
||||
self.mock_object(horizon_api, "QuotaSet")
|
||||
|
||||
@ddt.data((None, True), ("some_fake_sg_id", False))
|
||||
@ddt.unpack
|
||||
|
@ -353,6 +356,31 @@ class ManilaApiTests(base.APITestCase):
|
|||
self.manilaclient.quota_classes.update.assert_called_once_with(
|
||||
api.DEFAULT_QUOTA_NAME, **expected_kwargs)
|
||||
|
||||
def test_tenant_quota_get(self):
|
||||
tenant_id = 'fake_tenant_id'
|
||||
result = api.tenant_quota_get(self.request, tenant_id)
|
||||
|
||||
self.assertIsNotNone(result)
|
||||
self.manilaclient.quotas.get.assert_called_once_with(tenant_id)
|
||||
|
||||
@ddt.data({
|
||||
'shares': 24, 'gigabytes': 333, 'snapshots': 14,
|
||||
'snapshot_gigabytes': 444, 'share_networks': 14
|
||||
})
|
||||
@ddt.unpack
|
||||
def test_ui_data_map(self, **kwargs):
|
||||
expected_result = {
|
||||
'shares': 24, 'share_gigabytes': 333, 'share_snapshots': 14,
|
||||
'share_snapshot_gigabytes': 444, 'share_networks': 14
|
||||
}
|
||||
|
||||
converted_result_for_ui = {}
|
||||
for field in api.MANILA_QUOTA_FIELDS:
|
||||
converted_result_for_ui[field] = (
|
||||
kwargs[api.MANILA_QUOTA_FIELDS_DATA_MAP[field]])
|
||||
|
||||
self.assertEqual(expected_result, converted_result_for_ui)
|
||||
|
||||
@ddt.data(
|
||||
{},
|
||||
{"name": "foo_name"},
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# (c) Copyright 2019 SUSE LLC
|
||||
# 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.
|
||||
|
||||
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from horizon.workflows import views
|
||||
from openstack_dashboard.api import base
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
from manila_ui.api import manila as manila_api
|
||||
from manila_ui.tests import helpers as manila_base_test
|
||||
|
||||
|
||||
class UpdateShareQuotaWorkflowTests(manila_base_test.BaseAdminViewTests):
|
||||
|
||||
def setUp(self):
|
||||
super(UpdateShareQuotaWorkflowTests, self).setUp()
|
||||
self.id = "fake_id"
|
||||
|
||||
# mock functions in manila.py
|
||||
self.mock_tenant_quota_get = (
|
||||
self.mock_object(manila_api, "tenant_quota_get"))
|
||||
self.mock_tenant_quota_get.return_value = (
|
||||
self._get_mock_share_quota_data())
|
||||
|
||||
# mock functions in quotas.py
|
||||
self.mock_object(quotas, "get_tenant_quota_data")
|
||||
self.mock_object(quotas, "get_disabled_quotas").return_value = set()
|
||||
|
||||
def _get_mock_share_quota_data(self):
|
||||
quota_data = {
|
||||
'shares': 24, 'gigabytes': 333, 'snapshots': 14,
|
||||
'snapshot_gigabytes': 444, 'share_networks': 14
|
||||
}
|
||||
|
||||
return base.QuotaSet(quota_data)
|
||||
|
||||
@override_settings(EXTRA_STEPS={
|
||||
'openstack_dashboard.dashboards.identity.projects.\
|
||||
workflows.UpdateQuota': (
|
||||
'manila_ui.dashboards.identity.projects.workflows.UpdateShareQuota'
|
||||
)}
|
||||
)
|
||||
def test_tenant_quota_get(self):
|
||||
tenant_id = 'fake_tenant_id'
|
||||
url = reverse('horizon:identity:projects:update_quotas',
|
||||
args=[tenant_id])
|
||||
res = self.client.get(url)
|
||||
|
||||
workflow = res.context['workflow']
|
||||
self.assertTemplateUsed(res, views.WorkflowView.template_name)
|
||||
step = workflow.get_step("update_share_quotas")
|
||||
|
||||
# Check step UI fields got the fields converted and data correct
|
||||
self.assertEqual(step.action.initial['project_id'], tenant_id)
|
||||
self.assertEqual(step.action.initial['shares'], 24)
|
||||
self.assertEqual(step.action.initial['share_gigabytes'], 333)
|
||||
self.assertEqual(step.action.initial['share_snapshot_gigabytes'], 444)
|
||||
self.assertEqual(step.action.initial['share_snapshots'], 14)
|
||||
self.assertEqual(step.action.initial['share_networks'], 14)
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed issue that the saved Share quota data is not shown in Modify
|
||||
Quotas modal dialog.
|
||||
|
Loading…
Reference in New Issue