From 79acbf0ad730a4f58f7606c2f093b22a968f5562 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 13 Mar 2013 13:24:23 -0400 Subject: Fix use of potentially-stale instance_type in tenant_usage The simple_tenant_usage API extension may return incorrect billing information if a flavor is changed or deleted while an instance using it is still running. This makes it use the stashed instance_type instead. Fixes bug 1154707 Change-Id: Ifce33488e5ef8aa942051d882407a3e2d088aaf5 --- nova/api/openstack/compute/contrib/simple_tenant_usage.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index f759e90b0..0fa9b9e40 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -24,7 +24,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova.compute import api -from nova import exception +from nova.compute import instance_types from nova.openstack.common import timeutils authorize_show = extensions.extension_authorizer('compute', @@ -119,18 +119,7 @@ class SimpleTenantUsageController(object): info['hours'] = self._hours_for(instance, period_start, period_stop) - flavor_type = instance['instance_type_id'] - - if not flavors.get(flavor_type): - try: - it_ref = compute_api.get_instance_type(context, - flavor_type) - flavors[flavor_type] = it_ref - except exception.InstanceTypeNotFound: - # can't bill if there is no instance type - continue - - flavor = flavors[flavor_type] + flavor = instance_types.extract_instance_type(instance) info['instance_id'] = instance['uuid'] info['name'] = instance['display_name'] -- cgit