Merge "quota: Move neutron quota logic in identity.projects.views"
This commit is contained in:
commit
01ffeb9389
@ -190,11 +190,8 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'user_list',
|
||||
'group_list',
|
||||
'role_list'),
|
||||
api.base: ('is_service_enabled',),
|
||||
api.cinder: ('is_volume_service_enabled',),
|
||||
api.neutron: ('is_extension_supported',
|
||||
'is_router_enabled',),
|
||||
quotas: ('get_default_quota_data',)})
|
||||
quotas: ('get_default_quota_data',
|
||||
'get_disabled_quotas')})
|
||||
def test_add_project_get(self):
|
||||
quota = self.quotas.first()
|
||||
default_role = self.roles.first()
|
||||
@ -204,20 +201,11 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
groups = self._get_all_groups(domain_id)
|
||||
roles = self.roles.list()
|
||||
|
||||
# init
|
||||
api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.base.is_service_enabled(IsA(http.HttpRequest), 'compute') \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.cinder.is_volume_service_enabled(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.keystone.get_default_domain(IsA(http.HttpRequest)) \
|
||||
.AndReturn(default_domain)
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'security-group').AndReturn(True)
|
||||
api.neutron.is_router_enabled(
|
||||
IsA(http.HttpRequest)).AndReturn(True)
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
|
||||
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
||||
.AndReturn(quotas.NEUTRON_QUOTA_FIELDS)
|
||||
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(default_role)
|
||||
@ -263,26 +251,17 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
'group_list',
|
||||
'role_list',
|
||||
'domain_get'),
|
||||
api.neutron: ('is_extension_supported',
|
||||
'tenant_quota_get',
|
||||
'is_router_enabled',),
|
||||
quotas: ('get_default_quota_data',)})
|
||||
@test.update_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
quotas: ('get_default_quota_data',
|
||||
'get_disabled_quotas')})
|
||||
def test_add_project_get_with_neutron(self):
|
||||
quota = self.quotas.first()
|
||||
neutron_quotas = self.neutron_quotas.first()
|
||||
quota += self.cinder_quotas.first()
|
||||
quota += self.neutron_quotas.first()
|
||||
|
||||
quotas.get_default_quota_data(IsA(http.HttpRequest)) \
|
||||
.AndReturn(quota)
|
||||
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'security-group').AndReturn(True)
|
||||
api.neutron.is_router_enabled(
|
||||
IsA(http.HttpRequest)).AndReturn(True)
|
||||
api.neutron.tenant_quota_get(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(neutron_quotas)
|
||||
quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
|
||||
.AndReturn(set())
|
||||
api.keystone.get_default_role(IsA(http.HttpRequest)) \
|
||||
.MultipleTimes().AndReturn(self.roles.first())
|
||||
api.keystone.user_list(IsA(http.HttpRequest), domain=None) \
|
||||
@ -315,7 +294,7 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
step = workflow.get_step("createprojectinfoaction")
|
||||
self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
|
||||
self.assertEqual(step.action.initial['subnet'],
|
||||
neutron_quotas.get('subnet').limit)
|
||||
self.neutron_quotas.first().get('subnet').limit)
|
||||
|
||||
@override_settings(PROJECT_TABLE_EXTRA_INFO={'phone_num': 'Phone Number'})
|
||||
@test.create_stubs({api.keystone: ('get_default_role',
|
||||
@ -415,17 +394,15 @@ class CreateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.test_add_project_post()
|
||||
|
||||
@test.create_stubs({api.neutron: ('is_extension_supported',
|
||||
'is_quotas_extension_supported',
|
||||
'tenant_quota_update')})
|
||||
@test.update_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
def test_add_project_post_with_neutron(self):
|
||||
quota_data = self.neutron_quotas.first()
|
||||
neutron_updated_quota = dict([(key, quota_data.get(key).limit)
|
||||
for key in quotas.NEUTRON_QUOTA_FIELDS])
|
||||
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'security-group').AndReturn(True)
|
||||
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.neutron.is_quotas_extension_supported(IsA(http.HttpRequest)) \
|
||||
.AndReturn(True)
|
||||
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
|
||||
self.tenant.id,
|
||||
**neutron_updated_quota)
|
||||
@ -1105,8 +1082,7 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
self.assertMessageCount(error=0, warning=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.neutron: ('is_extension_supported',
|
||||
'tenant_quota_get',
|
||||
@test.create_stubs({api.neutron: ('is_quotas_extension_supported',
|
||||
'tenant_quota_update')})
|
||||
@test.update_settings(OPENSTACK_NEUTRON_NETWORK={'enable_quotas': True})
|
||||
def test_update_project_save_with_neutron(self):
|
||||
@ -1114,11 +1090,8 @@ class UpdateProjectWorkflowTests(test.BaseAdminViewTests):
|
||||
neutron_updated_quota = dict([(key, quota_data.get(key).limit)
|
||||
for key in quotas.NEUTRON_QUOTA_FIELDS])
|
||||
|
||||
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'quotas') \
|
||||
.MultipleTimes().AndReturn(True)
|
||||
api.neutron.tenant_quota_get(IsA(http.HttpRequest),
|
||||
tenant_id=self.tenant.id) \
|
||||
.AndReturn(quota_data)
|
||||
api.neutron.is_quotas_extension_supported(IsA(http.HttpRequest)) \
|
||||
.AndReturn(True)
|
||||
api.neutron.tenant_quota_update(IsA(http.HttpRequest),
|
||||
self.tenant.id,
|
||||
**neutron_updated_quota)
|
||||
|
@ -170,27 +170,8 @@ class CreateProjectView(workflows.WorkflowView):
|
||||
if api.keystone.is_cloud_admin(self.request):
|
||||
try:
|
||||
quota_defaults = quotas.get_default_quota_data(self.request)
|
||||
|
||||
try:
|
||||
if api.base.is_service_enabled(
|
||||
self.request, 'network') and \
|
||||
api.neutron.is_quotas_extension_supported(
|
||||
self.request):
|
||||
# TODO(jpichon): There is no API to access the Neutron
|
||||
# default quotas (LP#1204956). For now, use the values
|
||||
# from the current project.
|
||||
project_id = self.request.user.project_id
|
||||
quota_defaults += api.neutron.tenant_quota_get(
|
||||
self.request,
|
||||
tenant_id=project_id)
|
||||
except Exception:
|
||||
error_msg = _('Unable to retrieve default Neutron quota '
|
||||
'values.')
|
||||
self.add_error_to_step(error_msg, 'create_quotas')
|
||||
|
||||
for field in quotas.QUOTA_FIELDS:
|
||||
initial[field] = quota_defaults.get(field).limit
|
||||
|
||||
except Exception:
|
||||
error_msg = _('Unable to retrieve default quota values.')
|
||||
self.add_error_to_step(error_msg, 'create_quotas')
|
||||
@ -246,11 +227,6 @@ class UpdateProjectView(workflows.WorkflowView):
|
||||
if keystone.is_cloud_admin(self.request):
|
||||
quota_data = quotas.get_tenant_quota_data(self.request,
|
||||
tenant_id=project_id)
|
||||
if api.base.is_service_enabled(self.request, 'network') and \
|
||||
api.neutron.is_quotas_extension_supported(
|
||||
self.request):
|
||||
quota_data += api.neutron.tenant_quota_get(
|
||||
self.request, tenant_id=project_id)
|
||||
for field in quotas.QUOTA_FIELDS:
|
||||
initial[field] = quota_data.get(field).limit
|
||||
except Exception:
|
||||
|
@ -346,7 +346,7 @@ class QuotaTests(test.APITestCase):
|
||||
_("Unable to retrieve volume limit information."))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
quotas._get_quota_data(self.request, tenant_mode=True)
|
||||
quotas.get_tenant_quota_data(self.request)
|
||||
|
||||
@test.create_stubs({api.base: ('is_service_enabled',),
|
||||
api.cinder: ('tenant_absolute_limits',
|
||||
|
@ -163,83 +163,69 @@ class QuotaUsage(dict):
|
||||
self.usages[name]['available'] = available
|
||||
|
||||
|
||||
def _get_quota_data(request, tenant_mode=True, disabled_quotas=None,
|
||||
tenant_id=None):
|
||||
@profiler.trace
|
||||
def get_default_quota_data(request, disabled_quotas=None, tenant_id=None):
|
||||
quotasets = []
|
||||
if not tenant_id:
|
||||
tenant_id = request.user.tenant_id
|
||||
if disabled_quotas is None:
|
||||
disabled_quotas = get_disabled_quotas(request)
|
||||
|
||||
qs = base.QuotaSet()
|
||||
|
||||
if NOVA_QUOTA_FIELDS - disabled_quotas:
|
||||
if tenant_mode:
|
||||
quotasets.append(nova.tenant_quota_get(request, tenant_id))
|
||||
else:
|
||||
quotasets.append(nova.default_quota_get(request, tenant_id))
|
||||
quotasets.append(nova.default_quota_get(request, tenant_id))
|
||||
|
||||
if CINDER_QUOTA_FIELDS - disabled_quotas:
|
||||
try:
|
||||
if tenant_mode:
|
||||
quotasets.append(cinder.tenant_quota_get(request, tenant_id))
|
||||
else:
|
||||
quotasets.append(cinder.default_quota_get(request, tenant_id))
|
||||
quotasets.append(cinder.default_quota_get(request, tenant_id))
|
||||
except cinder.cinder_exception.ClientException:
|
||||
disabled_quotas.update(CINDER_QUOTA_FIELDS)
|
||||
msg = _("Unable to retrieve volume limit information.")
|
||||
msg = _("Unable to retrieve volume quota information.")
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
if NEUTRON_QUOTA_FIELDS - disabled_quotas:
|
||||
# TODO(jpichon): There is no API to access the Neutron default quotas
|
||||
# (LP#1204956). For now, use the values from the current project.
|
||||
try:
|
||||
quotasets.append(neutron.tenant_quota_get(request,
|
||||
tenant_id=tenant_id))
|
||||
except Exception:
|
||||
disabled_quotas.update(NEUTRON_QUOTA_FIELDS)
|
||||
msg = _('Unable to retrieve Neutron quota information.')
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
qs = base.QuotaSet()
|
||||
for quota in itertools.chain(*quotasets):
|
||||
if quota.name not in disabled_quotas:
|
||||
if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS:
|
||||
qs[quota.name] = quota.limit
|
||||
return qs
|
||||
|
||||
|
||||
@profiler.trace
|
||||
def get_default_quota_data(request, disabled_quotas=None, tenant_id=None):
|
||||
return _get_quota_data(request,
|
||||
tenant_mode=False,
|
||||
disabled_quotas=disabled_quotas,
|
||||
tenant_id=tenant_id)
|
||||
|
||||
|
||||
@profiler.trace
|
||||
def get_tenant_quota_data(request, disabled_quotas=None, tenant_id=None):
|
||||
qs = _get_quota_data(request,
|
||||
tenant_mode=True,
|
||||
disabled_quotas=disabled_quotas,
|
||||
tenant_id=tenant_id)
|
||||
quotasets = []
|
||||
if not tenant_id:
|
||||
tenant_id = request.user.tenant_id
|
||||
if disabled_quotas is None:
|
||||
disabled_quotas = get_disabled_quotas(request)
|
||||
|
||||
# TODO(jpichon): There is no API to get the default system quotas
|
||||
# in Neutron (cf. LP#1204956), so for now handle tenant quotas here.
|
||||
# This should be handled in _get_quota_data() eventually.
|
||||
if NOVA_QUOTA_FIELDS - disabled_quotas:
|
||||
quotasets.append(nova.tenant_quota_get(request, tenant_id))
|
||||
|
||||
# TODO(amotoki): Purge this tricky usage.
|
||||
# openstack_dashboard/dashboards/identity/projects/views.py
|
||||
# calls get_tenant_quota_data directly and it expects
|
||||
# neutron data is not returned.
|
||||
if not disabled_quotas:
|
||||
return qs
|
||||
if CINDER_QUOTA_FIELDS - disabled_quotas:
|
||||
try:
|
||||
quotasets.append(cinder.tenant_quota_get(request, tenant_id))
|
||||
except cinder.cinder_exception.ClientException:
|
||||
disabled_quotas.update(CINDER_QUOTA_FIELDS)
|
||||
msg = _("Unable to retrieve volume limit information.")
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
# Check if neutron is enabled by looking for network
|
||||
if not (NEUTRON_QUOTA_FIELDS - disabled_quotas):
|
||||
return qs
|
||||
|
||||
_get_neutron_quota_data(request, qs, disabled_quotas, tenant_id)
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
|
||||
tenant_id = tenant_id or request.user.tenant_id
|
||||
neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
|
||||
|
||||
for quota_name in NEUTRON_QUOTA_FIELDS:
|
||||
if quota_name not in disabled_quotas:
|
||||
quota_data = neutron_quotas.get(quota_name).limit
|
||||
qs.add(base.QuotaSet({quota_name: quota_data}))
|
||||
if NEUTRON_QUOTA_FIELDS - disabled_quotas:
|
||||
quotasets.append(neutron.tenant_quota_get(request, tenant_id))
|
||||
|
||||
qs = base.QuotaSet()
|
||||
for quota in itertools.chain(*quotasets):
|
||||
if quota.name not in disabled_quotas and quota.name in QUOTA_FIELDS:
|
||||
qs[quota.name] = quota.limit
|
||||
return qs
|
||||
|
||||
|
||||
@ -345,6 +331,18 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
|
||||
request, usages, disabled_quotas, tenant_id)
|
||||
|
||||
|
||||
def _get_neutron_quota_data(request, qs, disabled_quotas, tenant_id):
|
||||
tenant_id = tenant_id or request.user.tenant_id
|
||||
neutron_quotas = neutron.tenant_quota_get(request, tenant_id)
|
||||
|
||||
for quota_name in NEUTRON_QUOTA_FIELDS:
|
||||
if quota_name not in disabled_quotas:
|
||||
quota_data = neutron_quotas.get(quota_name).limit
|
||||
qs.add(base.QuotaSet({quota_name: quota_data}))
|
||||
|
||||
return qs
|
||||
|
||||
|
||||
def _get_tenant_network_usages_legacy(request, usages, disabled_quotas,
|
||||
tenant_id):
|
||||
qs = base.QuotaSet()
|
||||
|
Loading…
x
Reference in New Issue
Block a user