Catch InstanceNotFound exception

during simple_tenant_usage collection, there is possibility that
instance got delete, so we need to catch the exception because
instance.flavor might cause a instance.get_by_uuid call.

commit b52876f912 mentioned
<This follows the previous patch and makes simple-tenant-usage use
the bundled flavor for basic instance resource usage like everything
else. This is an important step to being able to remove those fields
at some point>
so this patch didn't use the flavor object directly

Change-Id: Icbfd1a4b97873d44bafd16754d09fff7a9d2b7af
Closes-Bug: 1643444
This commit is contained in:
jichenjc 2016-11-18 18:02:11 +08:00
parent 90f01d5ebb
commit 83e6dbf581
1 changed files with 10 additions and 6 deletions

View File

@ -119,14 +119,18 @@ class SimpleTenantUsageController(wsgi.Controller):
info['instance_id'] = instance.uuid
info['name'] = instance.display_name
info['memory_mb'] = instance.flavor.memory_mb
info['local_gb'] = (instance.flavor.root_gb +
instance.flavor.ephemeral_gb)
info['vcpus'] = instance.flavor.vcpus
info['tenant_id'] = instance.project_id
try:
info['memory_mb'] = instance.flavor.memory_mb
info['local_gb'] = (instance.flavor.root_gb +
instance.flavor.ephemeral_gb)
info['vcpus'] = instance.flavor.vcpus
except exception.InstanceNotFound:
# This is rare case, instance disappear during analysis
# As it's just info collection, we can try next one
continue
# NOTE(mriedem): We need to normalize the start/end times back
# to timezone-naive so the response doesn't change after the
# conversion to objects.