summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2013-07-27 17:19:47 -0500
committerSol Jerome <sol.jerome@gmail.com>2013-07-27 17:19:47 -0500
commitaa230853296cd3b69f0296d646daf37b4b2cd764 (patch)
tree8ad1a2e8ee5f05ef775c2536984440a0cc74ec78 /src/sbin
parent08f5ad7e1b470b79ce81130b2f299426b132db80 (diff)
parent3435963a7c715bd3e6e912c6224fc8b893b1abe4 (diff)
downloadbcfg2-aa230853296cd3b69f0296d646daf37b4b2cd764.tar.gz
bcfg2-aa230853296cd3b69f0296d646daf37b4b2cd764.tar.bz2
bcfg2-aa230853296cd3b69f0296d646daf37b4b2cd764.zip
Merge branch 'maint'
Signed-off-by: Sol Jerome <sol.jerome@gmail.com> Conflicts: doc/appendix/guides/ubuntu.txt src/lib/Bcfg2/Options.py src/lib/Bcfg2/Server/Plugins/Packages/Yum.py src/lib/Bcfg2/settings.py
Diffstat (limited to 'src/sbin')
-rwxr-xr-xsrc/sbin/bcfg2-info10
-rwxr-xr-xsrc/sbin/bcfg2-yum-helper34
2 files changed, 44 insertions, 0 deletions
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index 5eef72350..787ed1d49 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -465,6 +465,16 @@ Bcfg2 client itself.""")
('Logging', self.setup['logging'])]
print_tabular(output)
+ def do_expirecache(self, args):
+ """ expirecache [<hostname> [<hostname> ...]]- 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] <hostname>
Get probe list for the given host, in XML (the default) \
diff --git a/src/sbin/bcfg2-yum-helper b/src/sbin/bcfg2-yum-helper
index 414606abb..161aa3e50 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,29 @@ 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):
+ """ 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:
+ 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 +224,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 +244,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('*'):