Take shared subnets into account for quotas

Previously, shared subnets were ignored by collecting used
networks; the "Create subnet" button is still enabled, but
subnet creation is forbidden by neutron due to quota reached.

Change-Id: I20b3373ab86631922945285a12ca4810b707b0be
Closes-Bug: #1588764
This commit is contained in:
Itxaka 2016-06-14 13:37:08 +02:00 committed by Itxaka Serrano Garcia
parent 36e6bea4ce
commit 028aecc192
2 changed files with 15 additions and 5 deletions

View File

@ -390,8 +390,10 @@ class FloatingIpNeutronViewTests(FloatingIpViewTests):
.AndReturn(self.neutron_quotas.first())
api.neutron.router_list(IsA(http.HttpRequest)) \
.AndReturn(self.routers.list())
api.neutron.subnet_list(IsA(http.HttpRequest)) \
api.neutron.subnet_list(IsA(http.HttpRequest), shared=False) \
.AndReturn(self.subnets.list())
api.neutron.subnet_list(IsA(http.HttpRequest), shared=True) \
.AndReturn(list())
api.neutron.network_list(IsA(http.HttpRequest), shared=False) \
.AndReturn(self.networks.list())
api.neutron.network_list(IsA(http.HttpRequest), shared=True) \
@ -449,7 +451,9 @@ class FloatingIpNeutronViewTests(FloatingIpViewTests):
.AndReturn(self.neutron_quotas.first())
api.neutron.router_list(IsA(http.HttpRequest)) \
.AndReturn(self.routers.list())
api.neutron.subnet_list(IsA(http.HttpRequest)) \
api.neutron.subnet_list(IsA(http.HttpRequest), shared=False) \
.AndReturn(list())
api.neutron.subnet_list(IsA(http.HttpRequest), shared=True) \
.AndReturn(self.subnets.list())
api.neutron.network_list(IsA(http.HttpRequest), shared=False) \
.AndReturn(list())

View File

@ -324,9 +324,15 @@ def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
usages.tally('networks', len(shared_networks))
if 'subnet' not in disabled_quotas:
subnets = []
subnets = neutron.subnet_list(request)
usages.tally('subnets', len(subnets))
subnets = neutron.subnet_list(request, shared=False)
if tenant_id:
subnets = [sub for sub in subnets if sub.tenant_id == tenant_id]
# get shared subnets
shared_subnets = neutron.subnet_list(request, shared=True)
if tenant_id:
shared_subnets = [subnet for subnet in shared_subnets
if subnet.tenant_id == tenant_id]
usages.tally('subnets', len(subnets) + len(shared_subnets))
if 'router' not in disabled_quotas:
routers = []