From cf1a79203cd5e52a17f1e3228c137c8bd20132fc Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 18 Jul 2013 13:23:33 -0400 Subject: bcfg2-info: added expirecache command to expire metadata cache --- src/sbin/bcfg2-info | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 539ae3115..badf637e8 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -482,6 +482,16 @@ Bcfg2 client itself.""") ('Logging', self.setup['logging'])] print_tabular(output) + def do_expirecache(self, args): + """ expirecache [ [ ...]]- Expire the + metadata cache """ + alist = args.split() + if len(alist): + for client in self._get_client_list(alist): + self.metadata_cache.expire(client) + else: + self.metadata_cache.expire() + def do_probes(self, args): """ probes [-p] - Get probe list for the given host, in XML (the default) or human-readable pretty (with -p) -- cgit v1.2.3-1-g7c22 From 20794ebf60a9cc63d762b047ba24a2ad5c6a115f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 18 Jul 2013 14:19:00 -0400 Subject: bcfg2-info: fixed expirecache --- src/sbin/bcfg2-info | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index badf637e8..451d8e49c 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -489,8 +489,8 @@ Bcfg2 client itself.""") if len(alist): for client in self._get_client_list(alist): self.metadata_cache.expire(client) - else: - self.metadata_cache.expire() + else: + self.metadata_cache.expire() def do_probes(self, args): """ probes [-p] - Get probe list for the given -- cgit v1.2.3-1-g7c22 From 827d0a83b8c9148598c23cb550862c0cf50b5a23 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 18 Jul 2013 14:22:11 -0400 Subject: Packages: added lock to yum cache update --- src/sbin/bcfg2-yum-helper | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper index 414606abb..1f22c0ff9 100755 --- a/src/sbin/bcfg2-yum-helper +++ b/src/sbin/bcfg2-yum-helper @@ -10,6 +10,8 @@ import sys import yum import logging import Bcfg2.Logger +from Bcfg2.Compat import wraps +from lockfile import FileLock, LockTimeout from optparse import OptionParser try: import json @@ -192,6 +194,27 @@ class DepSolver(YumHelper): return list(packages), list(unknown) +def acquire_lock(func): + """ decorator for CacheManager methods that gets and release a + lock while the method runs """ + @wraps(func) + def inner(self, *args, **kwargs): + self.logger.debug("Acquiring lock at %s" % self.lockfile) + while not self.lock.i_am_locking(): + try: + self.lock.acquire(timeout=60) # wait up to 60 seconds + except LockTimeout: + self.lock.break_lock() + self.lock.acquire() + try: + func(self, *args, **kwargs) + finally: + self.lock.release() + self.logger.debug("Released lock at %s" % self.lockfile) + + return inner + + class CacheManager(YumHelper): """ Yum cache manager. Unlike :class:`DepSolver`, this can write to the yum cache, and so is used for operations that muck with the @@ -199,6 +222,14 @@ class CacheManager(YumHelper): either DepSolver or CacheManager, but for consistency I've put it here.) """ + def __init__(self, cfgfile, verbose=1): + YumHelper.__init__(self, cfgfile, verbose=verbose) + self.lockfile = \ + os.path.join(os.path.dirname(self.yumbase.conf.config_file_path), + "lock") + self.lock = FileLock(self.lockfile) + + @acquire_lock def clean_cache(self): """ clean the yum cache """ for mdtype in ["Headers", "Packages", "Sqlite", "Metadata", @@ -211,6 +242,7 @@ class CacheManager(YumHelper): if not msg.startswith("0 "): self.logger.info(msg) + @acquire_lock def populate_cache(self): """ populate the yum cache """ for repo in self.yumbase.repos.findRepos('*'): -- cgit v1.2.3-1-g7c22 From 6cc24e1f7fdddda46e8665c6bb2fbca4b6f6a57f Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 18 Jul 2013 14:50:52 -0400 Subject: bcfg2-yum-helper: added missing docstring --- src/sbin/bcfg2-yum-helper | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper index 1f22c0ff9..161aa3e50 100755 --- a/src/sbin/bcfg2-yum-helper +++ b/src/sbin/bcfg2-yum-helper @@ -199,6 +199,8 @@ def acquire_lock(func): lock while the method runs """ @wraps(func) def inner(self, *args, **kwargs): + """ Get and release a lock while running the function this + wraps. """ self.logger.debug("Acquiring lock at %s" % self.lockfile) while not self.lock.i_am_locking(): try: -- cgit v1.2.3-1-g7c22