From: Frank Brehm Date: Tue, 30 Apr 2019 09:35:07 +0000 (+0200) Subject: Implementing locking of r10k updates X-Git-Tag: 1.6.4^2^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=1031b65dd50e7d56b69d07d2d61d635a1fafc572;p=pixelpark%2Fpuppetmaster-webhooks.git Implementing locking of r10k updates --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 9bfc52c..97bf660 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.6.2' +__version__ = '1.6.3' # vim: ts=4 et list diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index d0de531..c2b2721 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -100,7 +100,6 @@ class WebhookDeployApp(BaseHookApp): lockretry_delay_start=0.5, lockretry_delay_increase=0.5, lockretry_max_delay=30, max_lockfile_age=900, locking_use_pid=True, lockdir='/tmp') - self.locker.initialized = True self.initialized = True diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 19c666f..8fce9f7 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -22,6 +22,8 @@ import pathlib import requests # Own modules +from fb_tools.handler.lock import LockHandler + from . import __version__ from .base_app import BaseHookApp @@ -46,6 +48,7 @@ class R10kHookApp(BaseHookApp): self.r10k_bin = None self.puppet_bin = None + self.locker = None description = _("Receives push events as JSON-Data and deploys it with r10k.") self.locale = 'de_DE.utf8' @@ -73,6 +76,14 @@ class R10kHookApp(BaseHookApp): self.search_r10k_bin() self.check_cert_files() + self.locker = LockHandler( + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, + simulate=self.simulate, sudo=False, quiet=self.quiet, + lockretry_delay_start=1, lockretry_delay_increase=1, + lockretry_max_delay=120, max_lockfile_age=1800, locking_use_pid=True, + lockdir='/tmp') + self.locker.initialized = True + self.initialized = True # ------------------------------------------------------------------------- @@ -201,16 +212,28 @@ class R10kHookApp(BaseHookApp): def run_hook(self): """Main routine.""" - if not self.exec_r10k(): - LOG.warn(_("Executing {!r} was not successful.").format(str(self.r10k_bin))) - return + lockfile = 'r10k.' + self.ref + '.lock' + LOG.info(_("Trying to create lockfile {fn!r} in directory {d!r} ...").format( + fn=lockfile, d=str(self.locker.lockdir))) - if not self.generate_puppet_types(): - what = '{c} generate types --environment {e}'.format(c=self.puppet_bin, e=self.ref) - LOG.warn(_("{!r} was not successful.").format(what)) - return + lock = self.locker.create_lockfile(lockfile) + + try: + lock.autoremove = True + + if not self.exec_r10k(): + LOG.warn(_("Executing {!r} was not successful.").format(str(self.r10k_bin))) + return + + if not self.generate_puppet_types(): + what = '{c} generate types --environment {e}'.format(c=self.puppet_bin, e=self.ref) + LOG.warn(_("{!r} was not successful.").format(what)) + return + + return self.del_env_cache() - return self.del_env_cache() + finally: + lock = None # ------------------------------------------------------------------------- def del_env_cache(self):