mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Add salt.fileserver.clear_lock()
This exposes the lock clearing logic used in salt.fileserver.Fileserver so that it can be used in the cache runner.
This commit is contained in:
parent
947ed5f739
commit
d7ca297f7b
@ -272,6 +272,34 @@ def is_file_ignored(opts, fname):
|
||||
return False
|
||||
|
||||
|
||||
def clear_lock(clear_func, lock_type, remote=None):
|
||||
'''
|
||||
Function to allow non-fileserver functions to clear update locks
|
||||
|
||||
clear_func
|
||||
A function reference. This function will be run (with the ``remote``
|
||||
param as an argument) to clear the lock, and must return a 2-tuple of
|
||||
lists, one containing messages describing successfully cleared locks,
|
||||
and one containing messages describing errors encountered.
|
||||
|
||||
lock_type
|
||||
What type of lock is being cleared (gitfs, git_pillar, etc.). Used
|
||||
solely for logging purposes.
|
||||
|
||||
remote
|
||||
Optional string which should be used in ``func`` to pattern match so
|
||||
that a subset of remotes can be targeted.
|
||||
|
||||
|
||||
Returns a tuple containing two lists: One with messages
|
||||
'''
|
||||
msg = 'Clearing update lock for {0} remotes'.format(lock_type)
|
||||
if remote:
|
||||
msg += ' matching {0}'.format(remote)
|
||||
log.debug(msg)
|
||||
return clear_func(remote=remote)
|
||||
|
||||
|
||||
class Fileserver(object):
|
||||
'''
|
||||
Create a fileserver wrapper object that wraps the fileserver functions and
|
||||
@ -381,7 +409,7 @@ class Fileserver(object):
|
||||
default is to clear the lock for all enabled backends
|
||||
|
||||
remote
|
||||
If not None, then any remotes which contain the passed string will
|
||||
If specified, then any remotes which contain the passed string will
|
||||
have their lock cleared.
|
||||
'''
|
||||
back = self._gen_back(back)
|
||||
@ -390,11 +418,9 @@ class Fileserver(object):
|
||||
for fsb in back:
|
||||
fstr = '{0}.clear_lock'.format(fsb)
|
||||
if fstr in self.servers:
|
||||
msg = 'Clearing update lock for {0} remotes'.format(fsb)
|
||||
if remote:
|
||||
msg += ' matching {0}'.format(remote)
|
||||
log.debug(msg)
|
||||
good, bad = self.servers[fstr](remote=remote)
|
||||
good, bad = clear_lock(self.servers[fstr],
|
||||
fsb,
|
||||
remote=remote)
|
||||
cleared.extend(good)
|
||||
errors.extend(bad)
|
||||
return cleared, errors
|
||||
|
Loading…
Reference in New Issue
Block a user