Merge "Replace datetime of time_constraints by aware object"
This commit is contained in:
commit
18b95a34b8
@ -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
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user