Skip to content

Commit

Permalink
Add job to clean expired console auth tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
tzumainn committed Dec 9, 2024
1 parent 0f7ed83 commit 342a2ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions esi_leap/manager/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
9 changes: 9 additions & 0 deletions esi_leap/tests/manager/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 342a2ee

Please sign in to comment.