Remove the yum module, redirect it to dnf (#81895)

Fixes #81728
pull/81765/head
Martin Krizek 10 months ago committed by GitHub
parent c7334ea92c
commit f024cf35d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -87,7 +87,7 @@ body:
[collections org]: /ansible-collections
placeholder: dnf, apt, yum, pip, user etc.
placeholder: dnf, apt, pip, user etc.
validations:
required: true

@ -139,7 +139,7 @@ body:
[collections org]: /ansible-collections
placeholder: dnf, apt, yum, pip, user etc.
placeholder: dnf, apt, pip, user etc.
validations:
required: true

@ -0,0 +1,2 @@
removed_features:
- "With the removal of Python 2 support, the yum module and yum action plugin are removed and redirected to ``dnf``."

@ -15,7 +15,7 @@ This directory contains the following scripts:
Incidental testing and code coverage occurs when a test covers one or more portions of code as an unintentional side-effect of testing another portion of code.
For example, the ``yum`` integration test intentionally tests the ``yum`` Ansible module.
For example, the ``dnf`` integration test intentionally tests the ``dnf`` Ansible module.
However, in doing so it also uses, and unintentionally tests the ``file`` module as well.
As part of the process of migrating modules and plugins into collections, integration tests were identified that provided exclusive incidental code coverage.

@ -9088,6 +9088,8 @@ plugin_routing:
tombstone:
removal_date: "2023-05-16"
warning_text: Use include_tasks or import_tasks instead.
yum:
redirect: ansible.builtin.dnf
become:
doas:
redirect: community.general.doas

@ -54,7 +54,7 @@ class TaskResult:
if 'results' in self._result:
results = self._result['results']
# Loop tasks are only considered skipped if all items were skipped.
# some squashed results (eg, yum) are not dicts and can't be skipped individually
# some squashed results (eg, dnf) are not dicts and can't be skipped individually
if results and all(isinstance(res, dict) and res.get('skipped', False) for res in results):
return True

@ -19,7 +19,7 @@ def respawn_module(interpreter_path):
Respawn the currently-running Ansible Python module under the specified Python interpreter.
Ansible modules that require libraries that are typically available only under well-known interpreters
(eg, ``yum``, ``apt``, ``dnf``) can use bespoke logic to determine the libraries they need are not
(eg, ``apt``, ``dnf``) can use bespoke logic to determine the libraries they need are not
available, then call `respawn_module` to re-execute the current module under a different interpreter
and exit the current process when the new subprocess has completed. The respawned process inherits only
stdout/stderr from the current process.

@ -15,11 +15,11 @@ from ansible.module_utils.facts.collector import BaseFactCollector
# package manager, put the preferred one last. If there is an
# ansible module, use that as the value for the 'name' key.
PKG_MGRS = [{'path': '/usr/bin/rpm-ostree', 'name': 'atomic_container'},
{'path': '/usr/bin/yum', 'name': 'yum'},
# NOTE the `path` key for dnf/dnf5 is effectively discarded when matched for Red Hat OS family,
# special logic to infer the default `pkg_mgr` is used in `PkgMgrFactCollector._check_rh_versions()`
# leaving them here so a list of package modules can be constructed by iterating over `name` keys
{'path': '/usr/bin/yum', 'name': 'dnf'},
{'path': '/usr/bin/dnf-3', 'name': 'dnf'},
{'path': '/usr/bin/dnf5', 'name': 'dnf5'},
@ -45,7 +45,6 @@ PKG_MGRS = [{'path': '/usr/bin/rpm-ostree', 'name': 'atomic_container'},
{'path': '/usr/bin/swupd', 'name': 'swupd'},
{'path': '/usr/sbin/sorcery', 'name': 'sorcery'},
{'path': '/usr/bin/installp', 'name': 'installp'},
{'path': '/QOpenSys/pkgs/bin/yum', 'name': 'yum'},
]
@ -69,39 +68,18 @@ class PkgMgrFactCollector(BaseFactCollector):
super(PkgMgrFactCollector, self).__init__(*args, **kwargs)
self._default_unknown_pkg_mgr = 'unknown'
def _check_rh_versions(self, pkg_mgr_name, collected_facts):
def _check_rh_versions(self):
if os.path.exists('/run/ostree-booted'):
return "atomic_container"
# Reset whatever was matched from PKG_MGRS, infer the default pkg_mgr below
pkg_mgr_name = self._default_unknown_pkg_mgr
# Since /usr/bin/dnf and /usr/bin/microdnf can point to different versions of dnf in different distributions
# the only way to infer the default package manager is to look at the binary they are pointing to.
# /usr/bin/microdnf is likely used only in fedora minimal container so /usr/bin/dnf takes precedence
for bin_path in ('/usr/bin/dnf', '/usr/bin/microdnf'):
if os.path.exists(bin_path):
pkg_mgr_name = 'dnf5' if os.path.realpath(bin_path) == '/usr/bin/dnf5' else 'dnf'
break
try:
major_version = collected_facts['ansible_distribution_major_version']
if collected_facts['ansible_distribution'] == 'Kylin Linux Advanced Server':
major_version = major_version.lstrip('V')
distro_major_ver = int(major_version)
except ValueError:
# a non integer magical future version
return self._default_unknown_pkg_mgr
if (
(collected_facts['ansible_distribution'] == 'Fedora' and distro_major_ver < 23)
or (collected_facts['ansible_distribution'] == 'Kylin Linux Advanced Server' and distro_major_ver < 10)
or (collected_facts['ansible_distribution'] == 'Amazon' and distro_major_ver < 2022)
or (collected_facts['ansible_distribution'] == 'TencentOS' and distro_major_ver < 3)
or distro_major_ver < 8 # assume RHEL or a clone
) and any(pm for pm in PKG_MGRS if pm['name'] == 'yum' and os.path.exists(pm['path'])):
pkg_mgr_name = 'yum'
return 'dnf5' if os.path.realpath(bin_path) == '/usr/bin/dnf5' else 'dnf'
return pkg_mgr_name
return self._default_unknown_pkg_mgr
def _check_apt_flavor(self, pkg_mgr_name):
# Check if '/usr/bin/apt' is APT-RPM or an ordinary (dpkg-based) APT.
@ -142,9 +120,9 @@ class PkgMgrFactCollector(BaseFactCollector):
# installed or available to the distro, the ansible_fact entry should be
# the default package manager officially supported by the distro.
if collected_facts['ansible_os_family'] == "RedHat":
pkg_mgr_name = self._check_rh_versions(pkg_mgr_name, collected_facts)
pkg_mgr_name = self._check_rh_versions()
elif collected_facts['ansible_os_family'] == 'Debian' and pkg_mgr_name != 'apt':
# It's possible to install yum, dnf, zypper, rpm, etc inside of
# It's possible to install dnf, zypper, rpm, etc inside of
# Debian. Doing so does not mean the system wants to use them.
pkg_mgr_name = 'apt'
elif collected_facts['ansible_os_family'] == 'Altlinux':

@ -11,16 +11,12 @@
from __future__ import annotations
import os
import time
import glob
from abc import ABCMeta, abstractmethod
from ansible.module_utils.six import with_metaclass
yumdnf_argument_spec = dict(
argument_spec=dict(
allow_downgrade=dict(type='bool', default=False),
allowerasing=dict(default=False, type="bool"),
autoremove=dict(type='bool', default=False),
bugfix=dict(required=False, type='bool', default=False),
cacheonly=dict(type='bool', default=False),
@ -35,10 +31,14 @@ yumdnf_argument_spec = dict(
enablerepo=dict(type='list', elements='str', default=[]),
exclude=dict(type='list', elements='str', default=[]),
installroot=dict(type='str', default="/"),
install_repoquery=dict(type='bool', default=True),
install_repoquery=dict(
type='bool', default=True,
removed_in_version='2.20', removed_from_collection='ansible.builtin',
),
install_weak_deps=dict(type='bool', default=True),
list=dict(type='str'),
name=dict(type='list', elements='str', aliases=['pkg'], default=[]),
nobest=dict(default=False, type="bool"),
releasever=dict(default=None),
security=dict(type='bool', default=False),
skip_broken=dict(type='bool', default=False),
@ -56,7 +56,7 @@ yumdnf_argument_spec = dict(
)
class YumDnf(with_metaclass(ABCMeta, object)): # type: ignore[misc]
class YumDnf(metaclass=ABCMeta):
"""
Abstract class that handles the population of instance variables that should
be identical between both YUM and DNF modules because of the feature parity
@ -68,6 +68,7 @@ class YumDnf(with_metaclass(ABCMeta, object)): # type: ignore[misc]
self.module = module
self.allow_downgrade = self.module.params['allow_downgrade']
self.allowerasing = self.module.params['allowerasing']
self.autoremove = self.module.params['autoremove']
self.bugfix = self.module.params['bugfix']
self.cacheonly = self.module.params['cacheonly']
@ -86,6 +87,7 @@ class YumDnf(with_metaclass(ABCMeta, object)): # type: ignore[misc]
self.install_weak_deps = self.module.params['install_weak_deps']
self.list = self.module.params['list']
self.names = [p.strip() for p in self.module.params['name']]
self.nobest = self.module.params['nobest']
self.releasever = self.module.params['releasever']
self.security = self.module.params['security']
self.skip_broken = self.module.params['skip_broken']
@ -126,31 +128,6 @@ class YumDnf(with_metaclass(ABCMeta, object)): # type: ignore[misc]
results=[],
)
# 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'
@abstractmethod
def is_lockfile_pid_valid(self):
return
def _is_lockfile_present(self):
return (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)) and self.is_lockfile_pid_valid()
def wait_for_lock(self):
'''Poll until the lock is removed if timeout is a positive number'''
if not self._is_lockfile_present():
return
if self.lock_timeout > 0:
for iteration in range(0, self.lock_timeout):
time.sleep(1)
if not self._is_lockfile_present():
return
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):
"""
method to accept a list of strings as the parameter, find any strings

@ -54,17 +54,17 @@ author:
EXAMPLES = r'''
---
- name: Asynchronous yum task
ansible.builtin.yum:
- name: Asynchronous dnf task
ansible.builtin.dnf:
name: docker-io
state: present
async: 1000
poll: 0
register: yum_sleeper
register: dnf_sleeper
- name: Wait for asynchronous job to end
ansible.builtin.async_status:
jid: '{{ yum_sleeper.ansible_job_id }}'
jid: '{{ dnf_sleeper.ansible_job_id }}'
register: job_result
until: job_result.finished
retries: 100
@ -72,7 +72,7 @@ EXAMPLES = r'''
- name: Clean up async file
ansible.builtin.async_status:
jid: '{{ yum_sleeper.ansible_job_id }}'
jid: '{{ dnf_sleeper.ansible_job_id }}'
mode: cleanup
'''

@ -21,7 +21,7 @@ options:
description:
- By default, this module will select the backend based on the C(ansible_pkg_mgr) fact.
default: "auto"
choices: [ auto, dnf4, dnf5 ]
choices: [ auto, yum, yum4, dnf4, dnf5 ]
type: str
version_added: 2.15
name:
@ -206,8 +206,8 @@ options:
version_added: "2.7"
install_repoquery:
description:
- This is effectively a no-op in DNF as it is not needed with DNF, but is an accepted parameter for feature
parity/compatibility with the M(ansible.builtin.yum) module.
- This is effectively a no-op in DNF as it is not needed with DNF.
- This option is deprecated and will be removed in ansible-core 2.20.
type: bool
default: "yes"
version_added: "2.7"
@ -261,7 +261,7 @@ extends_documentation_fragment:
- action_common_attributes.flow
attributes:
action:
details: In the case of dnf, it has 2 action plugins that use it under the hood, M(ansible.builtin.yum) and M(ansible.builtin.package).
details: dnf has 2 action plugins that use it under the hood, M(ansible.builtin.dnf) and M(ansible.builtin.package).
support: partial
async:
support: none
@ -409,7 +409,6 @@ class DnfModule(YumDnf):
super(DnfModule, self).__init__(module)
self._ensure_dnf()
self.lockfile = "/var/cache/dnf/*_lock.pid"
self.pkg_mgr_name = "dnf"
try:
@ -417,15 +416,6 @@ class DnfModule(YumDnf):
except AttributeError:
self.with_modules = False
# DNF specific args that are not part of YumDnf
self.allowerasing = self.module.params['allowerasing']
self.nobest = self.module.params['nobest']
def is_lockfile_pid_valid(self):
# FIXME? it looks like DNF takes care of invalid lock files itself?
# https://github.com/ansible/ansible/issues/57189
return True
def _sanitize_dnf_error_msg_install(self, spec, error):
"""
For unhandled dnf.exceptions.Error scenarios, there are certain error
@ -467,7 +457,7 @@ class DnfModule(YumDnf):
'version': package.version,
'repo': package.repoid}
# envra format for alignment with the yum module
# envra format for backwards compat
result['envra'] = '{epoch}:{name}-{version}-{release}.{arch}'.format(**result)
# keep nevra key for backwards compat as it was previously
@ -1461,11 +1451,7 @@ def main():
# list=repos
# list=pkgspec
# Extend yumdnf_argument_spec with dnf-specific features that will never be
# backported to yum because yum is now in "maintenance mode" upstream
yumdnf_argument_spec['argument_spec']['allowerasing'] = dict(default=False, type='bool')
yumdnf_argument_spec['argument_spec']['nobest'] = dict(default=False, type='bool')
yumdnf_argument_spec['argument_spec']['use_backend'] = dict(default='auto', choices=['auto', 'dnf4', 'dnf5'])
yumdnf_argument_spec['argument_spec']['use_backend'] = dict(default='auto', choices=['auto', 'yum', 'yum4', 'dnf4', 'dnf5'])
module = AnsibleModule(
**yumdnf_argument_spec

@ -151,7 +151,7 @@ options:
validate_certs:
description:
- This is effectively a no-op in the dnf5 module as dnf5 itself handles downloading a https url as the source of the rpm,
but is an accepted parameter for feature parity/compatibility with the M(ansible.builtin.yum) module.
but is an accepted parameter for feature parity/compatibility with the M(ansible.builtin.dnf) module.
type: bool
default: "yes"
sslverify:
@ -174,8 +174,8 @@ options:
default: "no"
install_repoquery:
description:
- This is effectively a no-op in DNF as it is not needed with DNF, but is an accepted parameter for feature
parity/compatibility with the M(ansible.builtin.yum) module.
- This is effectively a no-op in DNF as it is not needed with DNF.
- This option is deprecated and will be removed in ansible-core 2.20.
type: bool
default: "yes"
download_only:
@ -222,7 +222,7 @@ extends_documentation_fragment:
- action_common_attributes.flow
attributes:
action:
details: In the case of dnf, it has 2 action plugins that use it under the hood, M(ansible.builtin.yum) and M(ansible.builtin.package).
details: dnf5 has 2 action plugins that use it under the hood, M(ansible.builtin.dnf) and M(ansible.builtin.package).
support: partial
async:
support: none
@ -408,14 +408,8 @@ class Dnf5Module(YumDnf):
super(Dnf5Module, self).__init__(module)
self._ensure_dnf()
# FIXME https://github.com/rpm-software-management/dnf5/issues/402
self.lockfile = ""
self.pkg_mgr_name = "dnf5"
# DNF specific args that are not part of YumDnf
self.allowerasing = self.module.params["allowerasing"]
self.nobest = self.module.params["nobest"]
def _ensure_dnf(self):
locale = get_best_parsable_locale(self.module)
os.environ["LC_ALL"] = os.environ["LC_MESSAGES"] = locale
@ -457,10 +451,6 @@ class Dnf5Module(YumDnf):
failures=[],
)
def is_lockfile_pid_valid(self):
# FIXME https://github.com/rpm-software-management/dnf5/issues/402
return True
def run(self):
if sys.version_info.major < 3:
self.module.fail_json(
@ -702,10 +692,6 @@ class Dnf5Module(YumDnf):
def main():
# Extend yumdnf_argument_spec with dnf-specific features that will never be
# backported to yum because yum is now in "maintenance mode" upstream
yumdnf_argument_spec["argument_spec"]["allowerasing"] = dict(default=False, type="bool")
yumdnf_argument_spec["argument_spec"]["nobest"] = dict(default=False, type="bool")
Dnf5Module(AnsibleModule(**yumdnf_argument_spec)).run()

@ -15,7 +15,7 @@ author:
- Ansible Core Team
short_description: Generic OS package manager
description:
- This modules manages packages on a target without specifying a package manager module (like M(ansible.builtin.yum), M(ansible.builtin.apt), ...).
- This modules manages packages on a target without specifying a package manager module (like M(ansible.builtin.dnf), M(ansible.builtin.apt), ...).
It is convenient to use in an heterogeneous environment of machines without having to create a specific task for
each package manager. M(ansible.builtin.package) calls behind the module for the package manager used by the operating system
discovered by the module M(ansible.builtin.setup). If M(ansible.builtin.setup) was not yet run, M(ansible.builtin.package) will run it.
@ -38,7 +38,7 @@ options:
required: true
use:
description:
- The required package manager module to use (V(yum), V(apt), and so on). The default V(auto) will use existing facts or try to autodetect it.
- The required package manager module to use (V(dnf), V(apt), and so on). The default V(auto) will use existing facts or try to autodetect it.
- You should only use this field if the automatic selection is not working for some reason.
default: auto
requirements:

File diff suppressed because it is too large Load Diff

@ -1165,7 +1165,7 @@ class ActionBase(ABC):
if data.pop("_ansible_suppress_tmpdir_delete", False):
self._cleanup_remote_tmp = False
# NOTE: yum returns results .. but that made it 'compatible' with squashing, so we allow mappings, for now
# NOTE: dnf returns results .. but that made it 'compatible' with squashing, so we allow mappings, for now
if 'results' in data and (not isinstance(data['results'], Sequence) or isinstance(data['results'], string_types)):
data['ansible_module_results'] = data['results']
del data['results']

@ -8,10 +8,9 @@ from ansible.utils.display import Display
display = Display()
VALID_BACKENDS = frozenset(("dnf", "dnf4", "dnf5"))
VALID_BACKENDS = frozenset(("yum", "yum4", "dnf", "dnf4", "dnf5"))
# FIXME mostly duplicate of the yum action plugin
class ActionModule(ActionBase):
TRANSFERS_FILES = False
@ -29,7 +28,7 @@ class ActionModule(ActionBase):
module = self._task.args.get('use', self._task.args.get('use_backend', 'auto'))
if module == 'auto':
if module in {'yum', 'auto'}:
try:
if self._task.delegate_to: # if we delegate, we should use delegated host's facts
module = self._templar.template("{{hostvars['%s']['ansible_facts']['pkg_mgr']}}" % self._task.delegate_to)
@ -57,7 +56,7 @@ class ActionModule(ActionBase):
)
else:
if module == "dnf4":
if module in {"yum4", "dnf4"}:
module = "dnf"
# eliminate collisions with collections search while still allowing local override

@ -1,110 +0,0 @@
# (c) 2018, Ansible Project
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from ansible.errors import AnsibleActionFail
from ansible.plugins.action import ActionBase
from ansible.utils.display import Display
display = Display()
VALID_BACKENDS = frozenset(('yum', 'yum4', 'dnf', 'dnf4', 'dnf5'))
class ActionModule(ActionBase):
TRANSFERS_FILES = False
def run(self, tmp=None, task_vars=None):
'''
Action plugin handler for yum3 vs yum4(dnf) operations.
Enables the yum module to use yum3 and/or yum4. Yum4 is a yum
command-line compatibility layer on top of dnf. Since the Ansible
modules for yum(aka yum3) and dnf(aka yum4) call each of yum3 and yum4's
python APIs natively on the backend, we need to handle this here and
pass off to the correct Ansible module to execute on the remote system.
'''
self._supports_check_mode = True
self._supports_async = True
result = super(ActionModule, self).run(tmp, task_vars)
del tmp # tmp no longer has any effect
# Carry-over concept from the package action plugin
if 'use' in self._task.args and 'use_backend' in self._task.args:
raise AnsibleActionFail("parameters are mutually exclusive: ('use', 'use_backend')")
module = self._task.args.get('use', self._task.args.get('use_backend', 'auto'))
if module == 'dnf':
module = 'auto'
if module == 'auto':
try:
if self._task.delegate_to: # if we delegate, we should use delegated host's facts
module = self._templar.template("{{hostvars['%s']['ansible_facts']['pkg_mgr']}}" % self._task.delegate_to)
else:
module = self._templar.template("{{ansible_facts.pkg_mgr}}")
except Exception:
pass # could not get it from template!
if module not in VALID_BACKENDS:
facts = self._execute_module(
module_name="ansible.legacy.setup", module_args=dict(filter="ansible_pkg_mgr", gather_subset="!all"),
task_vars=task_vars)
display.debug("Facts %s" % facts)
module = facts.get("ansible_facts", {}).get("ansible_pkg_mgr", "auto")
if (not self._task.delegate_to or self._task.delegate_facts) and module != 'auto':
result['ansible_facts'] = {'pkg_mgr': module}
if module not in VALID_BACKENDS:
result.update(
{
'failed': True,
'msg': ("Could not detect which major revision of yum is in use, which is required to determine module backend.",
"You should manually specify use_backend to tell the module whether to use the yum (yum3) or dnf (yum4) backend})"),
}
)
else:
if module in {"yum4", "dnf4"}:
module = "dnf"
# eliminate collisions with collections search while still allowing local override
module = 'ansible.legacy.' + module
if not self._shared_loader_obj.module_loader.has_plugin(module):
result.update({'failed': True, 'msg': "Could not find a yum module backend for %s." % module})
else:
new_module_args = self._task.args.copy()
if 'use_backend' in new_module_args:
del new_module_args['use_backend']
if 'use' in new_module_args:
del new_module_args['use']
display.vvvv("Running %s as the backend for the yum action plugin" % module)
result.update(self._execute_module(
module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val))
# Cleanup
if not self._task.async_val:
# remove a temporary path we created
self._remove_tmp_path(self._connection._shell.tmpdir)
return result

@ -2,7 +2,7 @@
# https://github.com/ansible/ansible/issues/70244
- block:
- name: Install dosfstools
yum:
dnf:
name: dosfstools
state: present
@ -31,6 +31,6 @@
state: absent
- name: Uninstall dosfstools
yum:
dnf:
name: dosfstools
state: absent

@ -332,7 +332,7 @@
state: absent
- name: Remove all test packages installed
yum:
dnf:
name:
- broken-*
- dinginessentail

@ -149,17 +149,17 @@
when: ansible_distribution in package_distros
##
## yum
## dnf
##
#Validation for new parameter 'use' in yum action plugin which aliases to 'use_backend'
#Validation for new parameter 'use' in dnf action plugin which aliases to 'use_backend'
#Issue: https://github.com/ansible/ansible/issues/70774
- block:
- name: verify if using both the parameters 'use' and 'use_backend' throw error
yum:
dnf:
name: at
state: present
use_backend: yum
use: yum
use_backend: dnf
use: dnf
ignore_errors: yes
register: result
@ -170,7 +170,7 @@
- "not result is changed"
- name: verify if package installation is successful using 'use' parameter
yum:
dnf:
name: at
state: present
use: dnf
@ -182,7 +182,7 @@
- "result is changed"
- name: remove at package
yum:
dnf:
name: at
state: absent
use: dnf
@ -194,7 +194,7 @@
- "result is changed"
- name: verify if package installation is successful using 'use_backend' parameter
yum:
dnf:
name: at
state: present
use_backend: dnf
@ -206,7 +206,7 @@
- "result is changed"
- name: remove at package
yum:
dnf:
name: at
state: absent
use_backend: dnf
@ -218,7 +218,7 @@
- "result is changed"
- name: verify if package installation is successful without using 'use_backend' and 'use' parameters
yum:
dnf:
name: at
state: present
register: result
@ -229,7 +229,7 @@
- "result is changed"
- name: remove at package
yum:
dnf:
name: at
state: absent
register: result

@ -1,10 +0,0 @@
- name: Enable RHEL7 extras
# EPEL 7 depends on RHEL 7 extras, which is not enabled by default on RHEL.
# See: https://docs.fedoraproject.org/en-US/epel/epel-policy/#_policy
command: yum-config-manager --enable rhel-7-server-rhui-extras-rpms
when: ansible_facts.distribution == 'RedHat' and ansible_facts.distribution_major_version == '7'
- name: Install EPEL
yum:
name: https://ci-files.testing.ansible.com/test/integration/targets/setup_epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
disable_gpg_check: true
when: ansible_facts.distribution in ['RedHat', 'CentOS']

@ -1,11 +1,4 @@
- block:
- name: Install epel repo which is missing on rhel-7 and is needed for rpmfluff
include_role:
name: setup_epel
when:
- ansible_distribution in ['RedHat', 'CentOS']
- ansible_distribution_major_version is version('7', '==')
- name: Include distribution specific variables
include_vars: "{{ lookup('first_found', params) }}"
vars:

@ -5,7 +5,7 @@
- name: Ensure required binaries are present
package:
name: "{{ unarchive_packages }}"
when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng')
when: ansible_pkg_mgr in ('dnf', 'apt', 'pkgng')
- name: prep our file
copy:

@ -1,5 +1,5 @@
- name: Test missing binaries
when: ansible_pkg_mgr in ('yum', 'dnf', 'apt', 'pkgng')
when: ansible_pkg_mgr in ('dnf', 'apt', 'pkgng')
block:
- name: Remove zip binaries
package:

@ -1,4 +0,0 @@
destructive
shippable/posix/group1
skip/freebsd
skip/macos

@ -1,5 +0,0 @@
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
tsflags=nodocs

@ -1,22 +0,0 @@
from __future__ import annotations
def filter_list_of_tuples_by_first_param(lst, search, startswith=False):
out = []
for element in lst:
if startswith:
if element[0].startswith(search):
out.append(element)
else:
if search in element[0]:
out.append(element)
return out
class FilterModule(object):
''' filter '''
def filters(self):
return {
'filter_list_of_tuples_by_first_param': filter_list_of_tuples_by_first_param,
}

@ -1,4 +0,0 @@
dependencies:
- prepare_tests
- setup_rpm_repo
- setup_remote_tmp_dir

@ -1,16 +0,0 @@
---
- name: Test cacheonly (clean before testing)
command: yum clean all
- name: Try installing from cache where it has been cleaned
yum:
name: sos
state: latest
cacheonly: true
register: yum_result
ignore_errors: true
- name: Verify yum failure
assert:
that:
- "yum_result is failed"

@ -1,61 +0,0 @@
- name: install htop in check mode to verify changes dict returned
yum:
name: htop
state: present
check_mode: yes
register: yum_changes_check_mode_result
- name: install verify changes dict returned in check mode
assert:
that:
- "yum_changes_check_mode_result is success"
- "yum_changes_check_mode_result is changed"
- "'changes' in yum_changes_check_mode_result"
- "'installed' in yum_changes_check_mode_result['changes']"
- "'htop' in yum_changes_check_mode_result['changes']['installed']"
- name: install htop to verify changes dict returned
yum:
name: htop
state: present
register: yum_changes_result
- name: install verify changes dict returned
assert:
that:
- "yum_changes_result is success"
- "yum_changes_result is changed"
- "'changes' in yum_changes_result"
- "'installed' in yum_changes_result['changes']"
- "'htop' in yum_changes_result['changes']['installed']"
- name: remove htop in check mode to verify changes dict returned
yum:
name: htop
state: absent
check_mode: yes
register: yum_changes_check_mode_result
- name: remove verify changes dict returned in check mode
assert:
that:
- "yum_changes_check_mode_result is success"
- "yum_changes_check_mode_result is changed"
- "'changes' in yum_changes_check_mode_result"
- "'removed' in yum_changes_check_mode_result['changes']"
- "'htop' in yum_changes_check_mode_result['changes']['removed']"
- name: remove htop to verify changes dict returned
yum:
name: htop
state: absent
register: yum_changes_result
- name: remove verify changes dict returned
assert:
that:
- "yum_changes_result is success"
- "yum_changes_result is changed"
- "'changes' in yum_changes_result"
- "'removed' in yum_changes_result['changes']"
- "'htop' in yum_changes_result['changes']['removed']"

@ -1,28 +0,0 @@
- block:
- name: Make sure testing package is not installed
yum:
name: sos
state: absent
- name: Create bogus lock file
copy:
content: bogus content for this lock file
dest: /var/run/yum.pid
- name: Install a package, lock file should be deleted by the module
yum:
name: sos
state: present
register: yum_result
- assert:
that:
- yum_result is success
always:
- name: Clean up
yum:
name: sos
state: absent
when: ansible_pkg_mgr == 'yum'

@ -1,82 +0,0 @@
# (c) 2014, James Tanner <tanner.jc@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Note: We install the yum package onto Fedora so that this will work on dnf systems
# We want to test that for people who don't want to upgrade their systems.
- block:
- name: ensure test packages are removed before starting
yum:
name:
- sos
state: absent
- import_tasks: yum.yml
always:
- name: remove installed packages
yum:
name:
- sos
state: absent
- name: remove installed group
yum:
name: "@Custom Group"
state: absent
- name: On Fedora 28 the above won't remove the group which results in a failure in repo.yml below
yum:
name: dinginessentail
state: absent
when:
- ansible_distribution in ['Fedora']
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']
- block:
- import_tasks: repo.yml
- import_tasks: yum_group_remove.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
always:
- yum_repository:
name: "{{ item }}"
state: absent
loop: "{{ repos }}"
- command: yum clean metadata
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']
- import_tasks: yuminstallroot.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']
- import_tasks: proxy.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']
- import_tasks: check_mode_consistency.yml
when:
- (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int == 7)
- import_tasks: lock.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
- import_tasks: multiarch.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux']
- ansible_architecture == 'x86_64'
# Our output parsing expects us to be on yum, not dnf
- ansible_distribution_major_version is version('7', '<=')
- import_tasks: cacheonly.yml
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']

@ -1,154 +0,0 @@
- block:
- name: Set up test yum repo
yum_repository:
name: multiarch-test-repo
description: ansible-test multiarch test repo
baseurl: "{{ multiarch_repo_baseurl }}"
gpgcheck: no
repo_gpgcheck: no
- name: Install two out of date packages from the repo
yum:
name:
- multiarch-a-1.0
- multiarch-b-1.0
register: outdated
- name: See what we installed
command: rpm -q multiarch-a multiarch-b
register: rpm_q
# Here we assume we're running on x86_64 (and limit to this in main.yml)
# (avoid comparing ansible_architecture because we only have test RPMs
# for i686 and x86_64 and ansible_architecture could be other things.)
- name: Assert that we got the right architecture
assert:
that:
- outdated is changed
- outdated.changes.installed | length == 2
- rpm_q.stdout_lines | length == 2
- rpm_q.stdout_lines[0].endswith('x86_64')
- rpm_q.stdout_lines[1].endswith('x86_64')
- name: Install the same versions, but i686 instead
yum:
name:
- multiarch-a-1.0*.i686
- multiarch-b-1.0*.i686
register: outdated_i686
- name: See what we installed
command: rpm -q multiarch-a multiarch-b
register: rpm_q
- name: Assert that all four are installed
assert:
that:
- outdated_i686 is changed
- outdated.changes.installed | length == 2
- rpm_q.stdout_lines | length == 4
- name: Update them all to 2.0
yum:
name: multiarch-*
state: latest
update_only: true
register: yum_latest
- name: Assert that all were updated and shown in results
assert:
that:
- yum_latest is changed
# This is just testing UI stability. The behavior is arguably not
# correct, because multiple packages are being updated. But the
# "because of (at least)..." wording kinda locks us in to only
# showing one update in this case. :(
- yum_latest.changes.updated | length == 1
- name: Downgrade them so we can upgrade them a different way
yum:
name:
- multiarch-a-1.0*
- multiarch-b-1.0*
allow_downgrade: true
register: downgrade
- name: See what we installed
command: rpm -q multiarch-a multiarch-b --queryformat '%{name}-%{version}.%{arch}\n'
register: rpm_q
- name: Ensure downgrade worked
assert:
that:
- downgrade is changed
- rpm_q.stdout_lines | sort == ['multiarch-a-1.0.i686', 'multiarch-a-1.0.x86_64', 'multiarch-b-1.0.i686', 'multiarch-b-1.0.x86_64']
# This triggers a different branch of logic that the partial wildcard
# above, but we're limited to check_mode here since it's '*'.
- name: Upgrade with full wildcard
yum:
name: '*'
state: latest
update_only: true
update_cache: true
check_mode: true
register: full_wildcard
# https://github.com/ansible/ansible/issues/73284
- name: Ensure we report things correctly (both arches)
assert:
that:
- full_wildcard is changed
- full_wildcard.changes.updated | filter_list_of_tuples_by_first_param('multiarch', startswith=True) | length == 4
- name: Downgrade them so we can upgrade them a different way
yum:
name:
- multiarch-a-1.0*
- multiarch-b-1.0*
allow_downgrade: true
register: downgrade
- name: Try to install again via virtual provides, should be unchanged
yum:
name:
- virtual-provides-multiarch-a
- virtual-provides-multiarch-b
state: present
register: install_vp
- name: Ensure the above did not change
assert:
that:
- install_vp is not changed
- name: Try to upgrade via virtual provides
yum:
name:
- virtual-provides-multiarch-a
- virtual-provides-multiarch-b
state: latest
update_only: true
register: upgrade_vp
- name: Ensure we report things correctly (both arches)
assert:
that:
- upgrade_vp is changed
# This is just testing UI stability, like above.
# We'll only have one package in "updated" per spec, even though
# (in this case) two are getting updated per spec.
- upgrade_vp.changes.updated | length == 2
always:
- name: Remove test yum repo
yum_repository:
name: multiarch-test-repo
state: absent
- name: Remove all test packages installed
yum:
name:
- multiarch-*
- virtual-provides-multiarch-*
state: absent

@ -1,186 +0,0 @@
- name: test yum proxy settings
block:
- name: install tinyproxy
yum:
name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm'
state: installed
# systemd doesn't play nice with this in a container for some reason
- name: start tinyproxy (systemd with tiny proxy does not work in container)
shell: tinyproxy
changed_when: false
# test proxy without auth
- name: set unauthenticated proxy in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy=http://127.0.0.1:8888"
state: present
- name: clear proxy logs
shell: ': > /var/log/tinyproxy/tinyproxy.log'
changed_when: false
args:
executable: /usr/bin/bash
- name: install ninvaders with unauthenticated proxy
yum:
name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
state: installed
register: yum_proxy_result
- assert:
that:
- "yum_proxy_result.changed"
- "'msg' in yum_proxy_result"
- "'rc' in yum_proxy_result"
- name: check that it install via unauthenticated proxy
command: grep -q Request /var/log/tinyproxy/tinyproxy.log
- name: uninstall ninvaders with unauthenticated proxy
yum:
name: ninvaders
state: absent
register: yum_proxy_result
- assert:
that:
- "yum_proxy_result.changed"
- "'msg' in yum_proxy_result"
- "'rc' in yum_proxy_result"
- name: unset unauthenticated proxy in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy=http://127.0.0.1:8888"
state: absent
# test proxy with auth
- name: set authenticated proxy config in tinyproxy.conf
lineinfile:
path: /etc/tinyproxy/tinyproxy.conf
line: "BasicAuth 1testuser 1testpassword"
state: present
# systemd doesn't play nice with this in a container for some reason
- name: SIGHUP tinyproxy to reload config (workaround because of systemd+tinyproxy in container)
shell: kill -HUP $(ps -ef | grep tinyproxy | grep -v grep | awk '{print $2}')
changed_when: false
args:
executable: /usr/bin/bash
- name: set authenticated proxy config in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
state: present
- name: clear proxy logs
shell: ': > /var/log/tinyproxy/tinyproxy.log'
changed_when: false
args:
executable: /usr/bin/bash
- name: install ninvaders with authenticated proxy
yum:
name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
state: installed
register: yum_proxy_result
- assert:
that:
- "yum_proxy_result.changed"
- "'msg' in yum_proxy_result"
- "'rc' in yum_proxy_result"
- name: check that it install via authenticated proxy
command: grep -q Request /var/log/tinyproxy/tinyproxy.log
- name: uninstall ninvaders with authenticated proxy
yum:
name: ninvaders
state: absent
- name: unset authenticated proxy config in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
state: absent
- name: set proxy config in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy=http://127.0.0.1:8888"
state: present
- name: set proxy_username config in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy_username=1testuser"
state: present
- name: set proxy_password config in yum.conf
lineinfile:
path: /etc/yum.conf
line: "proxy_password=1testpassword"
state: present
- name: clear proxy logs
shell: ': > /var/log/tinyproxy/tinyproxy.log'
changed_when: false
args:
executable: /usr/bin/bash
- name: install ninvaders with proxy, proxy_username, and proxy_password config in yum.conf
yum:
name: 'https://ci-files.testing.ansible.com/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
state: installed
register: yum_proxy_result
- assert:
that:
- "yum_proxy_result.changed"
- "'msg' in yum_proxy_result"
- "'rc' in yum_proxy_result"
- name: check that it install via proxy with proxy_username, proxy_password config in yum.conf
command: grep -q Request /var/log/tinyproxy/tinyproxy.log
always:
#cleanup
- name: uninstall tinyproxy
yum:
name: tinyproxy
state: absent
- name: uninstall ninvaders
yum:
name: ninvaders
state: absent
- name: ensure unset authenticated proxy
lineinfile:
path: /etc/yum.conf
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
state: absent
- name: ensure unset proxy
lineinfile:
path: /etc/yum.conf
line: "proxy=http://127.0.0.1:8888"
state: absent
- name: ensure unset proxy_username
lineinfile:
path: /etc/yum.conf
line: "proxy_username=1testuser"
state: absent
- name: ensure unset proxy_password
lineinfile:
path: /etc/yum.conf
line: "proxy_password=1testpassword"
state: absent
when:
- (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int == 7 and ansible_architecture in ['x86_64'])

@ -1,729 +0,0 @@
- block:
- name: Install dinginessentail-1.0-1
yum:
name: dinginessentail-1.0-1
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1.0-1 again
yum:
name: dinginessentail-1.0-1
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1:1.0-2
yum:
name: "dinginessentail-1:1.0-2.{{ ansible_architecture }}"
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove dinginessentail
yum:
name: dinginessentail
state: absent
# ============================================================================
- name: Downgrade dinginessentail
yum:
name: dinginessentail-1.0-1
state: present
allow_downgrade: yes
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Update to the latest dinginessentail
yum:
name: dinginessentail
state: latest
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1.0-1 from a file (higher version is already installed)
yum:
name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove dinginessentail
yum:
name: dinginessentail
state: absent
# ============================================================================
- name: Install dinginessentail-1.0-1 from a file
yum:
name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1.0-1 from a file again
yum:
name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1.0-2 from a file
yum:
name: "{{ repodir }}/dinginessentail-1.0-2.{{ ansible_architecture }}.rpm"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install dinginessentail-1.0-2 from a file again
yum:
name: "{{ repodir }}/dinginessentail-1.0-2.{{ ansible_architecture }}.rpm"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Try to downgrade dinginessentail without allow_downgrade being set
yum:
name: dinginessentail-1.0-1
state: present
allow_downgrade: no
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Update dinginessentail with update_only set
yum:
name: dinginessentail
state: latest
update_only: yes
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove dinginessentail
yum:
name: dinginessentail
state: absent
# ============================================================================
- name: Try to update dinginessentail which is not installed, update_only is set
yum:
name: dinginessentail
state: latest
update_only: yes
register: yum_result
ignore_errors: yes
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
ignore_errors: yes
- name: Verify installation
assert:
that:
- "rpm_result.rc == 1"
- "yum_result.rc == 0"
- "not yum_result.changed"
- "not yum_result is failed"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Try to install incompatible arch
yum:
name: "{{ repodir_ppc64 }}/dinginessentail-1.0-1.ppc64.rpm"
state: present
register: yum_result
ignore_errors: yes
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
ignore_errors: yes
- name: Verify installation
assert:
that:
- "rpm_result.rc == 1"
- "yum_result.rc == 1"
- "not yum_result.changed"
- "yum_result is failed"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Make sure latest dinginessentail is installed
yum:
name: dinginessentail
state: latest
- name: Downgrade dinginessentail using rpm file
yum:
name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"
state: present
allow_downgrade: yes
disable_gpg_check: yes
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- block:
- name: make sure dinginessentail is not installed
yum:
name: dinginessentail
state: absent
- name: install dinginessentail both archs
yum:
name: "{{ pkgs }}"
state: present
disable_gpg_check: true
vars:
pkgs:
- "{{ repodir }}/dinginessentail-1.1-1.x86_64.rpm"
- "{{ repodir_i686 }}/dinginessentail-1.1-1.i686.rpm"
- name: try to install lower version of dinginessentail from rpm file, without allow_downgrade, just one arch
yum:
name: "{{ repodir_i686 }}/dinginessentail-1.0-1.i686.rpm"
state: present
register: yum_result
- name: check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout_lines[0].startswith('dinginessentail-1.1-1')"
- "rpm_result.stdout_lines[1].startswith('dinginessentail-1.1-1')"
- name: verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
when: ansible_architecture == "x86_64"
# ============================================================================
- block:
- name: make sure dinginessentail is not installed
yum:
name: dinginessentail
state: absent
- name: install dinginessentail both archs
yum:
name: "{{ pkgs }}"
state: present
disable_gpg_check: true
vars:
pkgs:
- "{{ repodir }}/dinginessentail-1.0-1.x86_64.rpm"
- "{{ repodir_i686 }}/dinginessentail-1.0-1.i686.rpm"
- name: Update both arch in one task using rpm files
yum:
name: "{{ repodir }}/dinginessentail-1.1-1.x86_64.rpm,{{ repodir_i686 }}/dinginessentail-1.1-1.i686.rpm"
state: present
disable_gpg_check: yes
register: yum_result
- name: check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout_lines[0].startswith('dinginessentail-1.1-1')"
- "rpm_result.stdout_lines[1].startswith('dinginessentail-1.1-1')"
- name: verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
when: ansible_architecture == "x86_64"
# ============================================================================
always:
- name: Clean up
yum:
name: dinginessentail
state: absent
# FIXME: dnf currently doesn't support epoch as part of it's pkg_spec for
# finding install candidates
# https://bugzilla.redhat.com/show_bug.cgi?id=1619687
- block:
- name: Install 1:dinginessentail-1.0-2
yum:
name: "1:dinginessentail-1.0-2.{{ ansible_architecture }}"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
always:
- name: Clean up
yum:
name: dinginessentail
state: absent
when: ansible_pkg_mgr == 'yum'
# DNF1 (Fedora < 26) had some issues:
# - did not accept architecture tag as valid component of a package spec unless
# installing a file (i.e. can't search the repo)
# - doesn't handle downgrade transactions via the API properly, marks it as a
# conflict
#
# NOTE: Both DNF1 and Fedora < 26 have long been EOL'd by their respective
# upstreams
- block:
# ============================================================================
- name: Install dinginessentail-1.0-2
yum:
name: "dinginessentail-1.0-2.{{ ansible_architecture }}"
state: present
disable_gpg_check: true
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Install dinginessentail-1.0-2 again
yum:
name: dinginessentail-1.0-2
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
always:
- name: Clean up
yum:
name: dinginessentail
state: absent
when: not (ansible_distribution == "Fedora" and ansible_distribution_major_version|int < 26)
# https://github.com/ansible/ansible/issues/47689
- block:
- name: Install dinginessentail == 1.0
yum:
name: "dinginessentail == 1.0"
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
always:
- name: Clean up
yum:
name: dinginessentail
state: absent
when: ansible_pkg_mgr == 'yum'
# https://github.com/ansible/ansible/pull/54603
- block:
- name: Install dinginessentail < 1.1
yum:
name: "dinginessentail < 1.1"
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.0')"
- name: Install dinginessentail >= 1.1
yum:
name: "dinginessentail >= 1.1"
state: present
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('dinginessentail-1.1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
always:
- name: Clean up
yum:
name: dinginessentail
state: absent
when: ansible_pkg_mgr == 'yum'
# https://github.com/ansible/ansible/issues/45250
- block:
- name: Install dinginessentail-1.0, dinginessentail-olive-1.0, landsidescalping-1.0
yum:
name: "dinginessentail-1.0,dinginessentail-olive-1.0,landsidescalping-1.0"
state: present
- name: Upgrade dinginessentail*
yum:
name: dinginessentail*
state: latest
register: yum_result
- name: Check dinginessentail with rpm
shell: rpm -q dinginessentail
register: rpm_result
- name: Verify update of dinginessentail
assert:
that:
- "rpm_result.stdout.startswith('dinginessentail-1.1-1')"
- name: Check dinginessentail-olive with rpm
shell: rpm -q dinginessentail-olive
register: rpm_result
- name: Verify update of dinginessentail-olive
assert:
that:
- "rpm_result.stdout.startswith('dinginessentail-olive-1.1-1')"
- name: Check landsidescalping with rpm
shell: rpm -q landsidescalping
register: rpm_result
- name: Verify landsidescalping did NOT get updated
assert:
that:
- "rpm_result.stdout.startswith('landsidescalping-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "yum_result is changed"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
always:
- name: Clean up
yum:
name: dinginessentail,dinginessentail-olive,landsidescalping
state: absent
- block:
- yum:
name: dinginessentail
state: present
- yum:
list: dinginessentail*
register: list_out
- set_fact:
passed: true
loop: "{{ list_out.results }}"
when: item.yumstate == 'installed'
- name: Test that there is yumstate=installed in the result
assert:
that:
- passed is defined
always:
- name: Clean up
yum:
name: dinginessentail
state: absent

@ -1,884 +0,0 @@
# Setup by setup_rpm_repo
- set_fact:
package1: dinginessentail
package2: dinginessentail-olive
# UNINSTALL
- name: uninstall {{ package1 }}
yum: name={{ package1 }} state=removed
register: yum_result
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
ignore_errors: True
register: rpm_result
- name: verify uninstallation of {{ package1 }}
assert:
that:
- "yum_result is success"
- "rpm_result is failed"
# UNINSTALL AGAIN
- name: uninstall {{ package1 }} again in check mode
yum: name={{ package1 }} state=removed
check_mode: true
register: yum_result
- name: verify no change on re-uninstall in check mode
assert:
that:
- "not yum_result is changed"
- name: uninstall {{ package1 }} again
yum: name={{ package1 }} state=removed
register: yum_result
- name: verify no change on re-uninstall
assert:
that:
- "not yum_result is changed"
# INSTALL
- name: install {{ package1 }} in check mode
yum: name={{ package1 }} state=present
check_mode: true
register: yum_result
- name: verify installation of {{ package1 }} in check mode
assert:
that:
- "yum_result is changed"
- name: install {{ package1 }}
yum: name={{ package1 }} state=present
register: yum_result
- name: verify installation of {{ package1 }}
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
# INSTALL AGAIN
- name: install {{ package1 }} again in check mode
yum: name={{ package1 }} state=present
check_mode: true
register: yum_result
- name: verify no change on second install in check mode
assert:
that:
- "not yum_result is changed"
- name: install {{ package1 }} again
yum: name={{ package1 }} state=present
register: yum_result
- name: verify no change on second install
assert:
that:
- "not yum_result is changed"
- name: install {{ package1 }} again with empty string enablerepo
yum: name={{ package1 }} state=present enablerepo=""
register: yum_result
- name: verify no change on third install with empty string enablerepo
assert:
that:
- "yum_result is success"
- "not yum_result is changed"
# This test case is unfortunately distro specific because we have to specify
# repo names which are not the same across Fedora/RHEL/CentOS for base/updates
- name: install {{ package1 }} again with missing repo enablerepo
yum:
name: '{{ package1 }}'
state: present
enablerepo: '{{ repos + ["thisrepodoesnotexist"] }}'
disablerepo: "*"
register: yum_result
when: ansible_distribution == 'CentOS'
- name: verify no change on fourth install with missing repo enablerepo (yum)
assert:
that:
- "yum_result is success"
- "yum_result is not changed"
when: ansible_distribution == 'CentOS'
# This test case is unfortunately distro specific because we have to specify
# repo names which are not the same across Fedora/RHEL/CentOS for base/updates
- name: install repos again with disable all and enable select repo(s)
yum:
name: '{{ package1 }}'
state: present
enablerepo: '{{ repos }}'
disablerepo: "*"
register: yum_result
when: ansible_distribution == 'CentOS'
- name: verify no change on fourth install with missing repo enablerepo (yum)
assert:
that:
- "yum_result is success"
- "yum_result is not changed"
when: ansible_distribution == 'CentOS'
- name: install {{ package1 }} again with only missing repo enablerepo
yum:
name: '{{ package1 }}'
state: present
enablerepo: "thisrepodoesnotexist"
ignore_errors: true
register: yum_result
- name: verify no change on fifth install with only missing repo enablerepo (yum)
assert:
that:
- "yum_result is not success"
when: ansible_pkg_mgr == 'yum'
- name: verify no change on fifth install with only missing repo enablerepo (dnf)
assert:
that:
- "yum_result is success"
when: ansible_pkg_mgr == 'dnf'
# INSTALL AGAIN WITH LATEST
- name: install {{ package1 }} again with state latest in check mode
yum: name={{ package1 }} state=latest
check_mode: true
register: yum_result
- name: verify install {{ package1 }} again with state latest in check mode
assert:
that:
- "not yum_result is changed"
- name: install {{ package1 }} again with state latest idempotence
yum: name={{ package1 }} state=latest
register: yum_result
- name: verify install {{ package1 }} again with state latest idempotence
assert:
that:
- "not yum_result is changed"
# INSTALL WITH LATEST
- name: uninstall {{ package1 }}
yum: name={{ package1 }} state=removed
register: yum_result
- name: verify uninstall {{ package1 }}
assert:
that:
- "yum_result is successful"
- name: copy yum.conf file in case it is missing
copy:
src: yum.conf
dest: /etc/yum.conf
force: False
register: yum_conf_copy
- block:
- name: install {{ package1 }} with state latest in check mode with config file param
yum: name={{ package1 }} state=latest conf_file=/etc/yum.conf
check_mode: true
register: yum_result
- name: verify install {{ package1 }} with state latest in check mode with config file param
assert:
that:
- "yum_result is changed"
always:
- name: remove tmp yum.conf file if we created it
file:
path: /etc/yum.conf
state: absent
when: yum_conf_copy is changed
- name: install {{ package1 }} with state latest in check mode
yum: name={{ package1 }} state=latest
check_mode: true
register: yum_result
- name: verify install {{ package1 }} with state latest in check mode
assert:
that:
- "yum_result is changed"
- name: install {{ package1 }} with state latest
yum: name={{ package1 }} state=latest
register: yum_result
- name: verify install {{ package1 }} with state latest
assert:
that:
- "yum_result is changed"
- name: install {{ package1 }} with state latest idempotence
yum: name={{ package1 }} state=latest
register: yum_result
- name: verify install {{ package1 }} with state latest idempotence
assert:
that:
- "not yum_result is changed"
- name: install {{ package1 }} with state latest idempotence with config file param
yum: name={{ package1 }} state=latest
register: yum_result
- name: verify install {{ package1 }} with state latest idempotence with config file param
assert:
that:
- "not yum_result is changed"
# Multiple packages
- name: uninstall {{ package1 }} and {{ package2 }}
yum: name={{ package1 }},{{ package2 }} state=removed
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
ignore_errors: True
register: rpm_package1_result
- name: check {{ package2 }} with rpm
shell: rpm -q {{ package2 }}
ignore_errors: True
register: rpm_package2_result
- name: verify packages installed
assert:
that:
- "rpm_package1_result is failed"
- "rpm_package2_result is failed"
- name: install {{ package1 }} and {{ package2 }} as comma separated
yum: name={{ package1 }},{{ package2 }} state=present
register: yum_result
- name: verify packages installed
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
- name: check {{ package2 }} with rpm
shell: rpm -q {{ package2 }}
- name: uninstall {{ package1 }} and {{ package2 }}
yum: name={{ package1 }},{{ package2 }} state=removed
register: yum_result
- name: install {{ package1 }} and {{ package2 }} as list
yum:
name:
- '{{ package1 }}'
- '{{ package2 }}'
state: present
register: yum_result
- name: verify packages installed
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
- name: check {{ package2 }} with rpm
shell: rpm -q {{ package2 }}
- name: uninstall {{ package1 }} and {{ package2 }}
yum: name={{ package1 }},{{ package2 }} state=removed
register: yum_result
- name: install {{ package1 }} and {{ package2 }} as comma separated with spaces
yum:
name: "{{ package1 }}, {{ package2 }}"
state: present
register: yum_result
- name: verify packages installed
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }}
- name: check {{ package2 }} with rpm
shell: rpm -q {{ package2 }}
- name: uninstall {{ package1 }} and {{ package2 }}
yum: name={{ package1 }},{{ package2 }} state=removed
- name: install non-existent rpm
yum:
name: does-not-exist
register: non_existent_rpm
ignore_errors: True
- name: check non-existent rpm install failed
assert:
that:
- non_existent_rpm is failed
# Install in installroot='/'
- name: install {{ package1 }}
yum: name={{ package1 }} state=present installroot='/'
register: yum_result
- name: verify installation of {{ package1 }}
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: check {{ package1 }} with rpm
shell: rpm -q {{ package1 }} --root=/
- name: uninstall {{ package1 }}
yum:
name: '{{ package1 }}'
installroot: '/'
state: removed
register: yum_result
# Seems like some yum versions won't download a package from local file repository, continue to use sos for this test.
# https://stackoverflow.com/questions/58295660/yum-downloadonly-ignores-packages-in-local-repo
- name: Test download_only
yum:
name: sos
state: latest
download_only: true
register: yum_result
- name: verify download of sos (part 1 -- yum "install" succeeded)
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: uninstall sos (noop)
yum:
name: sos
state: removed
register: yum_result
- name: verify download of sos (part 2 -- nothing removed during uninstall)
assert:
that:
- "yum_result is success"
- "not yum_result is changed"
- name: uninstall sos for downloadonly/downloaddir test
yum:
name: sos
state: absent
- name: Test download_only/download_dir
yum:
name: sos
state: latest
download_only: true
download_dir: "/var/tmp/packages"
register: yum_result
- name: verify yum output
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- command: "ls /var/tmp/packages"
register: ls_out
- name: Verify specified download_dir was used
assert:
that:
- "'sos' in ls_out.stdout"
- name: install group
yum:
name: "@Custom Group"
state: present
register: yum_result
- name: verify installation of the group
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: install the group again
yum:
name: "@Custom Group"
state: present
register: yum_result
- name: verify nothing changed
assert:
that:
- "yum_result is success"
- "not yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: install the group again but also with a package that is not yet installed
yum:
name:
- "@Custom Group"
- '{{ package2 }}'
state: present
register: yum_result
- name: verify {{ package3 }} is installed
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: try to install the group again, with --check to check 'changed'
yum:
name: "@Custom Group"
state: present
check_mode: yes
register: yum_result
- name: verify nothing changed
assert:
that:
- "not yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: try to install non existing group
yum:
name: "@non-existing-group"
state: present
register: yum_result
ignore_errors: True
- name: verify installation of the non existing group failed
assert:
that:
- "yum_result is failed"
- "not yum_result is changed"
- "yum_result is failed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: try to install non existing file
yum:
name: /tmp/non-existing-1.0.0.fc26.noarch.rpm
state: present
register: yum_result
ignore_errors: yes
- name: verify installation failed
assert:
that:
- "yum_result is failed"
- "not yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- name: try to install from non existing url
yum:
name: https://ci-files.testing.ansible.com/test/integration/targets/yum/non-existing-1.0.0.fc26.noarch.rpm
state: present
register: yum_result
ignore_errors: yes
- name: verify installation failed
assert:
that:
- "yum_result is failed"
- "not yum_result is changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- name: use latest to install httpd
yum:
name: httpd
state: latest
register: yum_result
- name: verify httpd was installed
assert:
that:
- "'changed' in yum_result"
- name: uninstall httpd
yum:
name: httpd
state: removed
- name: update httpd only if it exists
yum:
name: httpd
state: latest
update_only: yes
register: yum_result
- name: verify httpd not installed
assert:
that:
- "not yum_result is changed"
- "'Packages providing httpd not installed due to update_only specified' in yum_result.results"
- name: try to install uncompatible arch rpm on non-ppc64le, should fail
yum:
name: https://ci-files.testing.ansible.com/test/integration/targets/yum/banner-1.3.4-3.el7.ppc64le.rpm
state: present
register: yum_result
ignore_errors: True
when:
- ansible_architecture not in ['ppc64le']
- name: verify that yum failed on non-ppc64le
assert:
that:
- "not yum_result is changed"
- "yum_result is failed"
when:
- ansible_architecture not in ['ppc64le']
- name: try to install uncompatible arch rpm on ppc64le, should fail
yum:
name: https://ci-files.testing.ansible.com/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm
state: present
register: yum_result
ignore_errors: True
when:
- ansible_architecture in ['ppc64le']
- name: verify that yum failed on ppc64le
assert:
that:
- "not yum_result is changed"
- "yum_result is failed"
when:
- ansible_architecture in ['ppc64le']
# setup for testing installing an RPM from url
- set_fact:
pkg_name: noarchfake
pkg_path: '{{ repodir }}/noarchfake-1.0-1.noarch.rpm'
- name: cleanup
yum:
name: "{{ pkg_name }}"
state: absent
# setup end
- name: install a local noarch rpm from file
yum:
name: "{{ pkg_path }}"
state: present
disable_gpg_check: true
register: yum_result
- name: verify installation
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- "yum_result is not failed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: install the downloaded rpm again
yum:
name: "{{ pkg_path }}"
state: present
register: yum_result
- name: verify installation
assert:
that:
- "yum_result is success"
- "not yum_result is changed"
- "yum_result is not failed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: clean up
yum:
name: "{{ pkg_name }}"
state: absent
- name: install from url
yum:
name: "file://{{ pkg_path }}"
state: present
disable_gpg_check: true
register: yum_result
- name: verify installation
assert:
that:
- "yum_result is success"
- "yum_result is changed"
- "yum_result is not failed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: Create a temp RPM file which does not contain nevra information
file:
name: "/tmp/non_existent_pkg.rpm"
state: touch
- name: Try installing RPM file which does not contain nevra information
yum:
name: "/tmp/non_existent_pkg.rpm"
state: present
register: no_nevra_info_result
ignore_errors: yes
- name: Verify RPM failed to install
assert:
that:
- "'changed' in no_nevra_info_result"
- "'msg' in no_nevra_info_result"
- name: Delete a temp RPM file
file:
name: "/tmp/non_existent_pkg.rpm"
state: absent
- name: get yum version
yum:
list: yum
register: yum_version
- name: set yum_version of installed version
set_fact:
yum_version: "{%- if item.yumstate == 'installed' -%}{{ item.version }}{%- else -%}{{ yum_version }}{%- endif -%}"
with_items: "{{ yum_version.results }}"
- name: Ensure double uninstall of wildcard globs works
block:
- name: "Install lohit-*-fonts"
yum:
name: "lohit-*-fonts"
state: present
- name: "Remove lohit-*-fonts (1st time)"
yum:
name: "lohit-*-fonts"
state: absent
register: remove_lohit_fonts_1
- name: "Verify lohit-*-fonts (1st time)"
assert:
that:
- "remove_lohit_fonts_1 is changed"
- "'msg' in remove_lohit_fonts_1"
- "'results' in remove_lohit_fonts_1"
- name: "Remove lohit-*-fonts (2nd time)"
yum:
name: "lohit-*-fonts"
state: absent
register: remove_lohit_fonts_2
- name: "Verify lohit-*-fonts (2nd time)"
assert:
that:
- "remove_lohit_fonts_2 is not changed"
- "'msg' in remove_lohit_fonts_2"
- "'results' in remove_lohit_fonts_2"
- "'lohit-*-fonts is not installed' in remove_lohit_fonts_2['results']"
- block:
- name: uninstall {{ package2 }}
yum: name={{ package2 }} state=removed
- name: check {{ package2 }} with rpm
shell: rpm -q {{ package2 }}
ignore_errors: True
register: rpm_package2_result
- name: verify {{ package2 }} is uninstalled
assert:
that:
- "rpm_package2_result is failed"
- name: exclude {{ package2 }} (yum backend)
lineinfile:
dest: /etc/yum.conf
regexp: (^exclude=)(.)*
line: "exclude={{ package2 }}*"
state: present
when: ansible_pkg_mgr == 'yum'
- name: exclude {{ package2 }} (dnf backend)
lineinfile:
dest: /etc/dnf/dnf.conf
regexp: (^excludepkgs=)(.)*
line: "excludepkgs={{ package2 }}*"
state: present
when: ansible_pkg_mgr == 'dnf'
# begin test case where disable_excludes is supported
- name: Try install {{ package2 }} without disable_excludes
yum: name={{ package2 }} state=latest
register: yum_package2_result
ignore_errors: True
- name: verify {{ package2 }} did not install because it is in exclude list
assert:
that:
- "yum_package2_result is failed"
- name: install {{ package2 }} with disable_excludes
yum: name={{ package2 }} state=latest disable_excludes=all
register: yum_package2_result_using_excludes
- name: verify {{ package2 }} did install using disable_excludes=all
assert:
that:
- "yum_package2_result_using_excludes is success"
- "yum_package2_result_using_excludes is changed"
- "yum_package2_result_using_excludes is not failed"
- name: remove exclude {{ package2 }} (cleanup yum.conf)
lineinfile:
dest: /etc/yum.conf
regexp: (^exclude={{ package2 }}*)
line: "exclude="
state: present
when: ansible_pkg_mgr == 'yum'
- name: remove exclude {{ package2 }} (cleanup dnf.conf)
lineinfile:
dest: /etc/dnf/dnf.conf
regexp: (^excludepkgs={{ package2 }}*)
line: "excludepkgs="
state: present
when: ansible_pkg_mgr == 'dnf'
# Fedora < 26 has a bug in dnf where package excludes in dnf.conf aren't
# actually honored and those releases are EOL'd so we have no expectation they
# will ever be fixed
when: not ((ansible_distribution == "Fedora") and (ansible_distribution_major_version|int < 26))
- name: Check that packages with Provides are handled correctly in state=absent
block:
- name: Install test packages
yum:
name:
- https://ci-files.testing.ansible.com/test/integration/targets/yum/test-package-that-provides-toaster-1.3.3.7-1.el7.noarch.rpm
- https://ci-files.testing.ansible.com/test/integration/targets/yum/toaster-1.2.3.4-1.el7.noarch.rpm
disable_gpg_check: true
register: install
- name: Remove toaster
yum:
name: toaster
state: absent
register: remove
- name: rpm -qa
command: rpm -qa
register: rpmqa
- assert:
that:
- install is successful
- install is changed
- remove is successful
- remove is changed
- "'toaster-1.2.3.4' not in rpmqa.stdout"
- "'test-package-that-provides-toaster' in rpmqa.stdout"
always:
- name: Remove test packages
yum:
name:
- test-package-that-provides-toaster
- toaster
state: absent
- yum:
list: "{{ package1 }}"
register: list_out
- name: check that both yum and dnf return envra
assert:
that:
- '"envra" in list_out["results"][0]'
- name: check that dnf returns nevra for backwards compat
assert:
that:
- '"nevra" in list_out["results"][0]'
when: ansible_pkg_mgr == 'dnf'

@ -1,152 +0,0 @@
- name: install a group to test and yum-utils
yum:
name: "{{ pkgs }}"
state: present
vars:
pkgs:
- "@Custom Group"
- yum-utils
when: ansible_pkg_mgr == "yum"
- name: install a group to test and dnf-utils
yum:
name: "{{ pkgs }}"
state: present
vars:
pkgs:
- "@Custom Group"
- dnf-utils
when: ansible_pkg_mgr == "dnf"
- name: check mode remove the group
yum:
name: "@Custom Group"
state: absent
check_mode: yes
register: yum_result
- name: verify changed
assert:
that:
- "yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'results' in yum_result"
- name: remove the group
yum:
name: "@Custom Group"
state: absent
register: yum_result
- name: verify changed
assert:
that:
- "yum_result.rc == 0"
- "yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: remove the group again
yum:
name: "@Custom Group"
state: absent
register: yum_result
- name: verify changed
assert:
that:
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: check mode remove the group again
yum:
name: "@Custom Group"
state: absent
check_mode: yes
register: yum_result
- name: verify changed
assert:
that:
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'results' in yum_result"
- name: install a group and a package to test
yum:
name: "@Custom Group,sos"
state: present
register: yum_output
- name: check mode remove the group along with the package
yum:
name: "@Custom Group,sos"
state: absent
register: yum_result
check_mode: yes
- name: verify changed
assert:
that:
- "yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'results' in yum_result"
- name: remove the group along with the package
yum:
name: "@Custom Group,sos"
state: absent
register: yum_result
- name: verify changed
assert:
that:
- "yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'results' in yum_result"
- name: check mode remove the group along with the package
yum:
name: "@Custom Group,sos"
state: absent
register: yum_result
check_mode: yes
- name: verify not changed
assert:
that:
- "not yum_result.changed"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'results' in yum_result"

@ -1,132 +0,0 @@
# make a installroot
- name: Create installroot
command: mktemp -d "{{ remote_tmp_dir }}/ansible.test.XXXXXX"
register: yumroot
#- name: Populate directory
# file:
# path: "/{{ yumroot.stdout }}/etc/"
# state: directory
# mode: 0755
#
#- name: Populate directory2
# copy:
# content: "[main]\ndistropkgver={{ ansible_distribution_version }}\n"
# dest: "/{{ yumroot.stdout }}/etc/yum.conf"
- name: Make a necessary directory
file:
path: "{{ yumroot.stdout }}/etc/yum/vars/"
state: directory
mode: 0755
- name: get yum releasever
command: "{{ ansible_python_interpreter }} -c 'import yum; yb = yum.YumBase(); print(yb.conf.yumvar[\"releasever\"])'"
register: releasever
ignore_errors: yes
- name: Populate directory
copy:
content: "{{ releasever.stdout_lines[-1] }}\n"
dest: "/{{ yumroot.stdout }}/etc/yum/vars/releasever"
when: releasever is successful
# This will drag in > 200 MB.
- name: attempt installroot
yum: name=zlib installroot="{{ yumroot.stdout }}/" disable_gpg_check=yes
register: yum_result
- name: check sos with rpm in installroot
shell: rpm -q zlib --root="{{ yumroot.stdout }}/"
failed_when: False
register: rpm_result
- name: verify installation of sos
assert:
that:
- "yum_result.rc == 0"
- "yum_result.changed"
- "rpm_result.rc == 0"
- name: verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: cleanup installroot
file:
path: "{{ yumroot.stdout }}/"
state: absent
# Test for releasever working correctly
#
# Bugfix: https://github.com/ansible/ansible/issues/67050
#
# This test case is based on a reproducer originally reported on Reddit:
# https://www.reddit.com/r/ansible/comments/g2ps32/ansible_yum_module_throws_up_an_error_when/
#
# NOTE: For the Ansible upstream CI we can only run this for RHEL7 because the
# containerized runtimes in shippable don't allow the nested mounting of
# buildah container volumes.
- name: perform yuminstallroot in a buildah mount with releasever
when:
- ansible_facts["distribution_major_version"] == "7"
- ansible_facts["distribution"] == "RedHat"
block:
- name: install required packages for buildah test
yum:
state: present
name:
- buildah
- name: create buildah container from scratch
command: "buildah --name yum_installroot_releasever_test from scratch"
- name: mount the buildah container
command: "buildah mount yum_installroot_releasever_test"
register: buildah_mount
- name: figure out yum value of $releasever
shell: python -c 'import yum; yb = yum.YumBase(); print(yb.conf.yumvar["releasever"])' | tail -1
register: buildah_host_releasever
- name: test yum install of python using releasever
yum:
name: 'python'
state: present
installroot: "{{ buildah_mount.stdout }}"
releasever: "{{ buildah_host_releasever.stdout }}"
register: yum_result
- name: verify installation of python
assert:
that:
- "yum_result.rc == 0"
- "yum_result.changed"
- "rpm_result.rc == 0"
- name: remove python before another test
yum:
name: 'python'
state: absent
installroot: "{{ buildah_mount.stdout }}"
releasever: "{{ buildah_host_releasever.stdout }}"
- name: test yum install of python using releasever with latest
yum:
name: 'python'
state: latest
installroot: "{{ buildah_mount.stdout }}"
releasever: "{{ buildah_host_releasever.stdout }}"
register: yum_result
- name: verify installation of python
assert:
that:
- "yum_result.rc == 0"
- "yum_result.changed"
- "rpm_result.rc == 0"
always:
- name: remove buildah container
command: "buildah rm yum_installroot_releasever_test"
ignore_errors: yes
- name: remove buildah from CI system
yum:
state: absent
name:
- buildah

@ -1 +0,0 @@
multiarch_repo_baseurl: https://ci-files.testing.ansible.com/test/integration/targets/yum/multiarch-test-repo/RPMS/

@ -46,9 +46,6 @@ ignore_missing_imports = True
[mypy-lxml.*]
ignore_missing_imports = True
[mypy-yum.*]
ignore_missing_imports = True
[mypy-rpmUtils.*]
ignore_missing_imports = True

@ -13,9 +13,6 @@ ignore_missing_imports = True
[mypy-md5.*]
ignore_missing_imports = True
[mypy-yum.*]
ignore_missing_imports = True
[mypy-rpmUtils.*]
ignore_missing_imports = True

@ -47,7 +47,6 @@ lib/ansible/modules/systemd_service.py validate-modules:parameter-invalid
lib/ansible/modules/uri.py validate-modules:doc-required-mismatch
lib/ansible/modules/user.py validate-modules:doc-default-does-not-match-spec
lib/ansible/modules/user.py validate-modules:use-run-command-not-popen
lib/ansible/modules/yum.py validate-modules:parameter-invalid
lib/ansible/module_utils/basic.py no-get-exception # only referenced in deprecation code
lib/ansible/module_utils/basic.py pylint:unused-import # deferring resolution to allow enabling the rule now
lib/ansible/module_utils/compat/selinux.py import-3.7!skip # pass/fail depends on presence of libselinux.so

@ -7,43 +7,28 @@ from __future__ import annotations
from ansible.module_utils.facts.system.pkg_mgr import PkgMgrFactCollector
_FEDORA_FACTS = {
"ansible_distribution": "Fedora",
"ansible_distribution_major_version": 38, # any version where yum isn't default
"ansible_os_family": "RedHat"
}
_KYLIN_FACTS = {
"ansible_distribution": "Kylin Linux Advanced Server",
"ansible_distribution_major_version": "V10",
"ansible_os_family": "RedHat"
}
# NOTE pkg_mgr == "dnf" means the dnf module for the dnf 4 or below
_FACTS = {"ansible_os_family": "RedHat"}
def test_default_dnf_version_detection_kylin_dnf4(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/dnf", "/usr/bin/dnf-3"))
mocker.patch("os.path.realpath", lambda p: {"/usr/bin/dnf": "/usr/bin/dnf-3"}.get(p, p))
assert PkgMgrFactCollector().collect(collected_facts=_KYLIN_FACTS).get("pkg_mgr") == "dnf"
# NOTE pkg_mgr == "dnf" means the dnf module for the dnf 4 or below
def test_default_dnf_version_detection_fedora_dnf4(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/dnf", "/usr/bin/dnf-3"))
mocker.patch("os.path.realpath", lambda p: {"/usr/bin/dnf": "/usr/bin/dnf-3"}.get(p, p))
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf"
def test_default_dnf_version_detection_fedora_dnf5(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/dnf", "/usr/bin/dnf5"))
mocker.patch("os.path.realpath", lambda p: {"/usr/bin/dnf": "/usr/bin/dnf5"}.get(p, p))
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf5"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf5"
def test_default_dnf_version_detection_fedora_dnf4_both_installed(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/dnf", "/usr/bin/dnf-3", "/usr/bin/dnf5"))
mocker.patch("os.path.realpath", lambda p: {"/usr/bin/dnf": "/usr/bin/dnf-3"}.get(p, p))
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf"
def test_default_dnf_version_detection_fedora_dnf4_microdnf5_installed(mocker):
@ -55,20 +40,20 @@ def test_default_dnf_version_detection_fedora_dnf4_microdnf5_installed(mocker):
"os.path.realpath",
lambda p: {"/usr/bin/dnf": "/usr/bin/dnf-3", "/usr/bin/microdnf": "/usr/bin/dnf5"}.get(p, p)
)
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf"
def test_default_dnf_version_detection_fedora_dnf4_microdnf(mocker):
mocker.patch("os.path.exists", lambda p: p == "/usr/bin/microdnf")
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf"
def test_default_dnf_version_detection_fedora_dnf5_microdnf(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/microdnf", "/usr/bin/dnf5"))
mocker.patch("os.path.realpath", lambda p: {"/usr/bin/microdnf": "/usr/bin/dnf5"}.get(p, p))
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "dnf5"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "dnf5"
def test_default_dnf_version_detection_fedora_no_default(mocker):
mocker.patch("os.path.exists", lambda p: p in ("/usr/bin/dnf-3", "/usr/bin/dnf5"))
assert PkgMgrFactCollector().collect(collected_facts=_FEDORA_FACTS).get("pkg_mgr") == "unknown"
assert PkgMgrFactCollector().collect(collected_facts=_FACTS).get("pkg_mgr") == "unknown"

@ -1,221 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import unittest
from ansible.modules.yum import YumModule
yum_plugin_load_error = """
Plugin "product-id" can't be imported
Plugin "search-disabled-repos" can't be imported
Plugin "subscription-manager" can't be imported
Plugin "product-id" can't be imported
Plugin "search-disabled-repos" can't be imported
Plugin "subscription-manager" can't be imported
"""
# from https://github.com/ansible/ansible/issues/20608#issuecomment-276106505
wrapped_output_1 = """
Загружены модули: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.h1host.ru
* extras: mirror.h1host.ru
* updates: mirror.h1host.ru
vms-agent.x86_64 0.0-9 dev
"""
# from https://github.com/ansible/ansible/issues/20608#issuecomment-276971275
wrapped_output_2 = """
Загружены модули: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.corbina.net
* extras: mirror.corbina.net
* updates: mirror.corbina.net
empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty.x86_64
0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1-0
addons
libtiff.x86_64 4.0.3-27.el7_3 updates
"""
# From https://github.com/ansible/ansible/issues/20608#issuecomment-276698431
wrapped_output_3 = """
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
ceph.x86_64 1:11.2.0-0.el7 ceph
ceph-base.x86_64 1:11.2.0-0.el7 ceph
ceph-common.x86_64 1:11.2.0-0.el7 ceph
ceph-mds.x86_64 1:11.2.0-0.el7 ceph
ceph-mon.x86_64 1:11.2.0-0.el7 ceph
ceph-osd.x86_64 1:11.2.0-0.el7 ceph
ceph-selinux.x86_64 1:11.2.0-0.el7 ceph
libcephfs1.x86_64 1:11.0.2-0.el7 ceph
librados2.x86_64 1:11.2.0-0.el7 ceph
libradosstriper1.x86_64 1:11.2.0-0.el7 ceph
librbd1.x86_64 1:11.2.0-0.el7 ceph
librgw2.x86_64 1:11.2.0-0.el7 ceph
python-cephfs.x86_64 1:11.2.0-0.el7 ceph
python-rados.x86_64 1:11.2.0-0.el7 ceph
python-rbd.x86_64 1:11.2.0-0.el7 ceph
"""
# from https://github.com/ansible/ansible-modules-core/issues/4318#issuecomment-251416661
wrapped_output_4 = """
ipxe-roms-qemu.noarch 20160127-1.git6366fa7a.el7
rhelosp-9.0-director-puddle
quota.x86_64 1:4.01-11.el7_2.1 rhelosp-rhel-7.2-z
quota-nls.noarch 1:4.01-11.el7_2.1 rhelosp-rhel-7.2-z
rdma.noarch 7.2_4.1_rc6-2.el7 rhelosp-rhel-7.2-z
screen.x86_64 4.1.0-0.23.20120314git3c2946.el7_2
rhelosp-rhel-7.2-z
sos.noarch 3.2-36.el7ost.2 rhelosp-9.0-puddle
sssd-client.x86_64 1.13.0-40.el7_2.12 rhelosp-rhel-7.2-z
"""
# A 'normal-ish' yum check-update output, without any wrapped lines
unwrapped_output_rhel7 = """
Loaded plugins: etckeeper, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
NetworkManager-openvpn.x86_64 1:1.2.6-1.el7 epel
NetworkManager-openvpn-gnome.x86_64 1:1.2.6-1.el7 epel
cabal-install.x86_64 1.16.1.0-2.el7 epel
cgit.x86_64 1.1-1.el7 epel
python34-libs.x86_64 3.4.5-3.el7 epel
python34-test.x86_64 3.4.5-3.el7 epel
python34-tkinter.x86_64 3.4.5-3.el7 epel
python34-tools.x86_64 3.4.5-3.el7 epel
qgit.x86_64 2.6-4.el7 epel
rdiff-backup.x86_64 1.2.8-12.el7 epel
stoken-libs.x86_64 0.91-1.el7 epel
xlockmore.x86_64 5.49-2.el7 epel
"""
# Some wrapped obsoletes for prepending to output for testing both
wrapped_output_rhel7_obsoletes_postfix = """
Obsoleting Packages
ddashboard.x86_64 0.2.0.1-1.el7_3 mhlavink-developerdashboard
developerdashboard.x86_64 0.1.12.2-1.el7_2 @mhlavink-developerdashboard
python-bugzilla.noarch 1.2.2-3.el7_2.1 mhlavink-developerdashboard
python-bugzilla-develdashboardfixes.noarch
1.2.2-3.el7 @mhlavink-developerdashboard
python2-futures.noarch 3.0.5-1.el7 epel
python-futures.noarch 3.0.3-1.el7 @epel
python2-pip.noarch 8.1.2-5.el7 epel
python-pip.noarch 7.1.0-1.el7 @epel
python2-pyxdg.noarch 0.25-6.el7 epel
pyxdg.noarch 0.25-5.el7 @epel
python2-simplejson.x86_64 3.10.0-1.el7 epel
python-simplejson.x86_64 3.3.3-1.el7 @epel
Security: kernel-3.10.0-327.28.2.el7.x86_64 is an installed security update
Security: kernel-3.10.0-327.22.2.el7.x86_64 is the currently running version
"""
wrapped_output_multiple_empty_lines = """
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
screen.x86_64 4.1.0-0.23.20120314git3c2946.el7_2
rhelosp-rhel-7.2-z
sos.noarch 3.2-36.el7ost.2 rhelosp-9.0-puddle
"""
longname = """
Loaded plugins: fastestmirror, priorities, rhnplugin
This system is receiving updates from RHN Classic or Red Hat Satellite.
Loading mirror speeds from cached hostfile
xxxxxxxxxxxxxxxxxxxxxxxxxx.noarch
1.16-1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
glibc.x86_64 2.17-157.el7_3.1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"""
unwrapped_output_rhel7_obsoletes = unwrapped_output_rhel7 + wrapped_output_rhel7_obsoletes_postfix
unwrapped_output_rhel7_expected_new_obsoletes_pkgs = [
"ddashboard", "python-bugzilla", "python2-futures", "python2-pip",
"python2-pyxdg", "python2-simplejson"
]
unwrapped_output_rhel7_expected_old_obsoletes_pkgs = [
"developerdashboard", "python-bugzilla-develdashboardfixes",
"python-futures", "python-pip", "pyxdg", "python-simplejson"
]
unwrapped_output_rhel7_expected_updated_pkgs = [
"NetworkManager-openvpn", "NetworkManager-openvpn-gnome", "cabal-install",
"cgit", "python34-libs", "python34-test", "python34-tkinter",
"python34-tools", "qgit", "rdiff-backup", "stoken-libs", "xlockmore"
]
class TestYumUpdateCheckParse(unittest.TestCase):
def _assert_expected(self, expected_pkgs, result):
for expected_pkg in expected_pkgs:
self.assertIn(expected_pkg, result)
self.assertEqual(len(result), len(expected_pkgs))
self.assertIsInstance(result, dict)
def test_empty_output(self):
res, obs = YumModule.parse_check_update("")
expected_pkgs = []
self._assert_expected(expected_pkgs, res)
def test_longname(self):
res, obs = YumModule.parse_check_update(longname)
expected_pkgs = ['xxxxxxxxxxxxxxxxxxxxxxxxxx', 'glibc']
self._assert_expected(expected_pkgs, res)
def test_plugin_load_error(self):
res, obs = YumModule.parse_check_update(yum_plugin_load_error)
expected_pkgs = []
self._assert_expected(expected_pkgs, res)
def test_wrapped_output_1(self):
res, obs = YumModule.parse_check_update(wrapped_output_1)
expected_pkgs = ["vms-agent"]
self._assert_expected(expected_pkgs, res)
def test_wrapped_output_2(self):
res, obs = YumModule.parse_check_update(wrapped_output_2)
expected_pkgs = ["empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty-empty",
"libtiff"]
self._assert_expected(expected_pkgs, res)
def test_wrapped_output_3(self):
res, obs = YumModule.parse_check_update(wrapped_output_3)
expected_pkgs = ["ceph", "ceph-base", "ceph-common", "ceph-mds",
"ceph-mon", "ceph-osd", "ceph-selinux", "libcephfs1",
"librados2", "libradosstriper1", "librbd1", "librgw2",
"python-cephfs", "python-rados", "python-rbd"]
self._assert_expected(expected_pkgs, res)
def test_wrapped_output_4(self):
res, obs = YumModule.parse_check_update(wrapped_output_4)
expected_pkgs = ["ipxe-roms-qemu", "quota", "quota-nls", "rdma", "screen",
"sos", "sssd-client"]
self._assert_expected(expected_pkgs, res)
def test_wrapped_output_rhel7(self):
res, obs = YumModule.parse_check_update(unwrapped_output_rhel7)
self._assert_expected(unwrapped_output_rhel7_expected_updated_pkgs, res)
def test_wrapped_output_rhel7_obsoletes(self):
res, obs = YumModule.parse_check_update(unwrapped_output_rhel7_obsoletes)
self._assert_expected(
unwrapped_output_rhel7_expected_updated_pkgs + unwrapped_output_rhel7_expected_new_obsoletes_pkgs,
res
)
self._assert_expected(unwrapped_output_rhel7_expected_old_obsoletes_pkgs, obs)
def test_wrapped_output_multiple_empty_lines(self):
res, obs = YumModule.parse_check_update(wrapped_output_multiple_empty_lines)
self._assert_expected(['screen', 'sos'], res)
Loading…
Cancel
Save