From 869443f41c8826c9a4de1dcc65c5a5354b623a04 Mon Sep 17 00:00:00 2001 From: RongzeZhu Date: Sun, 2 Sep 2012 18:43:56 +0800 Subject: Fix simple_tenant_usage's handing of future end times Fixes bug #1043999 simple_tenant_usage returns the usage in the range between the supplied start and end query parameters. The _hours_for() method calculates the number of hours the instance was running in this range, even if the end time is in the future. By default, python-novaclient requests usage between 4 weeks ago and tomorrow. This means we a report which accounts for 24 hours of extra running time for each currently running instance. Fix this by clamping the period of the returned report at the current time. Change-Id: I61c211fd85b729aaeaac6ef24644ee19eb5bb6b0 --- nova/api/openstack/compute/contrib/simple_tenant_usage.py | 6 ++++++ 1 file changed, 6 insertions(+) (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 75a3ddfc1..ee7924dec 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -218,6 +218,9 @@ class SimpleTenantUsageController(object): authorize_list(context) (period_start, period_stop, detailed) = self._get_datetime_range(req) + now = timeutils.utcnow() + if period_stop > now: + period_stop = now usages = self._tenant_usages_for_period(context, period_start, period_stop, @@ -233,6 +236,9 @@ class SimpleTenantUsageController(object): authorize_show(context, {'project_id': tenant_id}) (period_start, period_stop, ignore) = self._get_datetime_range(req) + now = timeutils.utcnow() + if period_stop > now: + period_stop = now usage = self._tenant_usages_for_period(context, period_start, period_stop, -- cgit