diff options
author | Adam Miller <admiller@redhat.com> | 2018-09-19 15:14:25 -0500 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2018-09-19 16:14:25 -0400 |
commit | 5fdf0290d00a80f3d8a4f6d1375684ccf0046e7d (patch) | |
tree | 35cbf6d248f8bc2dc75f8e616f85d4384c9149fe /lib/ansible/module_utils/yumdnf.py | |
parent | e3ec9e5345660c29541c29326c9634d6a8729b1a (diff) | |
download | ansible-5fdf0290d00a80f3d8a4f6d1375684ccf0046e7d.tar.gz |
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>
Diffstat (limited to 'lib/ansible/module_utils/yumdnf.py')
-rw-r--r-- | lib/ansible/module_utils/yumdnf.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/ansible/module_utils/yumdnf.py b/lib/ansible/module_utils/yumdnf.py index aa3e0138a6..eed3ebf21b 100644 --- a/lib/ansible/module_utils/yumdnf.py +++ b/lib/ansible/module_utils/yumdnf.py @@ -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 |