Fix yum_repository tests for CentOS 8 (#64863)

Refactor tests to run the same tasks with CentOS and Fedora using different variables.
This commit is contained in:
Sam Doran 2019-11-15 17:05:23 -05:00 committed by GitHub
parent 477fa63f68
commit 05a7ce798d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 239 additions and 363 deletions

View file

@ -1,24 +1,217 @@
# (c) 2017, Red Hat <davidn@redhat.coms> - name: Run tests
when: ansible_facts.distribution in ['CentOS', 'Fedora']
block:
- name: Include distribution specific variables
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- "{{ ansible_facts.distribution }}.yml"
- default.yml
paths:
- vars
# This file is part of Ansible - name: ensure {{ yum_repository_test_package }} is uninstalled to begin with
# action: "{{ ansible_facts.pkg_mgr }}"
# Ansible is free software: you can redistribute it and/or modify args:
# it under the terms of the GNU General Public License as published by name: "{{ yum_repository_test_package }}"
# the Free Software Foundation, either version 3 of the License, or state: absent
# (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/>.
- include: 'yum_repository_centos.yml' - name: disable {{ yum_repository_test_repo.name }}
when: ansible_distribution in ['CentOS'] yum_repository:
name: "{{ yum_repository_test_repo.name }}"
state: absent
# separate file for fedora because repos, package managers and packages are - name: disable {{ yum_repository_test_repo.name }} (Idempotant)
# different yum_repository:
- include: 'yum_repository_fedora.yml' name: "{{ yum_repository_test_repo.name }}"
when: ansible_distribution in ['Fedora'] state: absent
register: test_repo_remove
- name: check return values
assert:
that:
- "test_repo_remove.repo == yum_repository_test_repo.name"
- "test_repo_remove.state == 'absent'"
- name: check Idempotant
assert:
that: not test_repo_remove.changed
- name: install {{ yum_repository_test_package }}, which should fail
action: "{{ ansible_facts.pkg_mgr }}"
args:
name: "{{ yum_repository_test_package }}"
state: present
ignore_errors: yes
register: test_package_result
- name: check that install failed
assert:
that:
- test_package_result.failed
- test_package_result.msg in expected_messages
vars:
expected_messages:
- No package matching '{{ yum_repository_test_package }}' found available, installed or updated
- Failed to install some of the specified packages
- name: re-add {{ yum_repository_test_repo.name }}
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
description: "{{ yum_repository_test_repo.description }}"
baseurl: "{{ yum_repository_test_repo.baseurl }}"
state: present
register: test_repo_add
- name: check return values
assert:
that:
- test_repo_add.repo == yum_repository_test_repo.name
- test_repo_add.state == 'present'
- name: get repolist
shell: yum repolist
register: repolist
until: repolist.rc == 0
retries: 5
args:
warn: no
- name: ensure {{ yum_repository_test_repo.name }} was added
assert:
that:
- yum_repository_test_repo.name in repolist.stdout
- test_repo_add.changed
- name: install {{ yum_repository_test_package }}
action: "{{ ansible_facts.pkg_mgr }}"
args:
name: "{{ yum_repository_test_package }}"
state: present
register: test_package_result
- name: check that {{ yum_repository_test_package }} was successfully installed
assert:
that:
- test_package_result.changed
- name: remove {{ yum_repository_test_package }}
action: "{{ ansible_facts.pkg_mgr }}"
args:
name: "{{ yum_repository_test_package }}"
state: absent
- name: change configuration of {{ yum_repository_test_repo.name }} repo
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
baseurl: "{{ yum_repository_test_repo.baseurl }}"
description: New description
async: no
enablegroups: no
file: "{{ yum_repository_test_repo.name ~ 2 }}"
ip_resolve: 4
keepalive: no
register: test_repo_add1
- name: check that options are correctly getting written to the repo file
assert:
that:
- "'async = 0' in repo_file_contents"
- "'name = New description' in repo_file_contents"
- "'enablegroups = 0' in repo_file_contents"
- "'ip_resolve = 4' in repo_file_contents"
- "'keepalive = 0' in repo_file_contents"
vars:
repo_file: "{{ '/etc/yum.repos.d/' ~ yum_repository_test_repo.name ~ '2.repo' }}"
repo_file_contents: "{{ lookup('file', repo_file) }}"
- name: check new config doesn't change (Idempotant)
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
baseurl: "{{ yum_repository_test_repo.baseurl }}"
description: New description
async: no
enablegroups: no
file: "{{ yum_repository_test_repo.name ~ 2 }}"
ip_resolve: 4
keepalive: no
register: test_repo_add2
- name: check Idempotant
assert:
that:
- test_repo_add1 is changed
- test_repo_add2 is not changed
- name: re-enable the {{ yum_repository_test_repo.name }} repo
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
description: "{{ yum_repository_test_repo.description }}"
baseurl: "{{ yum_repository_test_repo.baseurl }}"
state: present
- name: re-enable the {{ yum_repository_test_repo.name }} repo (Idempotant)
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
description: "{{ yum_repository_test_repo.description }}"
baseurl: "{{ yum_repository_test_repo.baseurl }}"
state: present
register: test_repo_add
- name: check Idempotant
assert:
that: test_repo_add is not changed
- name: Test list options
yum_repository:
name: listtest
description: Testing list feature
baseurl:
- "{{ yum_repository_test_repo.baseurl }}"
- "{{ yum_repository_test_repo.baseurl | replace('download[0-9]?\\.', 'download2\\.', 1) }}"
gpgkey:
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts.distribution_major_version }}
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG2-KEY-EPEL-{{ ansible_facts.distribution_major_version }}
exclude:
- aaa
- bbb
includepkgs:
- ccc
- ddd
- name: Assert that lists were properly inserted
assert:
that:
- url_hostname in repofile
- url_hostname2 in repofile
- "'RPM-GPG-KEY-EPEL' in repofile"
- "'RPM-GPG2-KEY-EPEL' in repofile"
- "'aaa bbb' in repofile"
- "'ccc ddd' in repofile"
vars:
repofile: "{{ lookup('file', '/etc/yum.repos.d/listtest.repo') }}"
url_hostname: "{{ yum_repository_test_repo.baseurl | urlsplit('hostname') }}"
url_hostname2: "{{ url_hostname | replace('download[0-9]?\\.', 'download2\\.', 1) }}"
- name: CLEANUP | Remove list test repo
yum_repository:
name: listtest
state: absent
- name: CLEANUP | Remove {{ yum_repository_test_repo.name }}
yum_repository:
name: "{{ yum_repository_test_repo.name }}"
state: absent
- name: CLEANUP | Enable EPEL
yum_repository:
name: epel
state: present
description: "{{ yum_repository_epel.description | default(omit) }}"
metalink: "{{ yum_repository_epel.metalink | default(omit) }}"
mirrorlist: "{{ yum_repository_epel.mirrorlist | default(omit) }}"
gpgkey: "{{ yum_repository_epel.gpgkey }}"
gpgcheck: yes
when: ansible_facts.distribution == 'CentOS'

View file

@ -1,199 +0,0 @@
---
- name: ensure sl is uninstalled to begin with
yum:
name: sl
state: absent
- name: disable epel
yum_repository:
name: epel
state: absent
- name: disable epel (Idempotant)
yum_repository:
name: epel
state: absent
register: epel_remove
- name: check return values
assert:
that:
- "epel_remove.repo == 'epel'"
- "epel_remove.state == 'absent'"
- name: check Idempotant
assert:
that: not epel_remove.changed
- name: install sl, which should fail
yum:
name: sl
state: present
ignore_errors: yes
register: sl_result
- debug: var=sl_result
- name: check that install failed
assert:
that:
- sl_result.failed
- "sl_result.msg==\"No package matching 'sl' found available, installed or updated\""
- name: re-add epel
yum_repository:
name: epel
description: EPEL yum repo
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
state: present
register: epel_add
- name: check return values
assert:
that:
- "epel_add.repo == 'epel'"
- "epel_add.state == 'present'"
- name: get repolist
shell: yum repolist
register: repolist
- name: ensure epel was added
assert:
that:
- "'epel' in repolist.stdout"
- epel_add.changed
- name: install sl
yum:
name: sl
state: present
register: sl_result
- name: check that sl was successfully installed
assert:
that:
- sl_result.changed
- name: remove sl
yum:
name: sl
state: absent
- name: change configuration of epel repo
yum_repository:
name: epel
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
description: New description
async: no
enablegroups: no
file: epel2
ip_resolve: 4
keepalive: no
register: epel_add
- set_fact:
repofile: "{{ lookup('file', '/etc/yum.repos.d/epel2.repo') }}"
- debug: var=repofile
- name: check that options are correctly getting written to the repo file
assert:
that:
- "'async = 0' in repofile"
- "'name = New description' in repofile"
- "'enablegroups = 0' in repofile"
- "'ip_resolve = 4' in repofile"
- "'keepalive = 0' in repofile"
- name: check new config doesn't change (Idempotant)
yum_repository:
name: epel
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
description: New description
async: no
enablegroups: no
file: epel2
ip_resolve: 4
keepalive: no
register: epel_add
- name: check Idempotant
assert:
that: not epel_add.changed
- name: re-enable the epel repo
yum_repository:
name: epel
description: EPEL yum repo
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
state: present
- name: re-enable the epel repo (Idempotant)
yum_repository:
name: epel
description: EPEL yum repo
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
state: present
register: epel_add
- name: check Idempotant
assert:
that: not epel_add.changed
- name: Test list options
yum_repository:
name: listtest
description: Testing list feature
baseurl:
- https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
- https://download2.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
gpgkey:
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG2-KEY-EPEL-{{ ansible_distribution_major_version }}
exclude:
- aaa
- bbb
includepkgs:
- ccc
- ddd
- set_fact:
repofile: "{{ lookup('file', '/etc/yum.repos.d/listtest.repo') }}"
- name: Assert that lists were properly inserted
assert:
that:
- "'download.fedoraproject.org' in repofile"
- "'download2.fedoraproject.org' in repofile"
- "'RPM-GPG-KEY-EPEL' in repofile"
- "'RPM-GPG2-KEY-EPEL' in repofile"
- "'aaa bbb' in repofile"
- "'ccc ddd' in repofile"
- name: Cleanup list test repo
yum_repository:
name: listtest
state: absent
- name: disable epel (clean up)
yum_repository:
name: epel
state: absent
- name: add epel
yum_repository:
name: epel
description: EPEL yum repo
baseurl: https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
state: present
gpgcheck: no
- set_fact:
repofile: "{{ lookup('file', '/etc/yum.repos.d/epel.repo') }}"
- name: check for gpgcheck=0
assert:
that:
- "'gpgcheck = 0' in repofile"

View file

@ -1,143 +0,0 @@
---
- name: ensure libbdplus is uninstalled to begin with
dnf:
name: libbdplus
state: absent
- name: disable rpmfusion
yum_repository:
name: rpmfusion-free
state: absent
- name: disable rpmfusion (Idempotant)
yum_repository:
name: rpmfusion-free
state: absent
register: fusion_remove
- name: check return values
assert:
that:
- "fusion_remove.repo == 'rpmfusion-free'"
- "fusion_remove.state == 'absent'"
- name: check Idempotant
assert:
that: not fusion_remove.changed
- name: install libbdplus, which should fail
dnf:
name: libbdplus
state: present
ignore_errors: yes
register: lib_result
- name: check that install failed
assert:
that:
- lib_result.failed
- "lib_result.msg=='Failed to install some of the specified packages'"
- name: re-add rpmfusion
yum_repository:
name: rpmfusion-free
description: RPM Fusion for Fedora 25 - Free
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
state: present
register: fusion_add
- name: check return values
assert:
that:
- "fusion_add.repo == 'rpmfusion-free'"
- "fusion_add.state == 'present'"
- name: get repolist
shell: dnf repolist
register: repolist
- name: ensure rpm fusion was added
assert:
that:
- "'rpmfusion-free' in repolist.stdout"
- fusion_add.changed
- name: install libbdplus
dnf:
name: libbdplus
state: present
register: lib_result
- name: check that libbdplus was successfully installed
assert:
that:
- lib_result.changed
- name: remove libbdplus
dnf:
name: libbdplus
state: absent
- name: change configuration of rpmfusion repo
yum_repository:
name: rpmfusion-free
description: New description
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
async: no
enablegroups: no
file: fusion2
exclude:
- libbdplus
ip_resolve: 4
keepalive: no
register: fusion_add
- set_fact:
repofile: "{{ lookup('file', '/etc/yum.repos.d/fusion2.repo') }}"
- name: check that options are correctly getting written to the repo file
assert:
that:
- "'async = 0' in repofile"
- "'name = New description' in repofile"
- "'enablegroups = 0' in repofile"
- "'exclude = libbdplus' in repofile"
- "'ip_resolve = 4' in repofile"
- "'keepalive = 0' in repofile"
- name: check new config doesn't change (Idempotant)
yum_repository:
name: rpmfusion-free
description: New description
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
async: no
enablegroups: no
file: fusion2
exclude:
- libbdplus
ip_resolve: 4
keepalive: no
register: fusion_add
- name: check Idempotant
assert:
that: not fusion_add.changed
- name: re-add rpmfusion
yum_repository:
name: rpmfusion-free
description: RPM Fusion for Fedora 25 - Free
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
state: present
- name: re-add rpmfusion
yum_repository:
name: rpmfusion-free
description: RPM Fusion for Fedora 25 - Free
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
state: present
register: fusion_add
- name: check Idempotant
assert:
that: not fusion_add.changed

View file

@ -0,0 +1,10 @@
yum_repository_test_package: sshpass
yum_repository_test_repo:
name: epel
description: EPEL yum repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/Everything/$basearch
yum_repository_epel:
description: Extra Packages for Enterprise Linux $releasever - $basearch
metalink: https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts.distribution_major_version }}

View file

@ -0,0 +1,10 @@
yum_repository_test_package: sl
yum_repository_test_repo:
name: epel
description: EPEL yum repo
baseurl: http://download.fedoraproject.org/pub/epel/{{ ansible_facts.distribution_major_version }}/$basearch
yum_repository_epel:
description: Extra Packages for Enterprise Linux {{ ansible_facts.distribution_major_version }} - $basearch
mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-{{ ansible_facts.distribution_major_version }}&arch=$basearch
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts.distribution_major_version }}

View file

@ -0,0 +1,5 @@
yum_repository_test_package: libbdplus
yum_repository_test_repo:
name: rpmfusion-free
description: RPM Fusion for Fedora {{ ansible_distribution_major_version }} - Free
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/