Skip to content

Commit

Permalink
Move the lockfile back to tqm to make sure it stays unique
Browse files Browse the repository at this point in the history
  • Loading branch information
jimi-c committed Sep 3, 2015
1 parent ba658ff commit b93f27e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 4 additions & 1 deletion lib/ansible/executor/task_queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import socket
import sys
import tempfile

from ansible import constants as C
from ansible.errors import AnsibleError
Expand Down Expand Up @@ -86,6 +87,8 @@ def __init__(self, inventory, variable_manager, loader, display, options, passwo
except ValueError:
fileno = None

self._connection_lockfile = tempfile.TemporaryFile()

self._workers = []
for i in range(self._options.forks):
main_q = multiprocessing.Queue()
Expand Down Expand Up @@ -176,7 +179,7 @@ def run(self, play):
new_play = play.copy()
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:
if hasattr(callback_plugin, 'set_play_context'):
callback_plugin.set_play_context(play_context)
Expand Down
7 changes: 3 additions & 4 deletions lib/ansible/playbook/play_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pipes
import random
import re
import tempfile

from ansible import constants as C
from ansible.errors import AnsibleError
Expand Down Expand Up @@ -190,7 +189,7 @@ class PlayContext(Base):
_step = 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__()

Expand All @@ -202,7 +201,7 @@ def __init__(self, play=None, options=None, passwords=None):

# A temporary file (opened pre-fork) used by connection
# 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
if options:
Expand Down Expand Up @@ -329,7 +328,7 @@ def set_task_and_variable_override(self, task, variables):

def copy(self, exclude_block=False):
new_me = super(PlayContext, self).copy()
new_me.connection_lockf = self.connection_lockf
new_me.connection_lockfd = self.connection_lockfd
return new_me

def make_become_cmd(self, cmd, executable=None):
Expand Down
14 changes: 7 additions & 7 deletions lib/ansible/plugins/connections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def check_incorrect_password(self, output):
raise AnsibleError('Incorrect %s password' % self._play_context.become_method)

def lock_connection(self):
f = self._play_context.connection_lockf
self._display.vvvv('CONNECTION: pid %d waiting for lock on %d' % (os.getpid(), f.fileno()))
fcntl.lockf(f.fileno(), fcntl.LOCK_EX)
self._display.vvvv('CONNECTION: pid %d acquired lock on %d' % (os.getpid(), f.fileno()))
f = self._play_context.connection_lockfd
self._display.vvvv('CONNECTION: pid %d waiting for lock on %d' % (os.getpid(), f))
fcntl.lockf(f, fcntl.LOCK_EX)
self._display.vvvv('CONNECTION: pid %d acquired lock on %d' % (os.getpid(), f))

def unlock_connection(self):
f = self._play_context.connection_lockf
fcntl.lockf(f.fileno(), fcntl.LOCK_UN)
self._display.vvvv('CONNECTION: pid %d released lock on %d' % (os.getpid(), f.fileno()))
f = self._play_context.connection_lockfd
fcntl.lockf(f, fcntl.LOCK_UN)
self._display.vvvv('CONNECTION: pid %d released lock on %d' % (os.getpid(), f))

0 comments on commit b93f27e

Please sign in to comment.