Added support for turning off locking with environment variable

In some environments depending on how the configuration files are
mounted the locking can be problematic.  If this happens at least
there will be a way to disable the locking though access to the
property and configuration files will become multi-process unsafe
as a result.

Change-Id: I6007514abd52374d97025f85122b90794894effb
Jira-Issue: OPENSTACK-1214
This commit is contained in:
Borne Mace 2016-11-02 13:59:48 -07:00
parent bc42e6b13e
commit 3e5cc35f4b
2 changed files with 31 additions and 22 deletions

View File

@ -139,7 +139,6 @@ class AsyncApi(object):
ansible_job = actions.precheck(hostnames, verbose_level)
return Job(ansible_job)
def async_host_stop(self, hostnames, verbose_level=1):
# type: (List[str], int) -> Job
"""Stop Hosts.

View File

@ -128,6 +128,14 @@ def get_setup_user():
return os.environ.get("KOLLA_CLI_SETUP_USER", "root")
def get_lock_enabled():
evar = os.environ.get('KOLLA_CLI_LOCK', 'true')
if evar.lower() == 'false':
return False
else:
return True
def get_ansible_command(playbook=False):
"""get a python2 ansible command
@ -300,13 +308,14 @@ def sync_read_file(path, mode='r'):
"""
lock = None
try:
lock = Lock(path, 'sync_read')
locked = lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to read file {path} '
'as it was locked.')
.format(path=path))
if get_lock_enabled():
lock = Lock(path, 'sync_read')
locked = lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to read file {path} '
'as it was locked.')
.format(path=path))
with open(path, mode) as data_file:
data = data_file.read()
finally:
@ -320,21 +329,22 @@ def sync_write_file(path, data, mode='w'):
ansible_lock = None
lock = None
try:
ansible_lock = Lock(get_ansible_lock_path(), 'sync_write')
locked = ansible_lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to get ansible lock while writing to {path} '
'as it was locked.')
.format(path=path))
if get_lock_enabled():
ansible_lock = Lock(get_ansible_lock_path(), 'sync_write')
locked = ansible_lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to get ansible lock while writing to {path} '
'as it was locked.')
.format(path=path))
lock = Lock(path, 'sync_write')
locked = lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to write file {path} '
'as it was locked.')
.format(path=path))
lock = Lock(path, 'sync_write')
locked = lock.wait_acquire()
if not locked:
raise Exception(
u._('unable to write file {path} '
'as it was locked.')
.format(path=path))
with open(path, mode) as data_file:
data_file.write(data)
finally: