From 342a2ee3a3dcb5e39748c21ebd49e540c1ba0a8b Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Mon, 9 Dec 2024 16:10:29 -0500 Subject: [PATCH] Add job to clean expired console auth tokens --- esi_leap/manager/service.py | 7 +++++++ esi_leap/tests/manager/test_service.py | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/esi_leap/manager/service.py b/esi_leap/manager/service.py index b9db538a..7554c7b0 100644 --- a/esi_leap/manager/service.py +++ b/esi_leap/manager/service.py @@ -14,6 +14,7 @@ from esi_leap.common import statuses import esi_leap.conf from esi_leap.manager import utils +from esi_leap.objects import console_auth_token as cat_obj from esi_leap.objects import lease as lease_obj from esi_leap.objects import offer as offer_obj from oslo_context import context as ctx @@ -53,6 +54,8 @@ def start(self): self.tg.add_timer(EVENT_INTERVAL, self._cancel_leases) LOG.info("Starting _expire_offers periodic job") self.tg.add_timer(EVENT_INTERVAL, self._expire_offers) + LOG.info("Starting _clean_expired_console_tokens periodic job") + self.tg.add_timer(EVENT_INTERVAL, self._clean_expired_console_tokens) def stop(self): super(ManagerService, self).stop() @@ -137,6 +140,10 @@ def _expire_offers(self): offer.status = statuses.ERROR offer.save() + def _clean_expired_console_tokens(self): + LOG.info("Cleaning expired console tokens") + cat_obj.ConsoleAuthToken.clean_expired_console_tokens() + class ManagerEndpoint(object): target = utils.get_target() diff --git a/esi_leap/tests/manager/test_service.py b/esi_leap/tests/manager/test_service.py index 03bb93f6..f0c1f602 100644 --- a/esi_leap/tests/manager/test_service.py +++ b/esi_leap/tests/manager/test_service.py @@ -229,3 +229,12 @@ def test__expire_offers_error(self, mock_ga, mock_utcnow, mock_expire, mock_save ) self.assertEqual(statuses.ERROR, error_offer.status) mock_save.assert_called_once() + + @mock.patch( + "esi_leap.objects.console_auth_token.ConsoleAuthToken.clean_expired_console_tokens" + ) + def test__clean_expired_console_tokens(self, mock_cect): + s = ManagerService() + s._clean_expired_console_tokens() + + mock_cect.assert_called_once