Use isoformat() instead of isotime() in InfluxDB storage driver

This updates the InfluxDB v2 storage driver in order to use
datetime.isoformat() instead of cloudkitty.utils.isotime() for formatting
of timezone-aware datetime objects.

Change-Id: Ief7049cafeddbf97dae7dafcf9562e6ffc613bc9
This commit is contained in:
Luka Peschke
2019-08-02 14:13:39 +02:00
parent e552c3851f
commit cb6a653879
2 changed files with 10 additions and 11 deletions

View File

@@ -23,7 +23,6 @@ import six
from cloudkitty.storage import v2 as v2_storage
from cloudkitty import tzutils
from cloudkitty import utils
LOG = log.getLogger(__name__)
@@ -208,10 +207,10 @@ class InfluxClient(object):
def _get_time_query_delete(begin, end):
output = ""
if begin:
output += " WHERE time >= '{}'".format(utils.isotime(begin))
output += " WHERE time >= '{}'".format(begin.isoformat())
if end:
output += " AND " if output else " WHERE "
output += "time < '{}'".format(utils.isotime(end))
output += "time < '{}'".format(end.isoformat())
return output
def delete(self, begin, end, filters):

View File

@@ -88,8 +88,8 @@ class TestInfluxClient(unittest.TestCase):
self._storage.delete(begin=datetime(2019, 1, 1),
end=datetime(2019, 1, 2))
m.assert_called_once_with(
"""DELETE FROM "dataframes" WHERE time >= '2019-01-01T00:00:00Z'"""
""" AND time < '2019-01-02T00:00:00Z';""")
"""DELETE FROM "dataframes" WHERE time >= '2019-01-01T00:00:00'"""
""" AND time < '2019-01-02T00:00:00';""")
def test_delete_begin_end_filters(self):
self._storage._conn._conn.query = m = mock.MagicMock()
@@ -97,8 +97,8 @@ class TestInfluxClient(unittest.TestCase):
begin=datetime(2019, 1, 1), end=datetime(2019, 1, 2),
filters={'project_id': 'foobar'})
m.assert_called_once_with(
"""DELETE FROM "dataframes" WHERE time >= '2019-01-01T00:00:00Z'"""
""" AND time < '2019-01-02T00:00:00Z' AND "project_id"='foobar';"""
"""DELETE FROM "dataframes" WHERE time >= '2019-01-01T00:00:00'"""
""" AND time < '2019-01-02T00:00:00' AND "project_id"='foobar';"""
)
def test_delete_end_filters(self):
@@ -106,7 +106,7 @@ class TestInfluxClient(unittest.TestCase):
self._storage.delete(end=datetime(2019, 1, 2),
filters={'project_id': 'foobar'})
m.assert_called_once_with(
"""DELETE FROM "dataframes" WHERE time < '2019-01-02T00:00:00Z' """
"""DELETE FROM "dataframes" WHERE time < '2019-01-02T00:00:00' """
"""AND "project_id"='foobar';""")
def test_delete_begin_filters(self):
@@ -114,17 +114,17 @@ class TestInfluxClient(unittest.TestCase):
self._storage.delete(begin=datetime(2019, 1, 2),
filters={'project_id': 'foobar'})
m.assert_called_once_with(
"""DELETE FROM "dataframes" WHERE time >= '2019-01-02T00:00:00Z'"""
"""DELETE FROM "dataframes" WHERE time >= '2019-01-02T00:00:00'"""
""" AND "project_id"='foobar';""")
def test_delete_begin(self):
self._storage._conn._conn.query = m = mock.MagicMock()
self._storage.delete(begin=datetime(2019, 1, 2))
m.assert_called_once_with("""DELETE FROM "dataframes" WHERE """
"""time >= '2019-01-02T00:00:00Z';""")
"""time >= '2019-01-02T00:00:00';""")
def test_delete_end(self):
self._storage._conn._conn.query = m = mock.MagicMock()
self._storage.delete(end=datetime(2019, 1, 2))
m.assert_called_once_with("""DELETE FROM "dataframes" WHERE """
"""time < '2019-01-02T00:00:00Z';""")
"""time < '2019-01-02T00:00:00';""")