diff --git a/gnocchi/aggregates/moving_stats.py b/gnocchi/aggregates/moving_stats.py index fa4290ae..3645a0f3 100644 --- a/gnocchi/aggregates/moving_stats.py +++ b/gnocchi/aggregates/moving_stats.py @@ -16,14 +16,13 @@ import datetime import numpy +from oslo_utils import strutils +from oslo_utils import timeutils import pandas import six from gnocchi import aggregates - -from oslo_utils import strutils -from oslo_utils import timeutils -from pytimeparse import timeparse +from gnocchi import utils class MovingAverage(aggregates.CustomAggregator): @@ -35,7 +34,7 @@ class MovingAverage(aggregates.CustomAggregator): msg = 'Moving aggregate must have window specified.' raise aggregates.CustomAggFailure(msg) try: - return float(timeparse.timeparse(six.text_type(window))) + return utils.to_timespan(six.text_type(window)).total_seconds() except Exception: raise aggregates.CustomAggFailure('Invalid value for window') diff --git a/gnocchi/tests/test_aggregates.py b/gnocchi/tests/test_aggregates.py index 7ff7d490..1100e33c 100644 --- a/gnocchi/tests/test_aggregates.py +++ b/gnocchi/tests/test_aggregates.py @@ -46,14 +46,9 @@ class TestAggregates(tests_base.TestCase): self.assertEqual(60.0, result) window = '60' - self.assertRaises(aggregates.CustomAggFailure, - agg_obj.check_window_valid, - window) - - window = None - self.assertRaises(aggregates.CustomAggFailure, - agg_obj.check_window_valid, - window) + agg_obj = self.custom_agg[agg_method] + result = agg_obj.check_window_valid(window) + self.assertEqual(60.0, result) def _test_create_metric_and_data(self, data, spacing): metric = storage.Metric( diff --git a/gnocchi/utils.py b/gnocchi/utils.py index 851d9150..590088b4 100644 --- a/gnocchi/utils.py +++ b/gnocchi/utils.py @@ -22,7 +22,6 @@ import iso8601 import numpy from oslo_utils import timeutils import pandas as pd -from pytimeparse import timeparse import six import tenacity import uuid @@ -116,11 +115,9 @@ def to_timespan(value): seconds = float(value) except Exception: try: - seconds = timeparse.timeparse(six.text_type(value)) + seconds = pd.Timedelta(six.text_type(value)).total_seconds() except Exception: raise ValueError("Unable to parse timespan") - if seconds is None: - raise ValueError("Unable to parse timespan") if seconds <= 0: raise ValueError("Timespan must be positive") return datetime.timedelta(seconds=seconds) diff --git a/requirements.txt b/requirements.txt index ad86cbc2..79626e71 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,6 @@ oslo.utils>=3.18.0 oslo.middleware>=3.11.0 pandas>=0.17.0 pecan>=0.9 -pytimeparse>=1.1.5 futures jsonpatch cotyledon>=1.5.0