Nova usage report fix

Gracefully handled case where rawdata entry does
not exist for request_id while generating nova usage
audit report.

Change-Id: I675b2b5e9c4be70d45fc2385f1b448c159610f56
This commit is contained in:
Anuj Mathur 2014-05-30 17:02:01 +05:30
parent 655d9acf0a
commit bea3a75a35
2 changed files with 5 additions and 6 deletions

View File

@ -95,10 +95,7 @@ def _get_exists(beginning, ending):
def cell_and_compute(instance, launched_at):
usage = InstanceUsage.find(instance, launched_at)[0]
try:
deployment = usage.latest_deployment_for_request_id()
except IndexError:
deployment = None
cell = (deployment and deployment.name) or '-'
compute = usage.host() or '-'
return cell, compute

View File

@ -185,8 +185,10 @@ class InstanceUsage(models.Model):
return raw and raw.deployment
def latest_raw_for_request_id(self):
return self.request_id and RawData.objects.filter(
request_id=self.request_id).order_by('-id')[0]
raw = []
if self.request_id:
raw = RawData.objects.filter(request_id=self.request_id).order_by('-id')
return (len(raw) > 0 and raw[0]) or None
def host(self):
raw = self.latest_raw_for_request_id()