diff --git a/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml b/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml new file mode 100644 index 00000000000..97716d04693 --- /dev/null +++ b/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml @@ -0,0 +1,2 @@ +bugfixes: + - dnf5 - respect ``allow_downgrade`` when installing packages directly from rpm files diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 823d3a7fb96..3f54816b996 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -357,9 +357,15 @@ def is_installed(base, spec): def is_newer_version_installed(base, spec): + # FIXME investigate whether this function can be replaced by dnf5's allow_downgrade option + if "/" in spec: + spec = spec.split("/")[-1] + if spec.endswith(".rpm"): + spec = spec[:-4] + try: spec_nevra = next(iter(libdnf5.rpm.Nevra.parse(spec))) - except RuntimeError: + except (RuntimeError, StopIteration): return False spec_name = spec_nevra.get_name() v = spec_nevra.get_version() diff --git a/test/integration/targets/dnf/tasks/repo.yml b/test/integration/targets/dnf/tasks/repo.yml index 7f785b14e90..6aa268e2b29 100644 --- a/test/integration/targets/dnf/tasks/repo.yml +++ b/test/integration/targets/dnf/tasks/repo.yml @@ -101,6 +101,30 @@ that: - "'results' in dnf_result" # ============================================================================ + - name: Install dinginessentail-1.0-1 from a file (higher version is already installed) + dnf: + name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm" + state: present + disable_gpg_check: True + 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.startswith('dinginessentail-1.1-1')" + + - name: Verify dnf module outputs + assert: + that: + - "'msg' in dnf_result" + - "'rc' in dnf_result" + - "'results' in dnf_result" + # ============================================================================ - name: Install dinginessentail-1.0-1 from a file (downgrade) dnf: name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"