Quotas for users with admin role do not work
The quotas code does not isloate counts to resources within the current tenant/project. So if a user with the admin role makes calls for quota items, the admin role will have counts of a global list of resources. This changes that for the tenant quota call to fallback to the request.user.project_id if no project was otherwise specified for the tenant quota api call. Change-Id: Ib0e6ce7774c4c03686a044f233dbb9aa36dbe1b9 Closes-bug: #1391242
This commit is contained in:
parent
ffd442dee4
commit
f5b77f9a14
@ -298,7 +298,9 @@ class FloatingIpNeutronViewTests(FloatingIpViewTests):
|
||||
.AndReturn(self.quotas.first())
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.flavors.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest)) \
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([servers, False])
|
||||
api.neutron.is_extension_supported(
|
||||
IsA(http.HttpRequest), 'security-group').AndReturn(True)
|
||||
|
@ -73,11 +73,14 @@ class QuotaTests(test.APITestCase):
|
||||
.AndReturn(True)
|
||||
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.floating_ips.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest)) \
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([servers, False])
|
||||
cinder.volume_list(IsA(http.HttpRequest)) \
|
||||
opts = {'alltenants': 1, 'tenant_id': self.request.user.tenant_id}
|
||||
cinder.volume_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.volumes.list())
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest)) \
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.snapshots.list())
|
||||
cinder.tenant_quota_get(IsA(http.HttpRequest), '1') \
|
||||
.AndReturn(self.cinder_quotas.first())
|
||||
@ -112,7 +115,9 @@ class QuotaTests(test.APITestCase):
|
||||
.AndReturn(True)
|
||||
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.floating_ips.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest)) \
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([servers, False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
@ -147,7 +152,10 @@ class QuotaTests(test.APITestCase):
|
||||
.AndReturn(True)
|
||||
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn([])
|
||||
api.nova.server_list(IsA(http.HttpRequest)).AndReturn([[], False])
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([[], False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -189,11 +197,14 @@ class QuotaTests(test.APITestCase):
|
||||
.AndReturn(True)
|
||||
api.network.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn(self.floating_ips.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest)) \
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([servers, False])
|
||||
cinder.volume_list(IsA(http.HttpRequest)) \
|
||||
opts = {'alltenants': 1, 'tenant_id': self.request.user.tenant_id}
|
||||
cinder.volume_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.volumes.list())
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest)) \
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.snapshots.list())
|
||||
cinder.tenant_quota_get(IsA(http.HttpRequest), '1') \
|
||||
.AndReturn(self.cinder_quotas.first())
|
||||
@ -231,11 +242,14 @@ class QuotaTests(test.APITestCase):
|
||||
.AndReturn(self.quotas.first())
|
||||
api.network.floating_ip_supported(IsA(http.HttpRequest)) \
|
||||
.AndReturn(False)
|
||||
api.nova.server_list(IsA(http.HttpRequest)) \
|
||||
search_opts = {'tenant_id': self.request.user.tenant_id}
|
||||
api.nova.server_list(IsA(http.HttpRequest), search_opts=search_opts,
|
||||
all_tenants=True) \
|
||||
.AndReturn([servers, False])
|
||||
cinder.volume_list(IsA(http.HttpRequest)) \
|
||||
opts = {'alltenants': 1, 'tenant_id': self.request.user.tenant_id}
|
||||
cinder.volume_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.volumes.list())
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest)) \
|
||||
cinder.volume_snapshot_list(IsA(http.HttpRequest), opts) \
|
||||
.AndReturn(self.snapshots.list())
|
||||
cinder.tenant_quota_get(IsA(http.HttpRequest), '1') \
|
||||
.AndReturn(self.cinder_quotas.first())
|
||||
|
@ -254,7 +254,12 @@ def get_disabled_quotas(request):
|
||||
|
||||
@memoized
|
||||
def tenant_quota_usages(request, tenant_id=None):
|
||||
"""Get our quotas and construct our usage object."""
|
||||
"""Get our quotas and construct our usage object.
|
||||
If no tenant_id is provided, a the request.user.project_id
|
||||
is assumed to be used
|
||||
"""
|
||||
if not tenant_id:
|
||||
tenant_id = request.user.project_id
|
||||
|
||||
disabled_quotas = get_disabled_quotas(request)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user