nova-net: add more useful logging before raising FixedIpLimitExceeded

The OverQuota exception that we get back from the DB API contains some
useful information about the quota limits for the project and resource
and the current usage, so we can log that before raising
FixedIpLimitExceeded. Also logs the actual project ID passed to
quotas.reserve rather than context.project_id since it's possible those
are different.

This should help us figure out if we're leaking resources in gate runs.

Related-Bug: #1353962

Change-Id: Ia8a6d2336ddbbe28178be8d3ce4d97e6d4ab3787
This commit is contained in:
Matt Riedemann 2014-10-06 08:04:01 -07:00
parent 8ba0d9188d
commit 044b18e7f0
2 changed files with 14 additions and 5 deletions

View File

@ -39,7 +39,7 @@ from oslo import messaging
from nova import conductor
from nova import context
from nova import exception
from nova.i18n import _, _LE
from nova.i18n import _, _LE, _LW
from nova import ipv6
from nova import manager
from nova.network import api as network_api
@ -870,9 +870,16 @@ class NetworkManager(manager.Manager):
quotas.reserve(context, fixed_ips=1, project_id=quota_project,
user_id=quota_user)
cleanup.append(functools.partial(quotas.rollback, context))
except exception.OverQuota:
LOG.debug("Quota exceeded for %s, tried to allocate "
"fixed IP", context.project_id)
except exception.OverQuota as exc:
quotas = exc.kwargs['quotas']
headroom = exc.kwargs['headroom']
allowed = quotas['fixed_ips']
used = allowed - headroom['fixed_ips']
LOG.warn(_LW("Quota exceeded for project %(pid)s, tried to "
"allocate fixed IP. %(used)s of %(allowed)s are in "
"use or are already reserved."),
{'pid': quota_project, 'used': used, 'allowed': allowed},
instance_uuid=instance_id)
raise exception.FixedIpLimitExceeded()
try:

View File

@ -701,7 +701,9 @@ class FlatNetworkTestCase(test.TestCase):
inst = objects.Instance()
inst['uuid'] = 'nosuch'
get_by_uuid.return_value = inst
reserve.side_effect = exception.OverQuota(overs='testing')
reserve.side_effect = exception.OverQuota(overs='testing',
quotas={'fixed_ips': 10},
headroom={'fixed_ips': 0})
util_method.return_value = ('foo', 'bar')
self.assertRaises(exception.FixedIpLimitExceeded,
self.network.allocate_fixed_ip,