Fix UT failures due to horizon tenant_limit_usages drop
During quota logic refactoring in horizon, quotas.tenant_limit_usages was dropped. Previously manila-ui monkey-patched tenant_limit_usages but there is no need to call tenant_limit_usages actually. Instead manila-ui should call api.manila.tenant_absolute_limits. Change-Id: Icf07b5eb6b821f7cb135ec4fcaf9bcdbe5b44483
This commit is contained in:
parent
02fb80b151
commit
0dcd47ec53
|
@ -20,7 +20,6 @@ from horizon import forms
|
|||
from horizon import tables
|
||||
from horizon import tabs
|
||||
from horizon.utils import memoized
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
from manila_ui.api import manila
|
||||
from manila_ui.dashboards.project.share_snapshots import forms as ss_forms
|
||||
|
@ -116,7 +115,7 @@ class CreateShareSnapshotView(forms.ModalFormView):
|
|||
context = super(self.__class__, self).get_context_data(**kwargs)
|
||||
context['share_id'] = self.kwargs['share_id']
|
||||
try:
|
||||
context['usages'] = quotas.tenant_limit_usages(self.request)
|
||||
context['usages'] = manila.tenant_absolute_limits(self.request)
|
||||
except Exception:
|
||||
exceptions.handle(self.request, _('Unable to retrieve quotas.'))
|
||||
return context
|
||||
|
|
|
@ -22,7 +22,6 @@ from horizon import exceptions
|
|||
from horizon import forms
|
||||
from horizon import messages
|
||||
from horizon.utils.memoized import memoized # noqa
|
||||
from openstack_dashboard.usage import quotas
|
||||
import six
|
||||
|
||||
from manila_ui.api import manila
|
||||
|
@ -381,7 +380,7 @@ class ExtendForm(forms.SelfHandlingForm):
|
|||
self._errors["new_size"] = self.error_class([message])
|
||||
return cleaned_data
|
||||
|
||||
usages = quotas.tenant_limit_usages(self.request)
|
||||
usages = manila.tenant_absolute_limits(self.request)
|
||||
availableGB = (usages['maxTotalShareGigabytes'] -
|
||||
usages['totalShareGigabytesUsed'])
|
||||
if availableGB < (new_size - orig_size):
|
||||
|
|
|
@ -26,7 +26,6 @@ from manila_ui.dashboards.project.shares import forms as share_form
|
|||
from manila_ui.dashboards.project.shares import tables as shares_tables
|
||||
from manila_ui.dashboards.project.shares import tabs as shares_tabs
|
||||
from manila_ui.dashboards import utils as ui_utils
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
|
||||
class ShareTableMixIn(object):
|
||||
|
@ -136,7 +135,7 @@ class CreateView(forms.ModalFormView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateView, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['usages'] = quotas.tenant_limit_usages(self.request)
|
||||
context['usages'] = manila.tenant_absolute_limits(self.request)
|
||||
except Exception:
|
||||
exceptions.handle(self.request)
|
||||
return context
|
||||
|
@ -299,7 +298,7 @@ class ExtendView(forms.ModalFormView):
|
|||
args = (self.get_object().id,)
|
||||
context['submit_url'] = reverse(self.submit_url, args=args)
|
||||
try:
|
||||
context['usages'] = quotas.tenant_limit_usages(self.request)
|
||||
context['usages'] = manila.tenant_absolute_limits(self.request)
|
||||
context['usages']['totalShareGigabytesUsed'] -= int(
|
||||
self.get_object().size)
|
||||
except Exception:
|
||||
|
|
|
@ -53,9 +53,6 @@ class SharesTests(test.BaseAdminViewTests):
|
|||
api_manila, "share_snapshot_list", mock.Mock(return_value=snaps))
|
||||
self.mock_object(
|
||||
api_neutron, "is_service_enabled", mock.Mock(return_value=[True]))
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages",
|
||||
mock.Mock(return_value=test_data.quota_usage))
|
||||
self.mock_object(
|
||||
quotas, "tenant_quota_usages",
|
||||
mock.Mock(return_value=test_data.quota_usage))
|
||||
|
|
|
@ -16,7 +16,6 @@ import ddt
|
|||
from django.urls import reverse
|
||||
import mock
|
||||
from openstack_dashboard.api import neutron
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
from manila_ui.api import manila as api_manila
|
||||
from manila_ui.tests.dashboards.project import test_data
|
||||
|
@ -37,7 +36,8 @@ class SnapshotSnapshotViewTests(test.TestCase):
|
|||
url = reverse('horizon:project:share_snapshots:share_snapshot_create',
|
||||
args=[share.id])
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, "tenant_absolute_limits",
|
||||
mock.Mock(return_value=usage_limit))
|
||||
self.mock_object(
|
||||
neutron, "is_service_enabled", mock.Mock(return_value=[True]))
|
||||
|
||||
|
|
|
@ -71,9 +71,6 @@ class ShareViewTests(test.APITestCase):
|
|||
mock.Mock(return_value=share_networks))
|
||||
self.mock_object(
|
||||
neutron, "is_service_enabled", mock.Mock(return_value=[True]))
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages",
|
||||
mock.Mock(return_value=test_data.quota_usage))
|
||||
self.mock_object(
|
||||
quotas, "tenant_quota_usages",
|
||||
mock.Mock(return_value=test_data.quota_usage))
|
||||
|
@ -363,7 +360,8 @@ class ShareViewTests(test.APITestCase):
|
|||
}
|
||||
url = reverse('horizon:project:shares:extend', args=[share.id])
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, "tenant_absolute_limits",
|
||||
mock.Mock(return_value=usage_limit))
|
||||
self.mock_object(
|
||||
neutron, "is_service_enabled", mock.Mock(return_value=[True]))
|
||||
|
||||
|
@ -382,7 +380,8 @@ class ShareViewTests(test.APITestCase):
|
|||
url = reverse('horizon:project:shares:extend', args=[self.share.id])
|
||||
self.mock_object(api_manila, "share_extend")
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, 'tenant_absolute_limits',
|
||||
mock.Mock(return_value=usage_limit))
|
||||
|
||||
response = self.client.get(url)
|
||||
|
||||
|
@ -390,7 +389,7 @@ class ShareViewTests(test.APITestCase):
|
|||
self.assertTemplateUsed(response, 'project/shares/extend.html')
|
||||
api_manila.share_get.assert_called_once_with(mock.ANY, self.share.id)
|
||||
self.assertFalse(api_manila.share_extend.called)
|
||||
quotas.tenant_limit_usages.assert_called_once_with(mock.ANY)
|
||||
api_manila.tenant_absolute_limits.assert_called_once_with(mock.ANY)
|
||||
|
||||
def test_extend_share_get_with_api_exception(self):
|
||||
usage_limit = {
|
||||
|
@ -400,7 +399,8 @@ class ShareViewTests(test.APITestCase):
|
|||
url = reverse('horizon:project:shares:extend', args=[self.share.id])
|
||||
self.mock_object(api_manila, "share_extend")
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, 'tenant_absolute_limits',
|
||||
mock.Mock(return_value=usage_limit))
|
||||
self.mock_object(
|
||||
api_manila, "share_get",
|
||||
mock.Mock(return_value=Exception('Fake share NotFound exception')))
|
||||
|
@ -412,7 +412,7 @@ class ShareViewTests(test.APITestCase):
|
|||
response, 'project/shares/shares/extend.html')
|
||||
self.assertFalse(api_manila.share_extend.called)
|
||||
api_manila.share_get.assert_called_once_with(mock.ANY, self.share.id)
|
||||
self.assertFalse(quotas.tenant_limit_usages.called)
|
||||
self.assertFalse(api_manila.tenant_absolute_limits.called)
|
||||
|
||||
@ddt.data(6, 54, 55)
|
||||
def test_extend_share_post_successfully(self, new_size):
|
||||
|
@ -425,7 +425,8 @@ class ShareViewTests(test.APITestCase):
|
|||
url = reverse('horizon:project:shares:extend', args=[self.share.id])
|
||||
self.mock_object(api_manila, "share_extend")
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, 'tenant_absolute_limits',
|
||||
mock.Mock(return_value=usage_limit))
|
||||
|
||||
response = self.client.post(url, form_data)
|
||||
|
||||
|
@ -435,7 +436,7 @@ class ShareViewTests(test.APITestCase):
|
|||
api_manila.share_get.assert_called_once_with(mock.ANY, self.share.id)
|
||||
api_manila.share_extend.assert_called_once_with(
|
||||
mock.ANY, self.share.id, form_data['new_size'])
|
||||
quotas.tenant_limit_usages.assert_called_once_with(mock.ANY)
|
||||
api_manila.tenant_absolute_limits.assert_called_once_with(mock.ANY)
|
||||
self.assertRedirectsNoFollow(response, INDEX_URL)
|
||||
|
||||
@ddt.data(0, 5, 56)
|
||||
|
@ -449,7 +450,8 @@ class ShareViewTests(test.APITestCase):
|
|||
url = reverse('horizon:project:shares:extend', args=[self.share.id])
|
||||
self.mock_object(api_manila, "share_extend")
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, 'tenant_absolute_limits',
|
||||
mock.Mock(return_value=usage_limit))
|
||||
|
||||
response = self.client.post(url, form_data)
|
||||
|
||||
|
@ -457,7 +459,7 @@ class ShareViewTests(test.APITestCase):
|
|||
self.assertTemplateUsed(response, 'project/shares/extend.html')
|
||||
self.assertFalse(api_manila.share_extend.called)
|
||||
api_manila.share_get.assert_called_once_with(mock.ANY, self.share.id)
|
||||
quotas.tenant_limit_usages.assert_called_with(mock.ANY)
|
||||
api_manila.tenant_absolute_limits.assert_called_with(mock.ANY)
|
||||
|
||||
def test_extend_share_post_with_api_exception(self):
|
||||
self.share.size = 5
|
||||
|
@ -471,7 +473,8 @@ class ShareViewTests(test.APITestCase):
|
|||
api_manila, "share_extend",
|
||||
mock.Mock(return_value=Exception('Fake API exception')))
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
api_manila, 'tenant_absolute_limits',
|
||||
mock.Mock(return_value=usage_limit))
|
||||
|
||||
response = self.client.post(url, form_data)
|
||||
|
||||
|
@ -481,7 +484,7 @@ class ShareViewTests(test.APITestCase):
|
|||
api_manila.share_extend.assert_called_once_with(
|
||||
mock.ANY, self.share.id, form_data['new_size'])
|
||||
api_manila.share_get.assert_called_once_with(mock.ANY, self.share.id)
|
||||
quotas.tenant_limit_usages.assert_called_once_with(mock.ANY)
|
||||
api_manila.tenant_absolute_limits.assert_called_once_with(mock.ANY)
|
||||
self.assertRedirectsNoFollow(response, INDEX_URL)
|
||||
|
||||
def test_revert_to_snapshot_get_success(self):
|
||||
|
|
Loading…
Reference in New Issue