diff --git a/ceilometer/alarm/evaluator/__init__.py b/ceilometer/alarm/evaluator/__init__.py index 03329b1d5..f09f478f3 100644 --- a/ceilometer/alarm/evaluator/__init__.py +++ b/ceilometer/alarm/evaluator/__init__.py @@ -93,7 +93,7 @@ class Evaluator(object): if not alarm.time_constraints: return True - now_utc = timeutils.utcnow() + now_utc = timeutils.utcnow().replace(tzinfo=pytz.utc) for tc in alarm.time_constraints: tz = pytz.timezone(tc['timezone']) if tc['timezone'] else None now_tz = now_utc.astimezone(tz) if tz else now_utc diff --git a/ceilometer/tests/alarm/evaluator/test_base.py b/ceilometer/tests/alarm/evaluator/test_base.py index 3a0b62b67..1aa6f24a2 100644 --- a/ceilometer/tests/alarm/evaluator/test_base.py +++ b/ceilometer/tests/alarm/evaluator/test_base.py @@ -18,7 +18,6 @@ """ import datetime import mock -import pytz from ceilometer.alarm import evaluator from ceilometer.openstack.common import test @@ -122,6 +121,9 @@ class TestEvaluatorBaseClass(test.BaseTestCase): @mock.patch.object(timeutils, 'utcnow') def test_base_time_constraints_timezone(self, mock_utcnow): alarm = mock.MagicMock() + cls = evaluator.Evaluator + mock_utcnow.return_value = datetime.datetime(2014, 1, 1, 11, 0, 0) + alarm.time_constraints = [ {'name': 'test', 'description': 'test', @@ -129,13 +131,13 @@ class TestEvaluatorBaseClass(test.BaseTestCase): 'duration': 10800, # 3 hours 'timezone': 'Europe/Ljubljana'} ] - cls = evaluator.Evaluator - dt_eu = datetime.datetime(2014, 1, 1, 12, 0, 0, - tzinfo=pytz.timezone('Europe/Ljubljana')) - dt_us = datetime.datetime(2014, 1, 1, 12, 0, 0, - tzinfo=pytz.timezone('US/Eastern')) - mock_utcnow.return_value = dt_eu.astimezone(pytz.UTC) self.assertTrue(cls.within_time_constraint(alarm)) - mock_utcnow.return_value = dt_us.astimezone(pytz.UTC) + alarm.time_constraints = [ + {'name': 'test2', + 'description': 'test2', + 'start': '0 11 * * *', # daily at 11:00 + 'duration': 10800, # 3 hours + 'timezone': 'US/Eastern'} + ] self.assertFalse(cls.within_time_constraint(alarm))