From 7a9f14b19ea5e51906be2d8b670fbf5349e9b16c Mon Sep 17 00:00:00 2001 From: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:01:07 -0600 Subject: [PATCH] Revert #83504 (#83566) * Revert "[stable-2.17] dnf: follow-up on is_newer_installed arches fix (#83556) (#83563)" This reverts commit fa405031919bbfafbb8aad4f29b317ff86ce5186. * Revert "[stable-2.17] dnf - arches must be the same in the is_newer_installed check (#83417)" This reverts commit 6966b53b5be48cbcef600f53fb58a5c5b478a185. --- .../fragments/83406-dnf-fix-arch-cmp.yml | 2 - changelogs/fragments/dnf-revert.yaml | 2 + lib/ansible/modules/dnf.py | 23 +++----- test/integration/targets/dnf/tasks/repo.yml | 57 ------------------- 4 files changed, 10 insertions(+), 74 deletions(-) delete mode 100644 changelogs/fragments/83406-dnf-fix-arch-cmp.yml create mode 100644 changelogs/fragments/dnf-revert.yaml diff --git a/changelogs/fragments/83406-dnf-fix-arch-cmp.yml b/changelogs/fragments/83406-dnf-fix-arch-cmp.yml deleted file mode 100644 index c890d662e44..00000000000 --- a/changelogs/fragments/83406-dnf-fix-arch-cmp.yml +++ /dev/null @@ -1,2 +0,0 @@ -bugfixes: - - dnf - fix an issue where two packages of the same ``evr`` but different arch failed to install (https://github.com/ansible/ansible/issues/83406) diff --git a/changelogs/fragments/dnf-revert.yaml b/changelogs/fragments/dnf-revert.yaml new file mode 100644 index 00000000000..a9df000a45e --- /dev/null +++ b/changelogs/fragments/dnf-revert.yaml @@ -0,0 +1,2 @@ +bugfixes: + - dnf - reverted incomplete fix from 2.17.2rc1 (https://github.com/ansible/ansible/pull/83504) diff --git a/lib/ansible/modules/dnf.py b/lib/ansible/modules/dnf.py index 72f62aab0c0..2ab66fbd622 100644 --- a/lib/ansible/modules/dnf.py +++ b/lib/ansible/modules/dnf.py @@ -743,25 +743,18 @@ class DnfModule(YumDnf): else: return bool(installed_query) - def _is_newer_version_installed(self, pkg_spec): + def _is_newer_version_installed(self, pkg_name): try: - if isinstance(pkg_spec, dnf.package.Package): - installed = sorted(self.base.sack.query().installed().filter(name=pkg_spec.name, arch=pkg_spec.arch))[-1] - return installed.evr_gt(pkg_spec) + if isinstance(pkg_name, dnf.package.Package): + available = pkg_name else: - available = dnf.subject.Subject(pkg_spec).get_best_query(sack=self.base.sack).available() - installed = self.base.sack.query().installed().filter(name=available[0].name) - for arch in sorted(set(p.arch for p in installed)): # select only from already-installed arches for this case - installed_pkg = sorted(installed.filter(arch=arch))[-1] - try: - available_pkg = sorted(available.filter(arch=arch))[-1] - except IndexError: - continue # nothing currently available for this arch; keep going - if installed_pkg.evr_gt(available_pkg): - return True - return False + available = sorted( + dnf.subject.Subject(pkg_name).get_best_query(sack=self.base.sack).available().run() + )[-1] + installed = sorted(self.base.sack.query().installed().filter(name=available.name).run())[-1] except IndexError: return False + return installed > available def _mark_package_install(self, pkg_spec, upgrade=False): """Mark the package for install.""" diff --git a/test/integration/targets/dnf/tasks/repo.yml b/test/integration/targets/dnf/tasks/repo.yml index 31ad9633343..d50535be1b7 100644 --- a/test/integration/targets/dnf/tasks/repo.yml +++ b/test/integration/targets/dnf/tasks/repo.yml @@ -542,60 +542,3 @@ dnf: name: provides_foo* state: absent - -- name: test that only evr is compared, avoiding a situation when a specific arch would be considered as a "newer" package - block: - - dnf: - name: "{{ item }}" - state: present - loop: - - "dinginessentail-1.0-1.x86_64" - - "dinginessentail-1.0-1.i686" - register: dnf_results - - - assert: - that: - - dnf_results["results"][0] is changed - - dnf_results["results"][1] is changed - always: - - name: Clean up - dnf: - name: dinginessentail - state: absent - -- block: - - name: make sure dinginessentail is not installed - dnf: - name: dinginessentail - state: absent - - - name: install dinginessentail both archs - dnf: - name: - - "{{ repodir }}/dinginessentail-1.1-1.x86_64.rpm" - - "{{ repodir_i686 }}/dinginessentail-1.1-1.i686.rpm" - state: present - disable_gpg_check: true - - - name: try to install lower version of dinginessentail from rpm file, without allow_downgrade, just one arch - dnf: - name: "{{ repodir_i686 }}/dinginessentail-1.0-1.i686.rpm" - state: present - register: dnf_result - - - name: check dinginessentail with rpm - shell: rpm -q dinginessentail - register: rpm_result - - - name: verify installation - assert: - that: - - "not dnf_result.changed" - - "rpm_result.stdout_lines[0].startswith('dinginessentail-1.1-1')" - - "rpm_result.stdout_lines[1].startswith('dinginessentail-1.1-1')" - always: - - name: Clean up - dnf: - name: dinginessentail - state: absent - when: ansible_architecture == "x86_64"