handle yum and dnf lockfiles - fixes #44120 (#45359)

* handle yum and dnf lockfiles - fixes #44120

Signed-off-by: Adam Miller <admiller@redhat.com>

* fix logic problem to properly check for dnf lockfile glob

Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
Adam Miller
2018-09-19 15:14:25 -05:00
committed by ansibot
parent e3ec9e5345
commit 5fdf0290d0
3 changed files with 59 additions and 0 deletions

View File

@@ -10,6 +10,8 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import os
import time
import glob
import tempfile
from abc import ABCMeta, abstractmethod
@@ -43,6 +45,8 @@ yumdnf_argument_spec = dict(
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),
),
required_one_of=[['name', 'list']],
mutually_exclusive=[['name', 'list']],
@@ -84,6 +88,8 @@ 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
# to be a string type, so we should handle that
@@ -92,6 +98,20 @@ class YumDnf(with_metaclass(ABCMeta, object)):
self.enablerepo = self.listify_comma_sep_strings_in_list(self.enablerepo)
self.exclude = self.listify_comma_sep_strings_in_list(self.exclude)
# This should really be redefined by both the yum and dnf module but a
# default isn't a bad idea
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))
def listify_comma_sep_strings_in_list(self, some_list):
"""
method to accept a list of strings as the parameter, find any strings