From 196e8fe4e3a79dc2cfdf3e21ffa422caec8aea6d Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 26 Feb 2021 23:37:30 +0100 Subject: [PATCH] yum_versionlock: do lock/unlock concurrently (#1912) (#1920) * Change all packages at once in yum_versionlock module * Re-enable tests * Convert package list to packages string * Fix module * Change variable name to make it appropriate * Fix module check_mode * Revert "Fix module" and apply felixfontein suggestion This reverts commit 5936da31987219a0cfc9a7b1bdaee0c093d2ccf8. * Rename package to packages * Only change packages which are needed * Ignore if list is empty * Add changelog (cherry picked from commit 811b609b05012717290356f08321072cb1d12b56) Co-authored-by: Amin Vakil --- ...yum_versionlock-lock_unlock_concurrently.yml | 3 +++ plugins/modules/packaging/os/yum_versionlock.py | 17 +++++++++++------ .../integration/targets/yum_versionlock/aliases | 1 - 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml diff --git a/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml b/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml new file mode 100644 index 0000000000..36f40da0fe --- /dev/null +++ b/changelogs/fragments/1912-yum_versionlock-lock_unlock_concurrently.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - yum_versionlock - Do the lock/unlock concurrently to speed up (https://github.com/ansible-collections/community.general/pull/1912). diff --git a/plugins/modules/packaging/os/yum_versionlock.py b/plugins/modules/packaging/os/yum_versionlock.py index 0830b3a4ab..13319f6711 100644 --- a/plugins/modules/packaging/os/yum_versionlock.py +++ b/plugins/modules/packaging/os/yum_versionlock.py @@ -13,7 +13,7 @@ module: yum_versionlock version_added: 2.0.0 short_description: Locks / unlocks a installed package(s) from being updated by yum package manager description: - - This module adds installed packages to yum versionlock to prevent the package from being updated. + - This module adds installed packages to yum versionlock to prevent the package(s) from being updated. options: name: description: @@ -93,9 +93,9 @@ class YumVersionLock: self.module.fail_json(msg="Error: Please install rpm package yum-plugin-versionlock : " + to_native(err) + to_native(out)) self.module.fail_json(msg="Error: " + to_native(err) + to_native(out)) - def ensure_state(self, package, command): - """ Ensure package state """ - rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command, package]) + def ensure_state(self, packages, command): + """ Ensure packages state """ + rc, out, err = self.module.run_command([self.yum_bin, "-q", "versionlock", command] + packages) if rc == 0: return True self.module.fail_json(msg="Error: " + to_native(err) + to_native(out)) @@ -121,6 +121,7 @@ def main(): versionlock_packages = yum_v.get_versionlock_packages() # Ensure versionlock state of packages + packages_list = [] if state in ('present'): command = 'add' for single_pkg in packages: @@ -128,7 +129,9 @@ def main(): if module.check_mode: changed = True continue - changed = yum_v.ensure_state(single_pkg, command) + packages_list.append(single_pkg) + if packages_list: + changed = yum_v.ensure_state(packages_list, command) elif state in ('absent'): command = 'delete' for single_pkg in packages: @@ -136,7 +139,9 @@ def main(): if module.check_mode: changed = True continue - changed = yum_v.ensure_state(single_pkg, command) + packages_list.append(single_pkg) + if packages_list: + changed = yum_v.ensure_state(packages_list, command) module.exit_json( changed=changed, diff --git a/tests/integration/targets/yum_versionlock/aliases b/tests/integration/targets/yum_versionlock/aliases index 895088b2c6..abe0a21e22 100644 --- a/tests/integration/targets/yum_versionlock/aliases +++ b/tests/integration/targets/yum_versionlock/aliases @@ -1,4 +1,3 @@ -disabled # The tests are way too slow - the locking/unlocking steps need 10 minutes each! shippable/posix/group1 skip/aix skip/freebsd