Fix yum/dnf lock file polling (#47250)

pull/47363/head
flowerysong 6 years ago committed by ansibot
parent c50a69c2eb
commit c21f92f8f7

@ -44,9 +44,7 @@ yumdnf_argument_spec = dict(
update_cache=dict(type='bool', default=False, aliases=['expire-cache']),
update_only=dict(required=False, default="no", type='bool'),
validate_certs=dict(type='bool', default=True),
# this should not be needed, but exists as a failsafe
lock_poll=dict(type='int', default=-1),
lock_timeout=dict(type='int', default=10),
lock_timeout=dict(type='int', default=0),
),
required_one_of=[['name', 'list', 'update_cache']],
mutually_exclusive=[['name', 'list']],
@ -88,7 +86,6 @@ class YumDnf(with_metaclass(ABCMeta, object)):
self.update_only = self.module.params['update_only']
self.update_cache = self.module.params['update_cache']
self.validate_certs = self.module.params['validate_certs']
self.lock_poll = self.module.params['lock_poll']
self.lock_timeout = self.module.params['lock_timeout']
# It's possible someone passed a comma separated string since it used
@ -103,14 +100,14 @@ class YumDnf(with_metaclass(ABCMeta, object)):
self.lockfile = '/var/run/yum.pid'
def wait_for_lock(self):
'''Poll until the lock is removed if interval is a positive number'''
if (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)) and self.lock_timeout > 0:
for iteration in range(0, self.lock_timeout):
time.sleep(self.lock_poll)
if not os.path.isfile(self.lockfile) or not glob.glob(self.lockfile):
break
if os.path.isfile(self.lockfile) or glob.glob(self.lockfile):
self.module.fail_json(msg='{0} lockfile was not released'.format(self.pkg_mgr_name))
'''Poll until the lock is removed if timeout is a positive number'''
if (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)):
if self.lock_timeout > 0:
for iteration in range(0, self.lock_timeout):
time.sleep(1)
if not os.path.isfile(self.lockfile) and not glob.glob(self.lockfile):
return
self.module.fail_json(msg='{0} lockfile is held by another process'.format(self.pkg_mgr_name))
def listify_comma_sep_strings_in_list(self, some_list):
"""

@ -176,20 +176,11 @@ options:
default: "no"
type: bool
version_added: "2.7"
lock_poll:
description:
- Poll interval to wait for the dnf lockfile to be freed.
- "By default this is set to -1, if you set it to a positive integer it will enable to polling"
required: false
default: -1
type: int
version_added: "2.8"
lock_timeout:
description:
- Amount of time to wait for the dnf lockfile to be freed
- This should be set along with C(lock_poll) to enable the lockfile polling.
- Amount of time to wait for the dnf lockfile to be freed.
required: false
default: 10
default: 0
type: int
version_added: "2.8"
notes:

@ -183,20 +183,11 @@ options:
default: "no"
type: bool
version_added: "2.7"
lock_poll:
description:
- Poll interval to wait for the yum lockfile to be freed.
- "By default this is set to -1, if you set it to a positive integer it will enable to polling"
required: false
default: -1
type: int
version_added: "2.8"
lock_timeout:
description:
- Amount of time to wait for the yum lockfile to be freed
- This should be set along with C(lock_poll) to enable the lockfile polling.
- Amount of time to wait for the yum lockfile to be freed.
required: false
default: 10
default: 0
type: int
version_added: "2.8"
notes:

Loading…
Cancel
Save