ansible/test/integration/targets/yum/tasks/repo.yml
Adam Miller 397febd343 YUM4/DNF compatibility via yum action plugin (#44322)
* YUM4/DNF compatibility via yum action plugin

DNF does not natively support allow_downgrade as an option, instead
that is always the default (not configurable by the administrator)
so it had to be implemented

 - Fixed group actions in check mode to report correct changed state
 - Better error handling for depsolve and transaction errors in DNF
 - Fixed group action idempotent transactions
 - Add use_backend to yum module/action plugin
 - Fix dnf handling of autoremove (didn't used to work nor had a
   default value specified, now does work and matches default
   behavior of yum)
 - Enable installroot tests for yum4(dnf) integration testing, dnf
   backend now supports that
 - Switch from zip to bc for certain package install/remove test
   cases in yum integration tests. The dnf depsolver downgrades
   python when you uninstall zip which alters the test environment
   and we have no control over that.
 - Add changelog fragment
 - Return a pkg_mgr fact if it was not previously set.
2018-08-27 10:17:47 -07:00

558 lines
15 KiB
YAML

- block:
- name: Install foo-1.0-1
yum:
name: foo-1.0-1
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1.0-1 again
yum:
name: foo-1.0-1
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1:1.0-2
yum:
name: "foo-1:1.0-2.{{ ansible_architecture }}"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove foo
yum:
name: foo
state: absent
# ============================================================================
- name: Downgrade foo
yum:
name: foo-1.0-1
state: present
allow_downgrade: yes
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-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 foo
yum:
name: foo
state: latest
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1.0-1 from a file (higher version is already installed)
yum:
name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove foo
yum:
name: foo
state: absent
# ============================================================================
- name: Install foo-1.0-1 from a file
yum:
name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1.0-1 from a file again
yum:
name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1.0-2 from a file
yum:
name: "{{ repodir }}/foo-1.0-2.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Install foo-1.0-2 from a file again
yum:
name: "{{ repodir }}/foo-1.0-2.{{ ansible_architecture }}.rpm"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-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 foo without allow_downgrade being set
yum:
name: foo-1.0-1
state: present
allow_downgrade: no
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================
- name: Update foo with update_only set
yum:
name: foo
state: latest
update_only: yes
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.1-1')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Remove foo
yum:
name: foo
state: absent
# ============================================================================
- name: Try to update foo which is not installed, update_only is set
yum:
name: foo
state: latest
update_only: yes
register: yum_result
ignore_errors: yes
- name: Check foo with rpm
shell: rpm -q foo
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 }}/foo-1.0-1.ppc64.rpm"
state: present
register: yum_result
ignore_errors: yes
- name: Check foo with rpm
shell: rpm -q foo
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 foo is installed
yum:
name: foo
state: latest
- name: Downgrade foo using rpm file
yum:
name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm"
state: present
allow_downgrade: yes
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-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 foo is not installed
yum:
name: foo
state: absent
- name: install foo both archs
yum:
name: "{{ item }}"
state: present
with_items:
- "{{ repodir }}/foo-1.1-1.x86_64.rpm"
- "{{ repodir_i686 }}/foo-1.1-1.i686.rpm"
- name: try to install lower version of foo from rpm file, without allow_downgrade, just one arch
yum:
name: "{{ repodir_i686 }}/foo-1.0-1.i686.rpm"
state: present
register: yum_result
- name: check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout_lines[0].startswith('foo-1.1-1')"
- "rpm_result.stdout_lines[1].startswith('foo-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 foo is not installed
yum:
name: foo
state: absent
- name: install foo both archs
yum:
name: "{{ item }}"
state: present
with_items:
- "{{ repodir }}/foo-1.0-1.x86_64.rpm"
- "{{ repodir_i686 }}/foo-1.0-1.i686.rpm"
- name: Update both arch in one task using rpm files
yum:
name: "{{ repodir }}/foo-1.1-1.x86_64.rpm,{{ repodir_i686 }}/foo-1.1-1.i686.rpm"
state: present
register: yum_result
- name: check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout_lines[0].startswith('foo-1.1-1')"
- "rpm_result.stdout_lines[1].startswith('foo-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: foo
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:foo-1.0-2
yum:
name: "1:foo-1.0-2.{{ ansible_architecture }}"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-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: foo
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 foo-1.0-2
yum:
name: "foo-1.0-2.{{ ansible_architecture }}"
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "yum_result.changed"
- "rpm_result.stdout.startswith('foo-1.0-2')"
- name: Verify yum module outputs
assert:
that:
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
- name: Install foo-1.0-2 again
yum:
name: foo-1.0-2
state: present
register: yum_result
- name: Check foo with rpm
shell: rpm -q foo
register: rpm_result
- name: Verify installation
assert:
that:
- "not yum_result.changed"
- "rpm_result.stdout.startswith('foo-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: foo
state: absent
when: not (ansible_distribution == "Fedora" and ansible_distribution_major_version|int < 26)