Merge "Ensure compatibility with all versions of gnocchiclient."

This commit is contained in:
Zuul 2017-12-12 22:31:11 +00:00 committed by Gerrit Code Review
commit d1c93fdbeb
1 changed files with 19 additions and 6 deletions

View File

@ -254,9 +254,15 @@ class GnocchiStorage(storage.BaseStorage):
except gexceptions.MetricNotFound:
return
if len(r) > 0:
# (aolwas) According http://gnocchi.xyz/rest.html#metrics,
# gnocchi always returns measures ordered by timestamp
return ck_utils.dt2ts(dateutil.parser.parse(r[-1][0]))
# NOTE(lukapeschke) Since version 5.0.0, gnocchiclient returns a
# datetime object instead of a timestamp. This fixture is made
# to ensure compatibility with all versions
try:
# (aolwas) According http://gnocchi.xyz/rest.html#metrics,
# gnocchi always returns measures ordered by timestamp
return ck_utils.dt2ts(dateutil.parser.parse(r[-1][0]))
except TypeError:
return ck_utils.dt2ts(r[-1][0])
def get_total(self, begin=None, end=None, tenant_id=None,
service=None, groupby=None):
@ -316,9 +322,16 @@ class GnocchiStorage(storage.BaseStorage):
project_id=None)
def _to_cloudkitty(self, res_type, resource_data, measure):
begin = dateutil.parser.parse(measure[0])
end = (dateutil.parser.parse(measure[0]) +
datetime.timedelta(seconds=self._period))
# NOTE(lukapeschke) Since version 5.0.0, gnocchiclient returns a
# datetime object instead of a timestamp. This fixture is made
# to ensure compatibility with all versions
try:
begin = dateutil.parser.parse(measure[0])
end = (dateutil.parser.parse(measure[0]) +
datetime.timedelta(seconds=self._period))
except TypeError:
begin = measure[0]
end = begin + datetime.timedelta(seconds=self._period)
cost = decimal.Decimal(measure[2])
# Rating informations
rating_dict = {}