Make sure we always get all limits

When checking with nova for the absolute limits
we were not taking into account the reserved
quotas (i.e. instance in rebuilding will take
cpu and ram) so this could lead to wrongly
thinking that the user could launch more instances
that its quota allowed. It also made the overview
page display wrong quotas as it didnt took into
account those reserved resources.

Change-Id: If51470d185ddc122acbdf4cf0d0fd952f3f791a0
Closes-bug: 1561310
This commit is contained in:
Itxaka 2016-04-21 12:18:30 +02:00 committed by Itxaka Serrano Garcia
parent 377da87e3c
commit 35eb25a955
9 changed files with 27 additions and 22 deletions

View File

@ -84,7 +84,7 @@ class UsageViewTests(test.BaseAdminViewTests):
now.month,
now.day, 23, 59, 59, 0)) \
.AndReturn(usage_list)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'security-group').AndReturn(True)
@ -174,7 +174,7 @@ class UsageViewTests(test.BaseAdminViewTests):
now.month,
now.day, 23, 59, 59, 0)) \
.AndReturn(usage_obj)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True)\
.AndReturn(self.limits['absolute'])
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'security-group').AndReturn(True)

View File

@ -1567,7 +1567,7 @@ class UsageViewTests(test.BaseAdminViewTests):
api.nova.usage_get(IsA(http.HttpRequest),
self.tenant.id,
start, end).AndReturn(usage_obj)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True)\
.AndReturn(self.limits['absolute'])
api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndReturn(self.cinder_limits['absolute'])

View File

@ -1573,7 +1573,7 @@ class InstanceTests(helpers.TestCase):
'ServerGroups', IsA(http.HttpRequest)).AndReturn(True)
api.nova.server_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.server_groups.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True)\
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
@ -1823,7 +1823,7 @@ class InstanceTests(helpers.TestCase):
'ServerGroups', IsA(http.HttpRequest)).AndReturn(True)
api.nova.server_group_list(IsA(http.HttpRequest)) \
.AndReturn(self.server_groups.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True)\
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
@ -2566,7 +2566,7 @@ class InstanceTests(helpers.TestCase):
.AndReturn(True)
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.glance.image_list_detailed(IsA(http.HttpRequest),
filters={'is_public': True,
@ -2985,7 +2985,7 @@ class InstanceTests(helpers.TestCase):
IsA(http.HttpRequest)).AndReturn(True)
api.nova.extension_supported('ServerGroups',
IsA(http.HttpRequest)).AndReturn(False)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndRaise(self.exceptions.nova)
@ -3249,7 +3249,7 @@ class InstanceTests(helpers.TestCase):
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
@ -3373,7 +3373,7 @@ class InstanceTests(helpers.TestCase):
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
@ -3512,7 +3512,7 @@ class InstanceTests(helpers.TestCase):
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
@ -3662,7 +3662,8 @@ class InstanceTests(helpers.TestCase):
api.nova.flavor_list(
IsA(http.HttpRequest)).AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(
IsA(http.HttpRequest)).AndReturn(self.limits['absolute'])
IsA(http.HttpRequest), reserved=True
).AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(
IsA(http.HttpRequest)).AndReturn(quota_usages)
api.nova.flavor_list(
@ -3806,7 +3807,7 @@ class InstanceTests(helpers.TestCase):
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
quotas.tenant_quota_usages(IsA(http.HttpRequest)) \
.AndReturn(quota_usages)
@ -4189,7 +4190,7 @@ class InstanceTests(helpers.TestCase):
policy_profiles = self.policy_profiles.list()
api.neutron.profile_list(IsA(http.HttpRequest),
'policy').AndReturn(policy_profiles)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('BlockDeviceMappingV2Boot',
IsA(http.HttpRequest)) \
@ -4308,7 +4309,7 @@ class InstanceTests(helpers.TestCase):
.AndReturn(self.flavors.list())
api.nova.flavor_list(IsA(http.HttpRequest)) \
.AndReturn(self.flavors.list())
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \
@ -4382,7 +4383,7 @@ class InstanceTests(helpers.TestCase):
.AndReturn([])
api.nova.flavor_get(IsA(http.HttpRequest), server.flavor['id']) \
.AndRaise(self.exceptions.nova)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
api.nova.extension_supported('DiskConfig',
IsA(http.HttpRequest)) \

View File

@ -392,7 +392,8 @@ class SetInstanceDetailsAction(workflows.Action):
def get_help_text(self, extra_context=None):
extra = {} if extra_context is None else dict(extra_context)
try:
extra['usages'] = api.nova.tenant_absolute_limits(self.request)
extra['usages'] = api.nova.tenant_absolute_limits(self.request,
reserved=True)
extra['usages_json'] = json.dumps(extra['usages'])
flavors = json.dumps([f._info for f in
instance_utils.flavor_list(self.request)])

View File

@ -61,7 +61,8 @@ class SetFlavorChoiceAction(workflows.Action):
def get_help_text(self, extra_context=None):
extra = {} if extra_context is None else dict(extra_context)
try:
extra['usages'] = api.nova.tenant_absolute_limits(self.request)
extra['usages'] = api.nova.tenant_absolute_limits(self.request,
reserved=True)
extra['usages_json'] = json.dumps(extra['usages'])
flavors = json.dumps([f._info for f in
instance_utils.flavor_list(self.request)])

View File

@ -51,10 +51,10 @@ class UsageViewTests(test.TestCase):
.AndReturn(nova_stu_enabled)
if tenant_limits_exception:
api.nova.tenant_absolute_limits(IsA(http.HttpRequest))\
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True)\
.AndRaise(tenant_limits_exception)
else:
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)) \
api.nova.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
.AndReturn(self.limits['absolute'])
if nova_stu_enabled:

View File

@ -317,7 +317,8 @@ class QuotaTests(test.APITestCase):
api.cinder.is_volume_service_enabled(
IsA(http.HttpRequest)
).AndReturn(True)
api.nova.tenant_absolute_limits(IsA(http.HttpRequest)).AndReturn({})
api.nova.tenant_absolute_limits(IsA(http.HttpRequest),
reserved=True).AndReturn({})
api.cinder.tenant_absolute_limits(IsA(http.HttpRequest)) \
.AndRaise(cinder.cinder_exception.ClientException('test'))
exceptions.handle(IsA(http.HttpRequest),

View File

@ -190,7 +190,8 @@ class BaseUsage(object):
def get_limits(self):
try:
self.limits = api.nova.tenant_absolute_limits(self.request)
self.limits = api.nova.tenant_absolute_limits(self.request,
reserved=True)
except Exception:
exceptions.handle(self.request,
_("Unable to retrieve limit information."))

View File

@ -385,7 +385,7 @@ def tenant_limit_usages(request):
limits = {}
try:
limits.update(nova.tenant_absolute_limits(request))
limits.update(nova.tenant_absolute_limits(request, reserved=True))
except Exception:
msg = _("Unable to retrieve compute limit information.")
exceptions.handle(request, msg)