Fix the multi-instance quota message
Make sure that when spawning multiple instance, the quota exceeded error still makes sense. Instead of reporting min_count (1) as the requested number, report "between min_count and max_count". Fixes bug 1211347 Change-Id: I5a562253788f93b932ccd99bd1dc6630444bd430
This commit is contained in:
Stanisław Pitucha
committed by
Stanislaw Pitucha
parent
3b2931a5a7
commit
8c169aa41b
2 changed files with 53 additions and 5 deletions
@@ -370,11 +370,24 @@ class API(base.Base):
used = quotas[resource] - headroom[resource]
total_allowed = used + headroom[resource]
overs = ','.join(overs)
LOG.warn(_("%(overs)s quota exceeded for %(pid)s,"
" tried to run %(min_count)s instances. %(msg)s"),
{'overs': overs, 'pid': context.project_id,
'min_count': min_count, 'msg': msg})
requested = dict(instances=min_count, cores=req_cores, ram=req_ram)
params = {'overs': overs, 'pid': context.project_id,
'min_count': min_count, 'max_count': max_count,
'msg': msg}
if min_count == max_count:
LOG.warn(_("%(overs)s quota exceeded for %(pid)s,"
" tried to run %(min_count)d instances. %(msg)s"),
params)
else:
LOG.warn(_("%(overs)s quota exceeded for %(pid)s,"
" tried to run between %(min_count)d and"
"%(max_count)d instances. %(msg)s"),
params)
num_instances = (str(min_count) if min_count == max_count else
"%s-%s" % (min_count, max_count))
requested = dict(instances=num_instances, cores=req_cores,
ram=req_ram)
raise exception.TooManyInstances(overs=overs,
req=requested[resource],
used=used, allowed=total_allowed,
@@ -122,6 +122,41 @@ class _ComputeAPIUnitTestMixIn(object):
instance.obj_reset_changes()
return instance
def test_create_quota_exceeded_messages(self):
image_href = "image_href"
image_id = 0
instance_type = self._create_flavor()
self.mox.StubOutWithMock(self.compute_api, "_get_image")
self.mox.StubOutWithMock(quota.QUOTAS, "limit_check")
self.mox.StubOutWithMock(quota.QUOTAS, "reserve")
quota_exception = exception.OverQuota(
quotas={'instances': 1, 'cores': 1, 'ram': 1},
usages=dict((r, {'in_use': 1, 'reserved': 1}) for r in
['instances', 'cores', 'ram']),
overs=['instances'])
for _unused in range(2):
self.compute_api._get_image(self.context, image_href).AndReturn(
(image_id, {}))
quota.QUOTAS.limit_check(self.context, metadata_items=mox.IsA(int))
quota.QUOTAS.reserve(self.context, instances=40,
cores=mox.IsA(int),
ram=mox.IsA(int)).AndRaise(quota_exception)
self.mox.ReplayAll()
for min_count, message in [(20, '20-40'), (40, '40')]:
try:
self.compute_api.create(self.context, instance_type,
"image_href", min_count=min_count,
max_count=40)
except exception.TooManyInstances as e:
self.assertEqual(message, e.kwargs['req'])
else:
self.fail("Exception not raised")
def test_suspend(self):
# Ensure instance can be suspended.
instance = self._create_instance_obj()
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.