From 60fd4de2b305d8800d3c101b3b16a498ca3ec1a3 Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Wed, 22 Aug 2018 15:20:17 +0100 Subject: [PATCH] Fix fernet token test/rotate to use UTC only The test/code was using localtime; this changes it to UTC so that DST changes don't affect rotations. Change-Id: I1c8247c08103833a842c422e19b5cd121515c054 --- hooks/keystone_utils.py | 3 ++- unit_tests/test_keystone_utils.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hooks/keystone_utils.py b/hooks/keystone_utils.py index a02b0171..970979f8 100644 --- a/hooks/keystone_utils.py +++ b/hooks/keystone_utils.py @@ -2069,7 +2069,8 @@ def fernet_keys_rotate_and_sync(log_func=log): if last_rotation + rotation_time > now: # Nothing to do as not reached rotation time log_func("No rotation until at least {}" - .format(time.ctime(last_rotation + rotation_time)), + .format( + time.asctime(time.gmtime(last_rotation + rotation_time))), level=DEBUG) return # now rotate the keys and sync them diff --git a/unit_tests/test_keystone_utils.py b/unit_tests/test_keystone_utils.py index fae3cc57..94a6ed89 100644 --- a/unit_tests/test_keystone_utils.py +++ b/unit_tests/test_keystone_utils.py @@ -1259,7 +1259,8 @@ class TestKeystoneUtils(CharmTestCase): mock_os.stat.side_effect = None # now set up the times, so that it still shouldn't be called. self.time.time.return_value = 30 - self.time.ctime = time.ctime + self.time.gmtime = time.gmtime + self.time.asctime = time.asctime _stat = MagicMock() _stat.st_mtime = 10 mock_os.stat.return_value = _stat