Overwrite Usage class's get() function

base.Resource's get function will call its manager's get() function
with one parameter. However UsageManager's get function takes three
parameters.

Change-Id: I958a55c4d52cec4d1177371b788b3cf788098a6c
Closes-bug: 1552616
This commit is contained in:
Cao ShuFeng 2016-03-03 19:28:55 +08:00
parent d63800d5ec
commit 3a538f6d86
2 changed files with 32 additions and 0 deletions

View File

@ -13,6 +13,8 @@
import datetime
import six
from novaclient.tests.unit import utils
from novaclient.tests.unit.v2 import fakes
from novaclient.v2 import usage
@ -58,3 +60,18 @@ class UsageTest(utils.TestCase):
("start=%s&" % now.isoformat()) +
("end=%s" % now.isoformat()))
self.assertIsInstance(u, usage.Usage)
def test_usage_class_get(self):
start = six.u('2012-01-22T19:48:41.750722')
stop = six.u('2012-01-22T19:48:41.750722')
info = {'tenant_id': 'tenantfoo', 'start': start,
'stop': stop}
u = usage.Usage(self.cs.usage, info)
u.get()
self.assert_request_id(u, fakes.FAKE_REQUEST_ID_LIST)
self.cs.assert_called(
'GET',
"/os-simple-tenant-usage/tenantfoo?start=%s&end=%s" %
(start, stop))

View File

@ -15,6 +15,8 @@
Usage interface.
"""
import oslo_utils
from novaclient import base
@ -25,6 +27,19 @@ class Usage(base.Resource):
def __repr__(self):
return "<ComputeUsage>"
def get(self):
fmt = '%Y-%m-%dT%H:%M:%S.%f'
if self.start and self.stop and self.tenant_id:
# set_loaded() first ... so if we have to bail, we know we tried.
self.set_loaded(True)
start = oslo_utils.timeutils.parse_strtime(self.start, fmt=fmt)
stop = oslo_utils.timeutils.parse_strtime(self.stop, fmt=fmt)
new = self.manager.get(self.tenant_id, start, stop)
if new:
self._add_details(new._info)
self.append_request_ids(new.request_ids)
class UsageManager(base.ManagerWithFind):
"""