1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Move the lockfile back to tqm to make sure it stays unique

This commit is contained in:
James Cammarata 2015-09-03 00:45:42 -04:00
parent ba658ff3a9
commit b93f27e260
3 changed files with 14 additions and 12 deletions

View file

@ -23,6 +23,7 @@ import multiprocessing
import os import os
import socket import socket
import sys import sys
import tempfile
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
@ -86,6 +87,8 @@ class TaskQueueManager:
except ValueError: except ValueError:
fileno = None fileno = None
self._connection_lockfile = tempfile.TemporaryFile()
self._workers = [] self._workers = []
for i in range(self._options.forks): for i in range(self._options.forks):
main_q = multiprocessing.Queue() main_q = multiprocessing.Queue()
@ -176,7 +179,7 @@ class TaskQueueManager:
new_play = play.copy() new_play = play.copy()
new_play.post_validate(templar) new_play.post_validate(templar)
play_context = PlayContext(new_play, self._options, self.passwords) play_context = PlayContext(new_play, self._options, self.passwords, self._connection_lockfile.fileno())
for callback_plugin in self._callback_plugins: for callback_plugin in self._callback_plugins:
if hasattr(callback_plugin, 'set_play_context'): if hasattr(callback_plugin, 'set_play_context'):
callback_plugin.set_play_context(play_context) callback_plugin.set_play_context(play_context)

View file

@ -24,7 +24,6 @@ __metaclass__ = type
import pipes import pipes
import random import random
import re import re
import tempfile
from ansible import constants as C from ansible import constants as C
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
@ -190,7 +189,7 @@ class PlayContext(Base):
_step = FieldAttribute(isa='bool', default=False) _step = FieldAttribute(isa='bool', default=False)
_diff = FieldAttribute(isa='bool', default=False) _diff = FieldAttribute(isa='bool', default=False)
def __init__(self, play=None, options=None, passwords=None): def __init__(self, play=None, options=None, passwords=None, connection_lockfd=None):
super(PlayContext, self).__init__() super(PlayContext, self).__init__()
@ -202,7 +201,7 @@ class PlayContext(Base):
# A temporary file (opened pre-fork) used by connection # A temporary file (opened pre-fork) used by connection
# plugins for inter-process locking. # plugins for inter-process locking.
self.connection_lockf = tempfile.TemporaryFile() self.connection_lockfd = connection_lockfd
# set options before play to allow play to override them # set options before play to allow play to override them
if options: if options:
@ -329,7 +328,7 @@ class PlayContext(Base):
def copy(self, exclude_block=False): def copy(self, exclude_block=False):
new_me = super(PlayContext, self).copy() new_me = super(PlayContext, self).copy()
new_me.connection_lockf = self.connection_lockf new_me.connection_lockfd = self.connection_lockfd
return new_me return new_me
def make_become_cmd(self, cmd, executable=None): def make_become_cmd(self, cmd, executable=None):

View file

@ -156,12 +156,12 @@ class ConnectionBase(with_metaclass(ABCMeta, object)):
raise AnsibleError('Incorrect %s password' % self._play_context.become_method) raise AnsibleError('Incorrect %s password' % self._play_context.become_method)
def lock_connection(self): def lock_connection(self):
f = self._play_context.connection_lockf f = self._play_context.connection_lockfd
self._display.vvvv('CONNECTION: pid %d waiting for lock on %d' % (os.getpid(), f.fileno())) self._display.vvvv('CONNECTION: pid %d waiting for lock on %d' % (os.getpid(), f))
fcntl.lockf(f.fileno(), fcntl.LOCK_EX) fcntl.lockf(f, fcntl.LOCK_EX)
self._display.vvvv('CONNECTION: pid %d acquired lock on %d' % (os.getpid(), f.fileno())) self._display.vvvv('CONNECTION: pid %d acquired lock on %d' % (os.getpid(), f))
def unlock_connection(self): def unlock_connection(self):
f = self._play_context.connection_lockf f = self._play_context.connection_lockfd
fcntl.lockf(f.fileno(), fcntl.LOCK_UN) fcntl.lockf(f, fcntl.LOCK_UN)
self._display.vvvv('CONNECTION: pid %d released lock on %d' % (os.getpid(), f.fileno())) self._display.vvvv('CONNECTION: pid %d released lock on %d' % (os.getpid(), f))