Fix yum/dnf lock file polling (#47250)
This commit is contained in:
parent
c50a69c2eb
commit
c21f92f8f7
3 changed files with 13 additions and 34 deletions
|
@ -44,9 +44,7 @@ yumdnf_argument_spec = dict(
|
||||||
update_cache=dict(type='bool', default=False, aliases=['expire-cache']),
|
update_cache=dict(type='bool', default=False, aliases=['expire-cache']),
|
||||||
update_only=dict(required=False, default="no", type='bool'),
|
update_only=dict(required=False, default="no", type='bool'),
|
||||||
validate_certs=dict(type='bool', default=True),
|
validate_certs=dict(type='bool', default=True),
|
||||||
# this should not be needed, but exists as a failsafe
|
lock_timeout=dict(type='int', default=0),
|
||||||
lock_poll=dict(type='int', default=-1),
|
|
||||||
lock_timeout=dict(type='int', default=10),
|
|
||||||
),
|
),
|
||||||
required_one_of=[['name', 'list', 'update_cache']],
|
required_one_of=[['name', 'list', 'update_cache']],
|
||||||
mutually_exclusive=[['name', 'list']],
|
mutually_exclusive=[['name', 'list']],
|
||||||
|
@ -88,7 +86,6 @@ class YumDnf(with_metaclass(ABCMeta, object)):
|
||||||
self.update_only = self.module.params['update_only']
|
self.update_only = self.module.params['update_only']
|
||||||
self.update_cache = self.module.params['update_cache']
|
self.update_cache = self.module.params['update_cache']
|
||||||
self.validate_certs = self.module.params['validate_certs']
|
self.validate_certs = self.module.params['validate_certs']
|
||||||
self.lock_poll = self.module.params['lock_poll']
|
|
||||||
self.lock_timeout = self.module.params['lock_timeout']
|
self.lock_timeout = self.module.params['lock_timeout']
|
||||||
|
|
||||||
# It's possible someone passed a comma separated string since it used
|
# 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'
|
self.lockfile = '/var/run/yum.pid'
|
||||||
|
|
||||||
def wait_for_lock(self):
|
def wait_for_lock(self):
|
||||||
'''Poll until the lock is removed if interval is a positive number'''
|
'''Poll until the lock is removed if timeout is a positive number'''
|
||||||
if (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)) and self.lock_timeout > 0:
|
if (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)):
|
||||||
for iteration in range(0, self.lock_timeout):
|
if self.lock_timeout > 0:
|
||||||
time.sleep(self.lock_poll)
|
for iteration in range(0, self.lock_timeout):
|
||||||
if not os.path.isfile(self.lockfile) or not glob.glob(self.lockfile):
|
time.sleep(1)
|
||||||
break
|
if not os.path.isfile(self.lockfile) and not glob.glob(self.lockfile):
|
||||||
if os.path.isfile(self.lockfile) or glob.glob(self.lockfile):
|
return
|
||||||
self.module.fail_json(msg='{0} lockfile was not released'.format(self.pkg_mgr_name))
|
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):
|
def listify_comma_sep_strings_in_list(self, some_list):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -176,20 +176,11 @@ options:
|
||||||
default: "no"
|
default: "no"
|
||||||
type: bool
|
type: bool
|
||||||
version_added: "2.7"
|
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:
|
lock_timeout:
|
||||||
description:
|
description:
|
||||||
- Amount of time to wait for the dnf lockfile to be freed
|
- 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.
|
|
||||||
required: false
|
required: false
|
||||||
default: 10
|
default: 0
|
||||||
type: int
|
type: int
|
||||||
version_added: "2.8"
|
version_added: "2.8"
|
||||||
notes:
|
notes:
|
||||||
|
|
|
@ -183,20 +183,11 @@ options:
|
||||||
default: "no"
|
default: "no"
|
||||||
type: bool
|
type: bool
|
||||||
version_added: "2.7"
|
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:
|
lock_timeout:
|
||||||
description:
|
description:
|
||||||
- Amount of time to wait for the yum lockfile to be freed
|
- 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.
|
|
||||||
required: false
|
required: false
|
||||||
default: 10
|
default: 0
|
||||||
type: int
|
type: int
|
||||||
version_added: "2.8"
|
version_added: "2.8"
|
||||||
notes:
|
notes:
|
||||||
|
|
Loading…
Reference in a new issue