This repository was archived by the owner on Jun 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +31
-5
lines changed
Expand file tree Collapse file tree 4 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 22import logging
33import os
44import subprocess
5+ import threading
56from retrying import retry
67
78logger = logging .getLogger (__name__ )
9+ # fasteners is for interprocess multiprocessing
10+ # threading.Lock is for multithreading
11+ lock = threading .Lock ()
812
913
1014class KrbCommand ():
@@ -59,6 +63,12 @@ def kdestroy(config):
5963 commands .append (config .ccache_name )
6064 return KrbCommand ._call (config , commands )
6165
66+ @staticmethod
67+ def cache_exists (config ):
68+ with lock :
69+ with fasteners .InterProcessLock (config .ccache_cmd_lockfile ):
70+ return os .path .isfile (config .ccache_name )
71+
6272 @staticmethod
6373 def _call (config , commands ):
6474
@@ -78,5 +88,6 @@ def retriable_call():
7888 custom_env ["LC_ALL" ] = "C"
7989 return subprocess .check_output (commands , universal_newlines = True , env = custom_env )
8090
81- with fasteners .InterProcessLock (config .ccache_cmd_lockfile ):
82- return retriable_call ()
91+ with lock :
92+ with fasteners .InterProcessLock (config .ccache_cmd_lockfile ):
93+ return retriable_call ()
Original file line number Diff line number Diff line change 1- import os
21from datetime import datetime
32import logging
43import threading
@@ -100,7 +99,7 @@ def get_instance(**kwargs):
10099
101100 @staticmethod
102101 def cache_exists (config ):
103- return os . path . isfile (config . ccache_name )
102+ return KrbCommand . cache_exists (config )
104103
105104 @staticmethod
106105 def init (principal , keytab = None , ** kwargs ):
@@ -158,3 +157,16 @@ def parseDatetime(str):
158157 expires = parseDatetime (expires ),
159158 service_principal = service_principal ,
160159 renew_expires = parseDatetime (renew_expires ))
160+
161+ @staticmethod
162+ def _destroy ():
163+ """
164+ destroy internal ticket registry
165+
166+ stop all updaters belonging to a ticket registered in registry, and remove all entiries
167+ """
168+ with KrbTicket .__instances_lock__ :
169+ for (key , ticket ) in KrbTicket .__instances__ .items ():
170+ ticket .updater ().stop ()
171+ KrbCommand .kdestroy (ticket .config )
172+ KrbTicket .__instances__ = {}
Original file line number Diff line number Diff line change 44import os
55import subprocess
66
7+ def teardown_function (function ):
8+ KrbTicket ._destroy ()
9+
710
811def test_init (config ):
912 KrbCommand .kdestroy (config )
Original file line number Diff line number Diff line change 88
99
1010def teardown_function (function ):
11- KrbTicket .__instances__ = {}
11+ KrbTicket ._destroy ()
1212
1313
1414def test_updater (config ):
You can’t perform that action at this time.
0 commit comments