Repository: ansible-collections/community.general

Issue:
yum_versionlock: tests are disabled in CI
**Summary**

The yum_versionlock tests are **extremely** slow: the locking and unlocking operation both take up to 10 minutes! That's why they have been disabled in #1907.

See for example:
- https://dev.azure.com/ansible/b24bf3ca-6168-45d7-99e2-bf8029e67c87/_apis/build/builds/7679/logs/1194
- https://dev.azure.com/ansible/b24bf3ca-6168-45d7-99e2-bf8029e67c87/_apis/build/builds/7679/logs/1187

Timestamps of interest:
- RHEL 8.2 on Ansible 2.10:
  ```
  2021-02-26T09:31:35.8642168Z 06:52 TASK [yum_versionlock : Lock all packages] *************************************
  2021-02-26T09:41:41.5695147Z 16:58 changed: [testhost] => {"changed": true, "meta": {"packages": ["epel-release", "rh-amazon-rhui-client", ..., "microcode_ctl"], "state": "present"}}
  ```
  for locking and
  ```
  2021-02-26T09:41:45.1511543Z 17:02 TASK [yum_versionlock : Unlock all packages] ***********************************
  2021-02-26T09:51:19.0732524Z 26:36 changed: [testhost] => {"changed": true, "meta": {"packages": ["epel-release", ..., "microcode_ctl"], "state": "absent"}}
  ```
  for unlocking: this is a total of 20 minutes!
- RHEL 8.2 on Ansible 2.9:
  ```
  2021-02-26T09:31:58.4566170Z 06:50 TASK [yum_versionlock : Lock all packages] *************************************
  2021-02-26T09:41:06.3081782Z 15:58 changed: [testhost] => {"changed": true, "meta": {"packages": ["epel-release", ..., "microcode_ctl"], "state": "present"}}
  ```
  for locking and
  ```
  2021-02-26T09:41:08.7250532Z 16:00 TASK [yum_versionlock : Unlock all packages] ***********************************
  2021-02-26T09:49:53.0925833Z 24:45 changed: [testhost] => {"changed": true, "meta": {"packages": ["epel-release", ..., "microcode_ctl"], "state": "absent"}}
  ```
  for unlocking: this is a total of 18 minutes!

(For some reason, the tests are NOT run on RHEL 8.3 with ansible-core's devel branch.)

**Issue Type**

Bug Report

**Component Name**

yum_versionlock

**Ansible Version**

2.9, 2.10

**Configuration**

_No response_

**OS / Environment**

_No response_

**Steps To Reproduce**

_No response_

**Expected Results**

_No response_

**Actual Results**

_No response_




Discussion:
Files identified in the description:
* [`plugins/modules/packaging/os/yum_versionlock.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/packaging/os/yum_versionlock.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @aminvakil @florianpaulhoberg
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/packaging/os/yum_versionlock.py b/plugins/modules/packaging/os/yum_versionlock.py
--- a/plugins/modules/packaging/os/yum_versionlock.py
+++ b/plugins/modules/packaging/os/yum_versionlock.py
@@ -13,7 +13,7 @@
 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 @@ def get_versionlock_packages(self):
             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,


Test patch:
diff --git a/tests/integration/targets/yum_versionlock/aliases b/tests/integration/targets/yum_versionlock/aliases
--- 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