-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ksauzz/feature/none-per-process-ccache
Add additional ticket updaters
- Loading branch information
Showing
12 changed files
with
302 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from krbticket.ticket import * | ||
from krbticket.updater import * | ||
from krbticket.config import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class KrbCommand(): | ||
@staticmethod | ||
def kinit(config): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import logging | ||
import threading | ||
import time | ||
|
||
import fasteners | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class KrbTicketUpdater(threading.Thread): | ||
DEFAULT_INTERVAL = 60 * 10 | ||
|
||
def __init__(self, ticket, interval=DEFAULT_INTERVAL): | ||
super(KrbTicketUpdater, self).__init__() | ||
|
||
self.ticket = ticket | ||
self.interval = interval | ||
self.stop_event = threading.Event() | ||
self.daemon = True | ||
|
||
def run(self): | ||
logger.info("{} start...".format(self.__class__.__name__)) | ||
while True: | ||
if self.stop_event.is_set(): | ||
return | ||
|
||
logger.debug("Trying to update ticket...") | ||
self.update() | ||
time.sleep(self.interval) | ||
|
||
def update(self): | ||
raise NotImplementedError | ||
|
||
@staticmethod | ||
def use_per_process_ccache(): | ||
raise NotImplementedError | ||
|
||
def stop(self): | ||
logger.debug("Stopping ticket updater...") | ||
self.stop_event.set() | ||
|
||
|
||
class SimpleKrbTicketUpdater(KrbTicketUpdater): | ||
""" | ||
KrbTicketUpdater w/o exclusion control | ||
Using this with multiprocessing, child processes uses dedicated ccache file | ||
""" | ||
def update(self): | ||
self.ticket.maybe_update() | ||
|
||
@staticmethod | ||
def use_per_process_ccache(): | ||
return True | ||
|
||
|
||
class MultiProcessKrbTicketUpdater(KrbTicketUpdater): | ||
""" | ||
Multiprocess KrbTicket Updater | ||
KrbTicketUpdater w/ exclusive lock for a ccache | ||
""" | ||
def update(self): | ||
with fasteners.InterProcessLock(self.ticket.config.ccache_lockfile): | ||
self.ticket.maybe_update() | ||
|
||
@staticmethod | ||
def use_per_process_ccache(): | ||
return False | ||
|
||
|
||
class SingleProcessKrbTicketUpdater(KrbTicketUpdater): | ||
""" | ||
Singleprocess KrbTicket Updater | ||
Single Process KrbTicketUpdater on the system. | ||
Multiple updaters can start, but they immediately stops if a updater is already running on the system. | ||
""" | ||
def run(self): | ||
lock = fasteners.InterProcessLock(self.ticket.config.ccache_lockfile) | ||
got_lock = lock.acquire(blocking=False) | ||
if not got_lock: | ||
logger.debug("Another updater is detected. Stopping ticket updater...") | ||
return | ||
|
||
logger.debug("Got lock: {}...".format(self.ticket.config.ccache_lockfile)) | ||
try: | ||
super().run() | ||
finally: | ||
if got_lock: | ||
lock.release() | ||
logger.debug("Released lock: {}...".format(self.ticket.config.ccache_lockfile)) | ||
|
||
def update(self): | ||
self.ticket.maybe_update() | ||
|
||
@staticmethod | ||
def use_per_process_ccache(): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
retrying==1.3.3 | ||
fasteners==0.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
DEFAULT_PRINCIPAL = '[email protected]' | ||
DEFAULT_KEYTAB = './tests/conf/krb5.keytab' | ||
DEFAULT_TICKET_RENEWAL_THRESHOLD_SEC = 1 | ||
DEFAULT_TICKET_LIFETIME = '2s' | ||
DEFAULT_TICKET_RENEWABLE_LIFETIME = '4s' | ||
DEFAULT_TICKET_LIFETIME_SEC = 4 | ||
DEFAULT_TICKET_LIFETIME = '{}s'.format(DEFAULT_TICKET_LIFETIME_SEC) | ||
DEFAULT_TICKET_RENEWABLE_LIFETIME_SEC = 8 | ||
DEFAULT_TICKET_RENEWABLE_LIFETIME = '{}s'.format(DEFAULT_TICKET_RENEWABLE_LIFETIME_SEC) | ||
DEFAULT_CCACHE_NAME = '/tmp/krb5cc_{}'.format(os.getuid()) | ||
|
||
|
||
|
@@ -33,17 +35,20 @@ def assert_config(c1, c2): | |
assert c1.ticket_renewable_lifetime == c2.ticket_renewable_lifetime | ||
assert c1.ccache_name == c2.ccache_name | ||
|
||
def default_config(): | ||
return KrbConfig( | ||
DEFAULT_PRINCIPAL, | ||
DEFAULT_KEYTAB, | ||
renewal_threshold=timedelta(seconds=DEFAULT_TICKET_RENEWAL_THRESHOLD_SEC), | ||
ticket_lifetime=DEFAULT_TICKET_LIFETIME, | ||
ticket_renewable_lifetime=DEFAULT_TICKET_RENEWABLE_LIFETIME, | ||
retry_options={ | ||
|
||
def default_config(**kwargs): | ||
default_options = { | ||
'principal': DEFAULT_PRINCIPAL, | ||
'keytab': DEFAULT_KEYTAB, | ||
'renewal_threshold': timedelta(seconds=DEFAULT_TICKET_RENEWAL_THRESHOLD_SEC), | ||
'ticket_lifetime': DEFAULT_TICKET_LIFETIME, | ||
'ticket_renewable_lifetime': DEFAULT_TICKET_RENEWABLE_LIFETIME, | ||
'retry_options': { | ||
'wait_exponential_multiplier': 100, | ||
'wait_exponential_max': 1000, | ||
'stop_max_attempt_number': 3}) | ||
'stop_max_attempt_number': 3} | ||
} | ||
return KrbConfig(**{**default_options, **kwargs}) | ||
|
||
|
||
@pytest.fixture | ||
|
Oops, something went wrong.