Fix format error in claims.

I have now seen two bug reports today about log message formatting
in the claims code. I'm not 100% sure what's going on here, but
I've removed the use of locals() in the hope it makes it clearer.
I've also moved to treating limits as floats because I think it
makes the messages clearer, but it is not a functional change.

Resolves bug 1175923.

Change-Id: I8b7b31f2637d1ab41d0fb2f274545181f9fddd9d
This commit is contained in:
Michael Still 2013-05-08 12:02:59 +10:00
parent f917d24bd3
commit f53df8c4f5
1 changed files with 15 additions and 10 deletions

View File

@ -159,28 +159,33 @@ class Claim(NopClaim):
"""Test if the given type of resource needed for a claim can be safely
allocated.
"""
msg = _("Total %(type_)s: %(total)d %(unit)s, used: %(used)d %(unit)s")
LOG.audit(msg % locals(), instance=self.instance)
LOG.audit(_('Total %(type)s: %(total)d %(unit)s, used: %(used).02f '
'%(unit)s'),
{'type': type_, 'total': total, 'unit': unit, 'used': used},
instance=self.instance)
if limit is None:
# treat resource as unlimited:
LOG.audit(_("%(type_)s limit not specified, defaulting to "
"unlimited") % locals(), instance=self.instance)
LOG.audit(_('%(type)s limit not specified, defaulting to '
'unlimited'), {'type': type_}, instance=self.instance)
return True
free = limit - used
# Oversubscribed resource policy info:
msg = _("%(type_)s limit: %(limit)d %(unit)s, free: %(free)d "
"%(unit)s") % locals()
LOG.audit(msg, instance=self.instance)
LOG.audit(_('%(type)s limit: %(limit).02f %(unit)s, free: %(free).02f '
'%(unit)s'),
{'type': type_, 'limit': limit, 'free': free, 'unit': unit},
instance=self.instance)
can_claim = requested <= free
if not can_claim:
msg = _("Unable to claim resources. Free %(type_)s %(free)d "
"%(unit)s < requested %(requested)d %(unit)s") % locals()
LOG.info(msg, instance=self.instance)
LOG.info(_('Unable to claim resources. Free %(type)s %(free).02f '
'%(unit)s < requested %(requested)d %(unit)s'),
{'type': type_, 'free': free, 'unit': unit,
'requested': requested},
instance=self.instance)
return can_claim