Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yum: allow for downgrade using rpm file #31647

Merged
merged 1 commit into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/ansible/modules/packaging/os/yum.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,20 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
(name, ver, rel, epoch, arch) = splitFilename(envra)
installed_pkgs = is_installed(module, repoq, name, conf_file, en_repos=en_repos, dis_repos=dis_repos, installroot=installroot)

# TODO support downgrade for rpm files
if len(installed_pkgs) == 1:
installed_pkg = installed_pkgs[0]
(cur_name, cur_ver, cur_rel, cur_epoch, cur_arch) = splitFilename(installed_pkg)
cur_epoch = cur_epoch or '0'
compare = compareEVR((cur_epoch, cur_ver, cur_rel), (epoch, ver, rel))

# compare > 0 (higher version is installed) or compare == 0 (exact version is installed)
if compare >= 0:
# compare > 0 -> higher version is installed
# compare == 0 -> exact version is installed
# compare < 0 -> lower version is installed
if compare > 0 and allow_downgrade:
downgrade_candidate = True
elif compare >= 0:
continue

# else: if there are more installed packages with the same name, that would mean
# kernel, gpg-pubkey or like, so just let yum deal with it and try to install it

Expand Down
33 changes: 33 additions & 0 deletions test/integration/targets/yum/tasks/repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,36 @@
- "'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:
- "rpm_result.rc == 0"
- "yum_result.rc == 0"
- "yum_result.changed"
- "not yum_result|failed"
- "rpm_result.stdout.startswith('foo-1.0-1')"

- name: Verify yum module outputs
assert:
that:
- "'changed' in yum_result"
- "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result"
# ============================================================================